Public Class Form1 Private Declare Function timeGetTime Lib "winmm" Alias "timeGetTime" () As UInteger Private Allows As New Dictionary(Of Keys, UInteger?)() From { {Keys.Up, Nothing}, {Keys.Down, Nothing}, {Keys.Left, Nothing}, {Keys.Right, Nothing} } Private startTime As Date, startTick As UInteger Public Sub New() InitializeComponent() Controls.Clear() startTime = Now startTick = timeGetTime() Debug.WriteLine("----測定開始----") End Sub Private Sub Form1_KeyUp(sender As Object, e As KeyEventArgs) Handles Me.KeyUp If Allows.ContainsKey(e.KeyCode) Then Dim tm1 = Allows(e.KeyCode).Value Dim tm2 = timeGetTime() Dim currentTime As Date = startTime.AddMilliseconds(CDbl(tm2 - startTick)) Dim pushedSpan = (tm2 - tm1) / 1000.0 Allows(e.KeyCode) = Nothing Debug.WriteLine(String.Format("{0:yyyy\/MM\/dd HH\:mm\:ss.fff} 離 {1,-6} ({2:N3}秒間)", currentTime, e.KeyCode, pushedSpan)) End If End Sub Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown If Allows.ContainsKey(e.KeyCode) AndAlso Allows(e.KeyCode) Is Nothing Then Dim tm = timeGetTime() Dim currentTime As Date = startTime.AddMilliseconds(CDbl(tm - startTick)) Allows(e.KeyCode) = tm Debug.WriteLine(String.Format("{0:yyyy\/MM\/dd HH\:mm\:ss.fff} 押 {1,-6}", currentTime, e.KeyCode)) End If End Sub End Class