Solved

How to capture multiple key presses (including modifier keys) to record, e.g. user pressed Ctrl+E, in C#?

Posted on 2010-11-14
2
1,103 Views
Last Modified: 2013-12-17
Hi,
I wanted to know if there is a way to capture multiple keypress or keydown events including modifier keys.  For example:  How would I be able to tell that a user pressed multiple keys at the same time, using keypress or keydown events, for an application that would allow them to set commands/shortcuts (e.g. user pressed Ctrl+Shift+E)?
0
Comment
Question by:endrec
2 Comments
 
LVL 2

Accepted Solution

by:
getnitincr earned 500 total points
ID: 34134086
protected override void OnPreviewKeyDown(KeyEventArgs e)
    {
       if ((e.Key == Key.V || e.Key == Key.X || e.Key == Key.C)
          && Keyboard.IsKeyDown(Key.LeftCtrl))
        return;
0
 
LVL 16

Expert Comment

by:Stephan
ID: 34134090
Try this out:


[DllImport ("user32.dll")]
public static extern int GetKeyboardState( byte[] keystate );


private void Form1_KeyDown( object sender, KeyEventArgs e )
{
   byte[] keys = new byte[255];

   GetKeyboardState (keys);

   if( keys[(int)Keys.Up] == 129 && keys[(int)Keys.Right] == 129 )
   {
       Console.WriteLine ("Up Arrow key and Right Arrow key down.");
   }
}

Open in new window

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

760 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

16 Experts available now in Live!

Get 1:1 Help Now