Solved

EventHandler that listens for a specific keystroke?

Posted on 2008-06-16
3
435 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 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 86

Expert Comment

by:Mike Tomlinson
ID: 21795754
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month11 days, 8 hours left to enroll

623 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