Detect Multiple Keystrokes?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Justin

    #1

    Detect Multiple Keystrokes?

    I'm creating a kiosk type application and this would be too simple for
    someone to figure out:

    Private Declare Function GetAsyncKeyStat e 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


  • Oenone

    #2
    Re: Detect Multiple Keystrokes?

    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


    Comment

    • Justin

      #3
      Re: Detect Multiple Keystrokes?

      It works great, Thanks!

      Me.KeyPreview = True

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


      Comment

      Working...