|
■No92988 (けーえんす さん) に返信
> 恐らく、2回目以降のキーの実行はArrowKeyMovementが実行される前の段階でキュー待ちような状態になっているのではないかと思います。
メッセージループを止めるとキーボードを押した等のメッセージはキューに貯まります。
ループが再開する前にメッセージを PeekMessage で刈り取るといいかと。
Imports System.Threading
Imports System.Runtime.InteropServices
Public Class Form1
Private Sub TrackBar1_ValueChanged(sender As Object, e As EventArgs) Handles TrackBar1.ValueChanged
Debug.Print("重い処理開始")
Thread.Sleep(10000)
Debug.Print("重い処理終了")
CancelInput()
End Sub
<StructLayout(LayoutKind.Sequential)>
Private Structure MSG
Public hwnd As IntPtr
Public Msg As Integer
Public WParam As IntPtr
Public LParam As IntPtr
Public time As Integer
Public x As Integer
Public y As Integer
End Structure
Private Const WM_KEYFIRST As Integer = &H100
Private Const WM_KEYLAST As Integer = &H108
Private Const PM_REMOVE As Integer = &H1
Private Const WM_MOUSEFIRST As Integer = &H200
Private Const WM_MOUSELAST As Integer = &H20E
<DllImport("User32.dll", CharSet:=CharSet.Auto)>
Private Shared Function PeekMessage(ByRef msg As MSG, hwnd As IntPtr, msgMin As Integer, msgMax As Integer, remove As Integer) As Boolean
End Function
Private Sub CancelInput()
Dim msg As New MSG
While PeekMessage(msg, IntPtr.Zero, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE)
End While
While PeekMessage(msg, IntPtr.Zero, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE)
End While
End Sub
End Class
|