user1613489
user1613489

Reputation: 11

Key combination without modifier keys

I need to get key combinations like "A" & "B" , "S" & "D" & "F" like that in C#. I can implement key combinations using modifier keys,like Control, Alter. But here, I need the key combinations without using those modifier keys.

Upvotes: 1

Views: 294

Answers (2)

BFree
BFree

Reputation: 103750

The best way to do this would be to P/Invoke GetKeyState. I'm guessing you're dealing with either a WinForms app or a WPF app, but in either case what you can do is in your KeyPressed event call the GetKeyState method and poll the keys you're interested in to see if those are pressed as well. Here's a helpful implementation of GetKeyState:

http://sanity-free.org/17/obtaining_key_state_info_in_dotnet_csharp_getkeystate_implementation.html

Upvotes: 0

Malgaur
Malgaur

Reputation: 1850

You will need to register for the KeyDown and the KeyUp events and keep track off which keys are currently down yourself.

Upvotes: 1

Related Questions