Imports System.Windows.Forms Imports System.Drawing Module Module1 Sub Main() Dim frm As New Form() AddHandler frm.KeyDown, New KeyEventHandler(AddressOf frm_KeyDown) AddHandler frm.KeyUp, New KeyEventHandler(AddressOf frm_KeyUp) frm.Show() Dim g As Graphics = frm.CreateGraphics() Dim AKeyPushCount As Integer = 0 Dim AKeyPressCount As Integer = 0 Dim nextFlame As Double = Environment.TickCount Dim wait As Single = 1000 / 60 While frm.Created If Environment.TickCount >= nextFlame Then upDate() If Push Then AKeyPushCount += 1 End If If Press Then AKeyPressCount += 1 End If If Environment.TickCount < nextFlame + wait Then g.FillRectangle(Brushes.White, 0, 0, frm.ClientSize.Width, frm.ClientSize.Height) g.DrawString("Push:" + AKeyPushCount.ToString() + " Press:" + AKeyPressCount.ToString(), frm.Font, Drawing.Brushes.Black, 0, 0) End If nextFlame += wait End If Application.DoEvents() End While End Sub Dim AKeyState() As Boolean = {False, False} Dim tmpAKeyState As Boolean = False ReadOnly Property Press() As Boolean Get Return AKeyState(1) End Get End Property ReadOnly Property Push() As Boolean Get Return AKeyState(1) AndAlso Not AKeyState(0) End Get End Property Sub frm_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) If e.KeyData = Keys.Down Then tmpAKeyState = True End If End Sub Sub frm_KeyUp(ByVal sender As Object, ByVal e As KeyEventArgs) If e.KeyData = Keys.Down Then tmpAKeyState = False End If End Sub Sub upDate() AKeyState(0) = AKeyState(1) AKeyState(1) = tmpAKeyState End Sub End Module