I define this in the page1 in the 'OnNavigatedTo' method
page1.keyEventHandler += (s, k) =>
{
if( k.Key == Key.P )
{
// Do Something ...
}
}
But i need to know if the user pressed on two keys together ... i need to know if the user pressed on the Key.Ctrl+Key.P
How can i do it ?
Thanks 开发者_如何学Python
Here you go:
page1.keyEventHandler += (s, k) => {
if (Keyboard.Modifiers == ModifierKeys.Control && k.Key == Key.P) {
...
}
}
Unfortunately there isn't nice way of doing this. You'll need to fire 2 events. One for each key, like so:
private bool KeyADown = false;
private bool KeyBDown = false;
private void LayoutRoot_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.A)
{
KeyADown = true;
}
else if (e.Key == Key.B)
{
KeyBDown = true;
}
// check for Ctrl+A+B
if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
{
if (KeyADown && KeyBDown)
{
MessageBox.Show("Ctrl+A+B detected");
}
}
}
private void LayoutRoot_KeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.A)
{
KeyADown = false;
}
else if (e.Key == Key.B)
{
KeyBDown = false;
}
}
精彩评论