Sunday, January 25, 2015

Track key press and key release on WPF applications

You want to track the Up and Down events. If you only use the Up event, then the variable will only be set to false when another key triggers the Up event:



private void PlotListView_KeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.Up || e.Key == Key.Down)
{
// set to true if either up or down key is pressed
_upDownKeyIsPressed = true;
}
}
private void PlotListView_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Up || e.Key == Key.Down)
{
// set to false if either up or down key is depressed
_upDownKeyIsPressed = false;
}
}






No comments:

Post a Comment