How can I capture multiple key downs in C# when working in a Windows Forms form?
I just can’t seem to get both the up arrow and right arrow at the same time.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think you’ll be best off when you use the GetKeyboardState API function.
In the KeyDown event, you just ask for the ‘state’ of the keyboard. The GetKeyboardState will populate the byte array that you give, and every element in this array represents the state of a key.
You can access each keystate by using the numerical value of each virtual key code. When the byte for that key is set to 129 or 128, it means that the key is down (pressed). If the value for that key is 1 or 0, the key is up (not pressed). The value 1 is meant for toggled key state (for example, caps lock state).
For details see the Microsoft documentation for GetKeyboardState.