我想要做的是让一个应用程序在后台运行,捕获键盘上的按键然后发送双击到窗口中的X和Y坐标(不是vb程序)。
这是我到目前为止所做的:
Public Class Form1
Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As System.Windows.Forms.Keys) As Integer
Private Declare Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As IntPtr)
Private Sub PerformMouseClick(ByVal LClick_RClick_DClick As String, ByVal xCoord As Integer, ByVal yCoord As Integer)
Const MOUSEEVENTF_LEFTDOWN As Integer = 2
Const MOUSEEVENTF_LEFTUP As Integer = 4
Const MOUSEEVENTF_RIGHTDOWN As Integer = 6
Const MOUSEEVENTF_RIGHTUP As Integer = 8
If LClick_RClick_DClick = "RClick" Then
mouse_event(MOUSEEVENTF_RIGHTDOWN, xCoord, yCoord, 0, IntPtr.Zero)
mouse_event(MOUSEEVENTF_RIGHTUP, xCoord, yCoord, 0, IntPtr.Zero)
ElseIf LClick_RClick_DClick = "LClick" Then
mouse_event(MOUSEEVENTF_LEFTDOWN, xCoord, yCoord, 0, IntPtr.Zero)
mouse_event(MOUSEEVENTF_LEFTUP, xCoord, yCoord, 0, IntPtr.Zero)
ElseIf LClick_RClick_DClick = "DClick" Then
mouse_event(MOUSEEVENTF_LEFTDOWN, xCoord, yCoord, 0, IntPtr.Zero)
mouse_event(MOUSEEVENTF_LEFTUP, xCoord, yCoord, 0, IntPtr.Zero)
mouse_event(MOUSEEVENTF_LEFTDOWN, xCoord, yCoord, 0, IntPtr.Zero)
mouse_event(MOUSEEVENTF_LEFTUP, xCoord, yCoord, 0, IntPtr.Zero)
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If GetAsyncKeyState(Keys.W) Then
PerformMouseClick("LClick", 74, 1103)
End If
End Sub
End Class
但双重不会发生。钥匙(W)在我的vb之外被识别出一切都很好。我只是不知道如何在坐标处发送双击。有人有想法吗?
答案 0 :(得分:0)
我认为这可以帮到你:
Public Structure PointAPI
Public x As Integer
Public y As Integer
End Structure
Module Module_SetMouseclick
Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)
Public Declare Auto Function SetCursorPos Lib "User32.dll" (ByVal X As Integer, ByVal Y As Integer) As Long
Declare Function GetCursorPos Lib "user32.dll" (ByRef lpPoint As PointAPI) As Boolean
Private Const MOUSEEVENTF_LEFTDOWN = &H2
Const MOUSEEVENTF_LEFTUP As Integer = &H4
Public x, y As Integer
Public Sub Position_Click(ByVal x As Integer, ByVal y As Integer, ByVal click As Boolean)
SetCursorPos(x, y)
If click Then
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 1)
Else
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 1)
End If
End Sub
End Module
并使用
访问它Module_SetMouseclick.Position_Click(500, 500, True)
Module_SetMouseclick.Position_Click(500, 500, False)
这对我来说效果很好。如果您想重置它,IT也会保存当前位置。