PDA

View Full Version : multiple keydown captures



jOch
September 29th, 2008, 04:04 PM
Hi, I am hoping to get some ideas on how to achieve the following..

I am trying to capture multiple keydowns in order to execute certain event..

I'm using WPF and C#... I've tried the following to test... it doesn't work, so I am hoping to get some ideas...



private void test(object sender, System.Windows.Input.KeyEventArgs e)
{
if (e.Key == System.Windows.Input.Key.H && e.Key == System.Windows.Input.Key.LeftCtrl
&& e.Key == System.Windows.Input.Key.System)
{
MessageBox.Show("Key pressed is: " + e.Key);
}
}



I am basically trying to capture Ctrl+Alt+h..

zac8141
October 10th, 2008, 07:31 PM
i havent c#, but i think you could use the "get asynckeystate"

Krilnon
October 10th, 2008, 07:38 PM
The reason that your code is not working is that e.Key only references the most recently pressed key, so it can't be equal to 3 different keys at once.

If nothing else, couldn't you maintain a list/array of the currently pressed keys? You could update the list with handlers for KeyUps and KeyDowns and figure out whether a certain combination of keys was pressed by iterating through the array. I'm not sure if there is built-in functionality to do this, but it would be easy enough to implement.