3

I can check whether key is down by Keyboard.IsKeyDown method. But how can I check specified key is only key which is down?

H.B.
  • 142,212
  • 27
  • 297
  • 366
SiberianGuy
  • 23,286
  • 52
  • 142
  • 260

4 Answers4

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.

https://stackoverflow.com/a/1752761/1232571

Community
  • 1
  • 1
Ben
  • 539
  • 3
  • 7
0

dependant on which key you want to check do something like this

if(Keyboard.IsKeyDown(Key.LeftCtrl))
    //do something
The Angry Saxon
  • 802
  • 2
  • 7
  • 22
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
  • 802
  • 2
  • 7
  • 22
  • 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,582
  • 2
  • 28
  • 51