如何检测Windows按键是否被按下?
答
关键代码被赋予Keys Enumeration页:
伦左Windows徽标键(Microsoft自然键盘)。
RWin右侧Windows徽标键(Microsoft Natural Keyboard)。
这并不表明,在使用键盘等比Microsoft自然键盘时,是否这些代码是(如果有的话)获得。
如果你正在使用的WinForms,那么你需要捕获KeyDown Event
如果您正在使用WPF,那么你需要的Keyboard.KeyDown Event
+0
如果它是一个控制台应用程序,你想调用`Console.ReadKey()`并检查返回的`ConsoleKeyInfo.Key`属性的值。值为`ConsoleKey.LeftWindows`和`ConsoleKey.RightWindows`。 – 2011-02-05 23:09:41
答
检查了这一点:
你寻找这些关键代码:
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
答
如果你真的想使用GetAsyncKeyState
,你正在寻找WINUSER.H被定义为VK_LWIN
和`VK_RWIN'值:分别0x5B和0x5C。
请正确标记您的问题。你使用C#还是VB?它是VB6还是VB.NET?什么版本? – Oded 2011-02-05 22:00:22