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