ahammar
asked on
Detect if shift key is down
Hello all,
How can I tell if my shift key is pressed even when my app does not have focus. I already have it so that it captures keys, but I can't figure out how to tell if the shift key is down. I am not too good with API's, but I was able to alter some code that I got to capture only the keys I wanted, so please by descriptive in how I need to use whatever code you give me. I tried using GetAsyncKeyState, but I couldn't get it to work. I could be going about all wrong though, or maybe that's not even what I should use.
Thanks and Cheers!
ahammar
How can I tell if my shift key is pressed even when my app does not have focus. I already have it so that it captures keys, but I can't figure out how to tell if the shift key is down. I am not too good with API's, but I was able to alter some code that I got to capture only the keys I wanted, so please by descriptive in how I need to use whatever code you give me. I tried using GetAsyncKeyState, but I couldn't get it to work. I could be going about all wrong though, or maybe that's not even what I should use.
Thanks and Cheers!
ahammar
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks navstar16
I already had a keyboard hook, I just didn't know how to use the GetAsyncKeyState API, or if that was even what I needed.
I got it to work though by reviewing the second link you listed.
Thanks!
Cheers!
ahammar
I already had a keyboard hook, I just didn't know how to use the GetAsyncKeyState API, or if that was even what I needed.
I got it to work though by reviewing the second link you listed.
Thanks!
Cheers!
ahammar
I'm not sure why you need to check for the shift key when your app does NOT have the focus, so I'll leave that part to the API experts.
For the form, you can handle this through the KeyDown/KeyUp events where you can check the state of the Shift key/Control key/Alt key.
If you want it ANYWHERE on the form, you'll need to change the form'sKeyPreview property then use the form's KeyDown/KeyUp event to get the state.