我的代码应该在另一个程序运行时记录击键 - 例如,当我在游戏中按下“Q”键时,我的代码应该记下我这样做的时间。稍后,我可以查看日志以查看击键发生的时间。(我正在使用 .Net 4.5 框架。)
在下面的代码中未检测到 keyPress - 我该如何解决这个问题?
Public Class MainForm
Dim startTime As DateTime
Private Sub MainForm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
If Button1.Text = "Start" Then
startTime = DateTime.Now
TimerLoad.Start()
Button1.Text = "Stop"
Else
TimerLoad.Stop()
Button1.Text = "Start"
Dim FileNumber As Integer = FreeFile()
FileOpen(FileNumber, "C:\Users\JasonValidia\Documents\MontageTimer.txt", OpenMode.Output)
For Each Item As Object In ListBox1.Items
PrintLine(FileNumber, Item.ToString)
Next
FileClose(FileNumber)
End If
End Sub
Private Sub TimerLoad_Tick(sender As System.Object, e As System.EventArgs) Handles TimerLoad.Tick
Dim timeDifferance As TimeSpan = DateTime.Now.Subtract(startTime)
Dim newDate As DateTime = timeDifferance.ToString
Label1.Text = newDate.ToString("HH:mm:ss")
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
ListBox1.Items.Add(Label1.Text)
End Sub
Private Sub login_KeyDown(ByVal sender As Object,
ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Enter Then
ListBox1.Items.Add(Label1.Text)
If CheckBox1.Checked = True Then startTime = DateTime.Now
End If
End Sub
End Class