How to use three different keys e.g. (Ctrl Shift O) to open a form in vb.net?

情到浓时终转凉″ 提交于 2019-12-11 04:04:09

问题


I need to use three different keys e.g, (Ctrl + Shift + F12) to open another form in vb.net.

Please help me.


回答1:


In the keydown event you can access these keys. For example, in this handler...

Private Sub keyDown(ByVal Sender As Object, ByVal e As KeyEventArgs) handles me.keydown

...you can use the booleans e.Alt, e.Control, and e.Shift to tell whether those control keys are down. Then you can do something like this:

Select case CInt(e.keycode)
  case Keys.F12
    if e.Control andalso e.Shift then frm.ShowDialog
    ...



回答2:


Define this function:

Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As IntPtr) As Short

So you can check wich keys are pressed at the same moment:

'For example, keys "arrow up" and letter "W"
If GetKeyState(87) < 0 AndAlso GetKeyState(38) < 0 Then
     'Do something
End If

And you can check the keys in a KeyDown event or with a Timer or anything. Hope this helps.




回答3:


You can handle it with key events as in xpda's answer, or, if you already have a MenuItem to do the same action, you can set the ShortcutKeys property of the ToolStripMenuItem.



来源:https://stackoverflow.com/questions/14373100/how-to-use-three-different-keys-e-g-ctrl-shift-o-to-open-a-form-in-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!