0

我想要做的是在后台运行一个应用程序,该应用程序在键盘上按下捕获键,然后双击发送到 Windows im on(不是 vb 程序)中的 X 和 Y 坐标。

这是我到目前为止所拥有的:

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 之外被识别,这一切都很好。我只是不知道如何在坐标处双击。有人有想法吗?

4

1 回答 1

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)

这对我来说效果很好。如果您想重置它,它还会保存当前位置。

于 2014-01-22T16:16:23.123 回答