none
用vb.net做个一个简单的鼠标连点器,可以设置点击间隔和持续时间。 RRS feed

  • 问题

  • 想用vb.net做个一个简单的鼠标连点器,可以设置点击间隔和持续时间。

    希望高手能指点一下~~

    相信看到窗体(发不了图片 :(  我用文字表述一下 ),已经知道我的用意了。就是:

    点击开始按钮后,鼠标左键按照延迟时间开始循环点击,此时可以移动鼠标到任意地方,但是点击一直持续,

    直到按下空格键或者达到持续时间中的时间。

    延迟时间(秒): Textbox1______

    持续时间(秒):Textbox2______

    按钮:开始

    说明:按下<空格键>停止运行

    2020年2月28日 12:56

全部回复

  • 大神在哪里?
    2020年3月1日 7:26
  • Hi Cute,

    根据你的描述,我认为你需要同时设置timer和stopwatch才可以进行类似的操作。

    下面是我写的应该代码示例,当中的“弹出test”行为弄可以改成相应的连点操作。

    Public Partial Class Form1
        Inherits Form
    
        <DllImport("user32", CharSet:=CharSet.Unicode)>
        Private Shared Function mouse_event(ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal dwData As Integer, ByVal dwExtraInfo As Integer) As Integer
        Const MOUSEEVENTF_LEFTDOWN As Integer = &H0002
        Const MOUSEEVENTF_LEFTUP As Integer = &H0004
        Private [stop] As Stopwatch = New Stopwatch()
        Private t As Boolean = False
    
        Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
            timer1.Interval = Convert.ToInt32(textBox1.Text)
            timer1.Start()
            [stop].Start()
            t = True
        End Sub
    
        Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As MouseEventArgs)
            If e.Button = MouseButtons.Left AndAlso t = True Then
                MessageBox.Show("Test")
            End If
        End Sub
    
        Private Sub timer1_Tick(ByVal sender As Object, ByVal e As EventArgs)
            mouse_event(MOUSEEVENTF_LEFTDOWN, Cursor.Position.X, Cursor.Position.Y, 0, 0)
            mouse_event(MOUSEEVENTF_LEFTUP, Cursor.Position.X, Cursor.Position.Y, 0, 0)
    
            If [stop].ElapsedMilliseconds >= Convert.ToInt32(textBox2.Text) Then
                timer1.[Stop]()
                [stop].[Stop]()
            End If
        End Sub
    
        Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
            If e.KeyCode = Keys.Space Then
                timer1.[Stop]()
                [stop].[Stop]()
            End If
        End Sub
    End Class

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.



    2020年3月2日 7:23
    版主