Home All Groups Group Topic Archive Search About

Detect Multiple Keystrokes?

Author
19 Dec 2006 12:12 AM
Justin
I'm creating a kiosk type application and this would be too simple for
someone to figure out:

Private Declare Function GetAsyncKeyState Lib "user32" ( ByVal vKey As
Short) As Short
Const VK_ESCAPE As Short = &H1B

How can I upgrade this to detect multiple keystrokes?  For example CRTL + E

Any points in the right direction would be much appreciated.  VB.NET 2005

Justin

Author
19 Dec 2006 10:14 AM
Oenone
Justin wrote:
> How can I upgrade this to detect multiple keystrokes?  For example
> CRTL + E

The API call you mention will tell you the state of any key on the keyboard,
so if you want to tell whether CTRL + E is pressed, check to see whether the
Ctrl key is pressed, and if it is, check to see whether the E key is
pressed. If it returns True for both, those two keys (among others,
possibly) are pressed.

Depending on what you're doing, it would probably be better to handle this
using the KeyDown events of a form or control, though:

\\\
If e.KeyCode = Keys.E AndAlso e.Control = True Then
  MsgBox("Ctrl+E was pressed")
End If
///

If you add that to the form's KeyDown event and set the form's KeyPreview
date to True, this will fire every time Ctrl+E is pressed while the form has
focus.

--

(O)enone
Author
19 Dec 2006 5:13 PM
Justin
It works great, Thanks!

Me.KeyPreview = True

Private Sub frmMain_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.E AndAlso e.Control = True Then
Me.Close()
End If
End Sub