3

我希望能够检测到何时按下 windows 键。我尝试使用 getasynckeystate 函数错误没有找到正确的虚拟键。感谢您的帮助 !

4

3 回答 3

3

看一下这个:

键枚举

您正在寻找这些关键代码:

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
于 2011-02-05T22:06:49.113 回答
1

密钥枚举页面上给出了密钥代码:

LWin 左 Windows 徽标键(Microsoft 自然键盘)。
RWin 右 Windows 徽标键(Microsoft 自然键盘)。

它不指示在使用Microsoft Natural Keyboard 以外的键盘时是否获得了这些代码中的任何一个(如果有)。

如果您使用的是 WinForms,那么您需要捕获KeyDown 事件

如果您使用的是 WPF,那么您需要Keyboard.KeyDown 事件

于 2011-02-05T22:04:43.360 回答
1

如果您真的想使用GetAsyncKeyState,您要查找的值在 WinUser.h 中定义为VK_LWIN和 `VK_RWIN':分别为 0x5B 和 0x5C。

于 2011-02-05T23:11:34.620 回答