vb.net 检查某个键是否被按下?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5495613/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Check if a certain key is being pressed?
提问by Voldemort
I need to check if the SHIFT or CTRL keys are being pressed in my VB.net application, any ideas? (get a boolean)
我需要检查我的 VB.net 应用程序中是否按下了 SHIFT 或 CTRL 键,有什么想法吗?(得到一个布尔值)
采纳答案by Alan Kuras
Check that link : http://msdn.microsoft.com/en-us/library/system.windows.forms.keyeventargs.aspx#
检查该链接:http: //msdn.microsoft.com/en-us/library/system.windows.forms.keyeventargs.aspx#
It's about KeyEventArgs Class with some examples how to detect shift/ctrl keypress etc.
这是关于 KeyEventArgs 类的一些示例,如何检测 shift/ctrl 按键等。
回答by OfficeAddinDev
The following will return True or False depending on whether the key is pressed at that moment. From the wording of your question, I assume you are notasking about event handling, which is what the other answers have addressed.
以下将根据当时是否按下键来返回 True 或 False。从你的问题的措辞来看,我假设你不是在问事件处理,这是其他答案所解决的问题。
My.Computer.Keyboard.ShiftKeyDown
My.Computer.Keyboard.CtrlKeyDown
回答by alldayremix
If Control.ModifierKeys = Keys.Shift Or Control.ModifierKeys = Keys.Control Then
' Shift, Ctrl, or Shift+Ctrl is being pressed
Else
' Neither Shift nor Ctrl is being pressed
End If
回答by Orhan Obut
I assume you want to see on whole application. To do this, forms or controls have "keypress" or "keydown" events. You can check them with those events. Click events tab and you'll see them
我假设您想查看整个应用程序。为此,窗体或控件具有“keypress”或“keydown”事件。您可以使用这些事件检查它们。单击事件选项卡,您将看到它们