我正在创建一个“自动点击器”,用于在按下按钮时反复左击鼠标的视频游戏中。我想让热键设置为全局工作,而无需自动点击器窗口成为焦点。出于某种原因,当前只有用于停止点击的热键起作用(F2)。F1 键应该开始单击,但目前启动它的唯一方法是手动按下窗体上的“开始”按钮。尝试将代码部署到 .NET 框架的 4.0 版时,该代码似乎会引发错误,但将其设置为 3.5 可以解决此问题。我在下面包含了我的整个代码,因为我无法弄清楚为什么 F1 热键无法正常工作,尽管 F2 热键工作完美。谢谢你的时间。这段代码的很大一部分是我通过查看其他人的工作示例得出的,我只是在一定程度上理解了它。我希望我的代码格式正确,因为我是这个网站的新手,我并不完全了解如何正确粘贴它。提前感谢您的帮助,我真的很感激。
Public Class Form1
Private Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vkey As Long) As Integer
Private Declare Sub mouse_event Lib "user32.dll" (ByVal dwflags As Long, ByVal dx As Long, ByVal cbuttons As Long, ByVal dy As Long, ByVal dwExtraInfo As Long)
Dim hotkey1 As Boolean
Dim hotkey2 As Boolean
Private Const mouseclickup = 4
Private Const mouseclickdown = 2
Dim Test As Integer
Dim Interval As Integer
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
Click.Start()
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
Click.Stop()
End Sub
Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
Test = Test + 1
Counter.Text = Test
End Sub
Private Sub Click_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Click.Tick
Interval = CInt(timeTextbox.Text)
Click.Interval = Interval
mouse_event(mouseclickdown, 0, 0, 0, 0)
mouse_event(mouseclickup, 0, 0, 0, 0)
hotkey1 = GetAsyncKeyState(Keys.F1)
If hotkey1 = True Then
btnStart.PerformClick()
End If
hotkey2 = GetAsyncKeyState(Keys.F2)
If hotkey2 = True Then
btnStop.PerformClick()
End If
End Sub
Private Sub timeTextbox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timeTextbox.TextChanged
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
KeyPreview = True
End Sub
结束类