我一直在编写一个应用程序,它首先能够使用*和+分别在屏幕上设置2个位置,然后按f6或f7分别转到该位置。代码正在运行,但是如果按f7然后多次按f6或f6,它会卡住,锁定鼠标并继续调用SetCursorPos(HPos.X,HPos.Y)。谁能帮我找到我出错的地方?
以下是代码:
Private Const KEY_DOWN As Integer = &H8000
Private Const VK_SHIFT As Integer = &H10
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Integer, _
ByVal y As Integer) As Integer
Private myX As Integer
Private myY As Integer
Dim mp As Point
Dim HPos As Point
Dim TPos As Point
Declare Function apimouse_event Lib "user32.dll" Alias "mouse_event" _
(ByVal dwFlags As Int32, ByVal dX As Int32, ByVal dY As Int32, _
ByVal cButtons As Int32, ByVal dwExtraInfo As Int32) As Boolean
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Private Sub CleanseTimer_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles CleanseTimer.Tick
Dim dummy As Integer
Dim dummy2 As Integer
If GetAsyncKeyState(106) Then
HPos = MousePosition
HTxt.Text = HPos.ToString
dummy = GetAsyncKeyState(106)
ElseIf GetAsyncKeyState(107) Then
TPos = MousePosition
TTxt.Text = TPos.ToString
dummy = GetAsyncKeyState(107)
End If
If (GetAsyncKeyState(117) And KEY_DOWN) And Not HTxt.Text = "" Then
SetCursorPos(HPos.X, HPos.Y)
Call apimouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
Call apimouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
SendKeys.Send("+7")
dummy = GetAsyncKeyState(117)
dummy2 = SetCursorPos(HPos.X, HPos.Y)
End If
If (GetAsyncKeyState(118) And KEY_DOWN) = KEY_DOWN And Not TTxt.Text = "" Then
SetCursorPos(TPos.X, TPos.Y)
Call apimouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
Call apimouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
SendKeys.Send("+7")
dummy = GetAsyncKeyState(118)
dummy2 = SetCursorPos(TPos.X, TPos.Y)
End If
End Sub