Can an event be fired when the shift key is pressed, and when the shift key is released? Can someone please provide sample code for how to do this?
Asked
Active
Viewed 1,572 times
3 Answers
3
private void Window_KeyDown(object sender, KeyEventArgs e)
{
if (!e.IsRepeat && (e.Key == Key.LeftShift || e.Key == Key.RightShift))
{
Trace.WriteLine("Down Shift " + DateTime.Now);
}
}
private void Window_KeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.LeftShift || e.Key == Key.RightShift)
{
Trace.WriteLine("Up Shift " + DateTime.Now);
}
}

kyrylomyr
- 12,192
- 8
- 52
- 79
0
To do this you have to first decide about on which control is activated and on that control you have to generate the Key_press event.
On key_press event you have to check about which key is pressed i.e. you need shift. So you need to code about if shift key is pressed then do functionality you want to do.
So this is the way how you can accomplish.
Hope this can help you.

Bhavik Goyal
- 2,786
- 6
- 23
- 42
0
John, take a look at my solution for the Enter Key. You could certainly apply it to the shift key as well if there is a particular control you want to do this for. Otherwise, please provide more information a solution can be narrowed down.
-
3your link goes to this page. Are you trying to cause a recursion stack overflow *on* StackOverflow?? :) – jb. Mar 12 '11 at 07:48