由鼠标控制的VB秒表

时间:2015-02-03 01:09:23

标签: vb.net

我正在制作一个秒表来测量某些武器在CS:GO中清空它们的剪辑需要多长时间。我有秒表编程,但它似乎只有在窗口的范围内点击才有效。如果可能,有人知道如何在其他程序中启动/停止它吗?我发布下面的代码。

Public Class Form1
Dim WithEvents timer As New Timer
Dim milliseconds As Integer

Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles MyBase.MouseDown
    Timer1.Start()
End Sub

Private Sub Form1_MouseUp(sender As Object, e As MouseEventArgs) Handles MyBase.MouseUp
    Timer1.Stop()
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    totalTime.Text = 0.0
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    totalTime.Text = totalTime.Text + 0.01
End Sub
End Class

1 个答案:

答案 0 :(得分:2)

MouseDownMouseUp事件仅在鼠标在应用程序中单击时发生,因此您无法将它们用作事件来跟踪鼠标在另一个应用程序中按住的时间。

您可以使用global mouse hook或查看Windows消息(例如Mouse DownMouse Up消息

来执行您想要的操作