I can check whether key is down by Keyboard.IsKeyDown
method. But how can I check specified key is only key which is down?
Asked
Active
Viewed 310 times
3

H.B.
- 166,899
- 29
- 327
- 400

SiberianGuy
- 24,674
- 56
- 152
- 266
4 Answers
1
There is a way to get the current keyboard state and work out what keys are pressed, but its a bit messy and uses the user32.dll. Have a look at the answer to this one.
0
dependant on which key you want to check do something like this
if(Keyboard.IsKeyDown(Key.LeftCtrl))
//do something

The Angry Saxon
- 792
- 2
- 7
- 24
-
1If Key.LeftCtrl is down, it doesn't mean it is the only key which is down – SiberianGuy Mar 26 '12 at 13:20
0
Or if you want to want to do something only if that one key is pressed try something like
if(!Keyboard.IsKeyDown(Key.LeftCtrl)) return;
That will throw them out of the function if the key pressed isn't what is required.

The Angry Saxon
- 792
- 2
- 7
- 24
-
But if there were multiple buttons pressed including LeftCtrl e.g. LeftCtrl and RightCtrl it wouldn't throw you out of the function – Ben Mar 26 '12 at 13:30
0
Maybe you can count the number of KeyDown vs KeyUp? If the counter is 1 and it's the key you want....

mlemay
- 1,622
- 2
- 32
- 53