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,108 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
[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
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

710 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