Can you detect a combination of keys pressed with a KeyPressed event handler on a Windows.Form?
I want to detect the UP and RIGHT arrow for example being pressed together (to move something diagonally)
Printable View
Can you detect a combination of keys pressed with a KeyPressed event handler on a Windows.Form?
I want to detect the UP and RIGHT arrow for example being pressed together (to move something diagonally)
hi - i had a similar problem and posed the same question elsewhere.
my reply was to use
then use something likeCode:public static bool IsKeyDown(Keys key)
{
return GetAsyncKeyState((int)key) < 0;
}
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern short GetAsyncKeyState(int vkey);
this will return the state of every key on the keyboard allowing you to check for simultaneous key presses.Code:bool temp;
if ((temp = IsKeyDown(Keys.Right)) && (temp = IsKeyDown(Keys.Left)))
//do something here depending on keys ( right & left at same time in this case)
hope this helps
Yup. That works fine :)