Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

EventHandler that listens for a specific keystroke?

Posted on 2008-06-16
3
Medium Priority
?
436 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 
LVL 86

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 86

Accepted Solution

by:
Mike Tomlinson earned 600 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 86

Expert Comment

by:Mike Tomlinson
ID: 21795754
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

704 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