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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 17:08:54  来源:igfitidea点击:

How to determine if the SHIFT or CTRL key was pressed when launching the application

vb.netwinformsvb.net-2010shiftctrl

提问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

不确定这是否是您要查找的内容。以下将返回TrueFalse取决于是否按下该键

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