我希望能够检测到Windows键何时被按下。我尝试使用getasynckeystate函数,但没有找到正确的虚拟键。
谢谢你的帮助!
我希望能够检测到Windows键何时被按下。我尝试使用getasynckeystate函数,但没有找到正确的虚拟键。
谢谢你的帮助!
看这个:
你需要查找这些按键代码:
LWin The left Windows logo key (Microsoft Natural Keyboard).
RWin The right Windows logo key (Microsoft Natural Keyboard).
示例代码:
Public Sub TextBox1_KeyPress(ByVal sender As Object, _
ByVal e As KeyPressEventArgs) Handles TextBox1.KeyPress
If (e.Key = Key.LWin Or e.Key = Key.RWin) Then
MsgBox("Pressed Windows Key")
End If
End Sub
键码在Keys Enumeration页面上给出:
LWin 左Windows徽标键(Microsoft自然键盘)。
RWin 右Windows徽标键(Microsoft自然键盘)。
它并没有表明除了Microsoft自然键盘之外的其他键盘是否可以获得这些代码。
如果您正在使用WinForms,则需要捕获KeyDown事件
如果您正在使用WPF,则需要Keyboard.KeyDown事件
Console.ReadKey()
并检查返回的 ConsoleKeyInfo.Key
属性的值。这些值分别是 ConsoleKey.LeftWindows
和 ConsoleKey.RightWindows
。 - Jim MischelGetAsyncKeyState
,你要找的值在WinUser.h中定义为VK_LWIN
和VK_RWIN
:分别是0x5B和0x5C。