Public ReadOnly Property KeyStatus(ByVal Key As Keys) AsBoolean
Get
If Key = Keys.LButton AndAlso My.Computer.Mouse.ButtonsSwappedThen
Key = Keys.RButton
ElseIf Key = Keys.RButton AndAlsoMy.Computer.Mouse.ButtonsSwapped Then
Key = Keys.LButton
End If
Return GetAsyncKeyState(Key) And &H8000US
End Get
End Property
调用:
While 1
If KeyStatus(Keys.F7) = True Then
MsgBox("按下了F7键,将退出循环")
Exit While
End If
End While