Added detection of left and right shift/control/alt buttons.

This commit is contained in:
the_fiddler 2008-03-08 17:35:58 +00:00
parent ef16a9d296
commit bc1801d5d5
2 changed files with 28 additions and 4 deletions

View file

@ -525,7 +525,7 @@ namespace OpenTK.Platform.Windows
[System.Security.SuppressUnmanagedCodeSecurity] [System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll", SetLastError = true)] [DllImport("user32.dll", SetLastError = true)]
internal static extern SHORT GetAsyncKeyState(int vKey); internal static extern SHORT GetAsyncKeyState(VirtualKeys vKey);
#endregion #endregion

View file

@ -110,17 +110,41 @@ namespace OpenTK.Platform.Windows
case WindowMessage.SYSKEYUP: case WindowMessage.SYSKEYUP:
bool pressed = (WindowMessage)msg.Msg == WindowMessage.KEYDOWN || bool pressed = (WindowMessage)msg.Msg == WindowMessage.KEYDOWN ||
(WindowMessage)msg.Msg == WindowMessage.SYSKEYDOWN; (WindowMessage)msg.Msg == WindowMessage.SYSKEYDOWN;
//bool left = (((int)msg.LParam) & 0x100000) == 0; // valid for Shift, Control and Menu presses.
switch ((VirtualKeys)msg.WParam) switch ((VirtualKeys)msg.WParam)
{ {
case VirtualKeys.SHIFT: case VirtualKeys.SHIFT:
// Win95 does not distinguish left/right constants (GetAsyncKeyState returns 0).
// In this case, report both keys as down.
bool left = Functions.GetAsyncKeyState(VirtualKeys.LSHIFT) != 0;
bool right = Functions.GetAsyncKeyState(VirtualKeys.RSHIFT) != 0;
if (left)
keyboard[Input.Key.ShiftLeft] = pressed;
if (right)
keyboard[Input.Key.ShiftRight] = pressed;
if (!left && !right)
keyboard[Input.Key.ShiftLeft] = keyboard[Input.Key.ShiftRight] = pressed; keyboard[Input.Key.ShiftLeft] = keyboard[Input.Key.ShiftRight] = pressed;
return; return;
case VirtualKeys.CONTROL: case VirtualKeys.CONTROL:
left = Functions.GetAsyncKeyState(VirtualKeys.LCONTROL) != 0;
right = Functions.GetAsyncKeyState(VirtualKeys.RCONTROL) != 0;
if (left)
keyboard[Input.Key.ControlLeft] = pressed;
if (right)
keyboard[Input.Key.ControlRight] = pressed;
if (!left && !right)
keyboard[Input.Key.ControlLeft] = keyboard[Input.Key.ControlRight] = pressed; keyboard[Input.Key.ControlLeft] = keyboard[Input.Key.ControlRight] = pressed;
return; return;
case VirtualKeys.MENU: case VirtualKeys.MENU:
left = Functions.GetAsyncKeyState(VirtualKeys.LMENU) != 0;
right = Functions.GetAsyncKeyState(VirtualKeys.RMENU) != 0;
if (left)
keyboard[Input.Key.AltLeft] = pressed;
if (right)
keyboard[Input.Key.AltRight] = pressed;
if (!left && !right)
keyboard[Input.Key.AltLeft] = keyboard[Input.Key.AltRight] = pressed; keyboard[Input.Key.AltLeft] = keyboard[Input.Key.AltRight] = pressed;
return; return;