鼠标左/右键单击功能 VB.NET
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23803938/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Left/Right Mouse Click Function VB.NET
提问by user3568182
I'm trying to make my own auto-clicker (settable to left or right, depending on the radio button selection) and I can't seem to make the mouse click. In order to be able to set the delay wished for the auto-clicker, I've put it within the Timer1 (one for left click, one for right click). My questions are:
我正在尝试制作自己的自动点击器(可设置为向左或向右,取决于单选按钮选择),但我似乎无法点击鼠标。为了能够设置自动点击器所需的延迟,我将它放在 Timer1 中(一个用于左键单击,一个用于右键单击)。我的问题是:
a) How can I make the mouse click when a certain key is pressed (e.g, F6).
a) 当按下某个键(例如 F6)时,如何使鼠标单击。
b) How can I make it have the delay of Timer1/Timer2 for each click.
b) 我怎样才能让它每次点击都有 Timer1/Timer2 的延迟。
For the record, I wish for this auto-clicker to work EVERYWHERE, not just within the form.
作为记录,我希望这个自动点击器可以在任何地方工作,而不仅仅是在表单内。
回答by Francesco Menzani
You can use user32.dll lib.
您可以使用 user32.dll 库。
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)
&H2means left mouse button down.
&H4means left mouse button up.
&H2表示按下鼠标左键。
&H4表示鼠标左键向上。
mouse_event(&H2, 0, 0, 0, 0)
mouse_event(&H4, 0, 0, 0, 0)
回答by Hansa Ribe
I would imagine something like this would work, check vKey list to change hotkey.
我会想象这样的事情会起作用,检查 vKey 列表以更改热键。
Above Class:
上级:
Imports System.Threading
Main Class declares:
主类声明:
Dim ClickTimer As System.Threading.Thread = New System.Threading.Thread(AddressOf DoClicks)
Public Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Int32) As Integer
Dim exit_thread As Boolean = False
Dim ClickerHotkey As Integer = &H20 '0x20 = space
Form_Load:
Form_Load:
ClickTimer.Start()
Inside class:
内课:
Public Function DoClicks()
While (Not exit_thread)
If GetAsyncKeyState(ClickerHotkey) Then
mouse_event(&H2, 0, 0, 0, 1)
mouse_event(&H4, 0, 0, 0, 1)
End If
Thread.Sleep(15)
End While
End Function
Form_OnClose:
Form_OnClose:
exit_thread = true

