vb.net 如何确定启动应用程序时是否按下了 SHIFT 或 CTRL 键
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22476342/
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
How to determine if the SHIFT or CTRL key was pressed when launching the application
提问by slayernoah
I need to be able to determine if the SHIFT or CTRL keys were pressed when the application is launched
我需要能够确定在应用程序启动时是否按下了 SHIFT 或 CTRL 键
How can I do this for a Windows Forms Application?
如何为 Windows 窗体应用程序执行此操作?
回答by ?s??? ????
Not sure if this is what you are looking for. The following will return Trueor Falsedepending on whether the key is pressed
不确定这是否是您要查找的内容。以下将返回True或False取决于是否按下该键
My.Computer.Keyboard.CtrlKeyDown
My.Computer.Keyboard.ShiftKeyDown
Example
例子
If My.Computer.Keyboard.CtrlKeyDown Or My.Computer.Keyboard.ShiftKeyDown Then
MsgBox("SHIFT or CTRL key down")
End If
If you are asking about event handling, KeyEventArgs Classis needed. Hereyou can view some examples how to detect shift/ctrl keypress
如果您询问事件处理,KeyEventArgs Class则需要。在这里您可以查看一些如何检测 shift/ctrl 按键的示例
回答by tezzo
Alternative solution using Control.ModifierKeys:
使用Control.ModifierKeys 的替代解决方案:
If Control.ModifierKeys = Keys.Shift Or Control.ModifierKeys = Keys.Control Then
MsgBox("SHIFT or CTRL key pressed.")
End If

