Solved

EventHandler that listens for a specific keystroke?

Posted on 2008-06-16
3
429 Views
Last Modified: 2012-06-27
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
Comment
Question by:soriega
  • 3
3 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 21795712
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
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 200 total points
ID: 21795742
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
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 21795754
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now