Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 437
  • Last Modified:

EventHandler that listens for a specific keystroke?

Hi
first of all: I use VB.net in Visual studio 2005

I am trying to make an eventhandler that waits (listen) for a specific keystroke which triggers a Sub() where some tasks are performed. How can that be done? For example i wan't to program a script that opens Internet explorer when i press "arrow down" key , opens Frontpage when i press "arrow up" opens excel when i press "arrow left" ?
How can that be done?
0
soriega
Asked:
soriega
  • 3
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You need to specify WHEN the keystroke should be captured:

(1) Only when your app has FOCUS.
(2) At ANY time, regardless of whether your app is in the foreground or not.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
For (2), you can do something like this:
Public Class Form1
 
    Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
        Select Case keyData
            Case Keys.Up
                Debug.Print("Up")
 
            Case Keys.Down
                Debug.Print("Down")
 
            Case Keys.Left
                Debug.Print("Left")
 
            Case Keys.Right
                Debug.Print("Right")
 
        End Select
 
        Return MyBase.ProcessCmdKey(msg, keyData)
    End Function
 
End Class

Open in new window

0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now