Mit diesem Code werden die Tastenschläge mit Hilfe von user32.dll gezählt
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("user32.dll")> Private Shared Function GetAsyncKeyState(ByVal vKey As Integer) As Short
End Function
Public Const KeyPressed As Integer = -32767
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Interval = 1
For Each key As Int32 In [Enum].GetValues(GetType(Windows.Forms.Keys))
If GetAsyncKeyState(key) = -32767 Then
Label1.Text += 1
End If
Next
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Timer1.Start
End Sub
1 Kommentare zum Snippet