Link to home
Start Free TrialLog in
Avatar of endrec
endrec

asked on

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

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)?
ASKER CERTIFIED SOLUTION
Avatar of getnitincr
getnitincr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Stephan
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