VB(模拟)鼠标点击(变形)
VB (simulate) mouse click (out of form)
我试图制作一个程序来模拟鼠标点击并对 Visual Basic 中的鼠标点击事件做出反应,但我找不到我需要的东西。我已经编写了逻辑上我不知道的代码并对其进行了标记,请告诉我我需要的代码命令。每个地方都是#我不知道代码。抱歉我的英文太棒了 ;D 我的老师很糟糕 :P
Public Class Form1
Public Tick As Integer = 0
Public MaxTick As Integer = 0
Public active As Boolean = False
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
RadioButton1.Select()
ComboBox1.SelectedIndex = 0
ComboBox2.SelectedIndex = 0
End Sub
Private Sub RadioButton1_Change(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.Click, RadioButton2.Click
If RadioButton1.Checked Then
GroupBox1.Enabled = True
GroupBox2.Enabled = False
Timer1.Interval = TextBox1.Text
Else
GroupBox2.Enabled = True
GroupBox1.Enabled = False
Timer2.Interval = TextBox3.Text
End If
End Sub
Private Sub Me_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Tab) Then
If RadioButton1.Checked Then
active = False
If Timer1.Enabled Then
Timer1.Stop()
Else
Timer1.Start()
End If
e.Handled = False
Else
active = True
End If
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If CheckBoxLeft.Checked Then
###Perform Mouseclick Left###
End If
If CheckBoxMiddle.Checked Then
###Perform Mouseclick Middle###
End If
If CheckBoxRight.Checked Then
###Perform Mouseclick Right###
End If
End Sub
###Private Sub OnClick_Event()###
###If Mouseclick == Right Then###
If CheckBoxRight.Checked Then
Timer2.start()
End If
###Else if Mouseclick == Middle Then###
If CheckBoxMiddle.Checked Then
Timer2.Start()
End If
###Else If Mouseclick == Left Then###
If CheckBoxLeft.Checked Then
Timer2.Start()
End If
End If
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
If active Then
Tick += 1
If CheckBoxLeft.Checked Then
###Perform Click Left###
End If
If CheckBoxMiddle.Checked Then
###Perform Click Middle###
End If
If CheckBoxRight.Checked Then
###Perform Click Right###
End If
If Tick = MaxTick Then
Tick = 0
Timer2.Stop()
End If
Else
Timer2.Stop()
Tick = 0
End If
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
MaxTick = TextBox2.Text
End Sub
End Class
所以我需要一个 Mouseclick 事件,然后询问哪个 Mousebutton 被点击,我需要一个方法来执行左中键和右键单击
LG 尼克拉斯
您应该查找 mouse_event() p/invoke 方法。这将允许您模拟鼠标事件。它在 VB.Net 中的声明是
<DllImport("user32.dll")> _
Private Shared Sub mouse_event(dwFlags As UInteger, dx As UInteger, dy As UInteger, dwData As UInteger, dwExtraInfo As Integer)
End Sub
您可以阅读更多相关内容 here. And here is a project on codeproject.com,其中有一个完整的示例。
我试图制作一个程序来模拟鼠标点击并对 Visual Basic 中的鼠标点击事件做出反应,但我找不到我需要的东西。我已经编写了逻辑上我不知道的代码并对其进行了标记,请告诉我我需要的代码命令。每个地方都是#我不知道代码。抱歉我的英文太棒了 ;D 我的老师很糟糕 :P
Public Class Form1
Public Tick As Integer = 0
Public MaxTick As Integer = 0
Public active As Boolean = False
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
RadioButton1.Select()
ComboBox1.SelectedIndex = 0
ComboBox2.SelectedIndex = 0
End Sub
Private Sub RadioButton1_Change(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.Click, RadioButton2.Click
If RadioButton1.Checked Then
GroupBox1.Enabled = True
GroupBox2.Enabled = False
Timer1.Interval = TextBox1.Text
Else
GroupBox2.Enabled = True
GroupBox1.Enabled = False
Timer2.Interval = TextBox3.Text
End If
End Sub
Private Sub Me_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Tab) Then
If RadioButton1.Checked Then
active = False
If Timer1.Enabled Then
Timer1.Stop()
Else
Timer1.Start()
End If
e.Handled = False
Else
active = True
End If
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If CheckBoxLeft.Checked Then
###Perform Mouseclick Left###
End If
If CheckBoxMiddle.Checked Then
###Perform Mouseclick Middle###
End If
If CheckBoxRight.Checked Then
###Perform Mouseclick Right###
End If
End Sub
###Private Sub OnClick_Event()###
###If Mouseclick == Right Then###
If CheckBoxRight.Checked Then
Timer2.start()
End If
###Else if Mouseclick == Middle Then###
If CheckBoxMiddle.Checked Then
Timer2.Start()
End If
###Else If Mouseclick == Left Then###
If CheckBoxLeft.Checked Then
Timer2.Start()
End If
End If
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
If active Then
Tick += 1
If CheckBoxLeft.Checked Then
###Perform Click Left###
End If
If CheckBoxMiddle.Checked Then
###Perform Click Middle###
End If
If CheckBoxRight.Checked Then
###Perform Click Right###
End If
If Tick = MaxTick Then
Tick = 0
Timer2.Stop()
End If
Else
Timer2.Stop()
Tick = 0
End If
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
MaxTick = TextBox2.Text
End Sub
End Class
所以我需要一个 Mouseclick 事件,然后询问哪个 Mousebutton 被点击,我需要一个方法来执行左中键和右键单击
LG 尼克拉斯
您应该查找 mouse_event() p/invoke 方法。这将允许您模拟鼠标事件。它在 VB.Net 中的声明是
<DllImport("user32.dll")> _
Private Shared Sub mouse_event(dwFlags As UInteger, dx As UInteger, dy As UInteger, dwData As UInteger, dwExtraInfo As Integer)
End Sub
您可以阅读更多相关内容 here. And here is a project on codeproject.com,其中有一个完整的示例。