SiberianGuy
SiberianGuy

Reputation: 25312

Check only specified key is down

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

Upvotes: 3

Views: 317

Answers (4)

Ben
Ben

Reputation: 559

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

Upvotes: 1

mlemay
mlemay

Reputation: 1637

Maybe you can count the number of KeyDown vs KeyUp? If the counter is 1 and it's the key you want....

Upvotes: 0

The Angry Saxon
The Angry Saxon

Reputation: 792

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.

Upvotes: 0

The Angry Saxon
The Angry Saxon

Reputation: 792

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

if(Keyboard.IsKeyDown(Key.LeftCtrl))
    //do something

Upvotes: 0

Related Questions