Added and fixed some scancodes

This commit is contained in:
jonathan.r.paton@googlemail.com 2017-10-04 15:21:18 +01:00 committed by Lukas Dürrenberger
parent 7f9bca43c5
commit 950d10c49f
4 changed files with 210 additions and 100 deletions

View file

@ -45,7 +45,114 @@ namespace priv
////////////////////////////////////////////////////////////
bool InputImpl::isKeyPressed(Keyboard::Key key)
{
return isKeyPressed(unlocalize(key));
int vkey = 0;
switch (key)
{
default: vkey = 0; break;
case Keyboard::A: vkey = 'A'; break;
case Keyboard::B: vkey = 'B'; break;
case Keyboard::C: vkey = 'C'; break;
case Keyboard::D: vkey = 'D'; break;
case Keyboard::E: vkey = 'E'; break;
case Keyboard::F: vkey = 'F'; break;
case Keyboard::G: vkey = 'G'; break;
case Keyboard::H: vkey = 'H'; break;
case Keyboard::I: vkey = 'I'; break;
case Keyboard::J: vkey = 'J'; break;
case Keyboard::K: vkey = 'K'; break;
case Keyboard::L: vkey = 'L'; break;
case Keyboard::M: vkey = 'M'; break;
case Keyboard::N: vkey = 'N'; break;
case Keyboard::O: vkey = 'O'; break;
case Keyboard::P: vkey = 'P'; break;
case Keyboard::Q: vkey = 'Q'; break;
case Keyboard::R: vkey = 'R'; break;
case Keyboard::S: vkey = 'S'; break;
case Keyboard::T: vkey = 'T'; break;
case Keyboard::U: vkey = 'U'; break;
case Keyboard::V: vkey = 'V'; break;
case Keyboard::W: vkey = 'W'; break;
case Keyboard::X: vkey = 'X'; break;
case Keyboard::Y: vkey = 'Y'; break;
case Keyboard::Z: vkey = 'Z'; break;
case Keyboard::Num0: vkey = '0'; break;
case Keyboard::Num1: vkey = '1'; break;
case Keyboard::Num2: vkey = '2'; break;
case Keyboard::Num3: vkey = '3'; break;
case Keyboard::Num4: vkey = '4'; break;
case Keyboard::Num5: vkey = '5'; break;
case Keyboard::Num6: vkey = '6'; break;
case Keyboard::Num7: vkey = '7'; break;
case Keyboard::Num8: vkey = '8'; break;
case Keyboard::Num9: vkey = '9'; break;
case Keyboard::Escape: vkey = VK_ESCAPE; break;
case Keyboard::LControl: vkey = VK_LCONTROL; break;
case Keyboard::LShift: vkey = VK_LSHIFT; break;
case Keyboard::LAlt: vkey = VK_LMENU; break;
case Keyboard::LSystem: vkey = VK_LWIN; break;
case Keyboard::RControl: vkey = VK_RCONTROL; break;
case Keyboard::RShift: vkey = VK_RSHIFT; break;
case Keyboard::RAlt: vkey = VK_RMENU; break;
case Keyboard::RSystem: vkey = VK_RWIN; break;
case Keyboard::Menu: vkey = VK_APPS; break;
case Keyboard::LBracket: vkey = VK_OEM_4; break;
case Keyboard::RBracket: vkey = VK_OEM_6; break;
case Keyboard::SemiColon: vkey = VK_OEM_1; break;
case Keyboard::Comma: vkey = VK_OEM_COMMA; break;
case Keyboard::Period: vkey = VK_OEM_PERIOD; break;
case Keyboard::Quote: vkey = VK_OEM_7; break;
case Keyboard::Slash: vkey = VK_OEM_2; break;
case Keyboard::BackSlash: vkey = VK_OEM_5; break;
case Keyboard::Tilde: vkey = VK_OEM_3; break;
case Keyboard::Equal: vkey = VK_OEM_PLUS; break;
case Keyboard::Dash: vkey = VK_OEM_MINUS; break;
case Keyboard::Space: vkey = VK_SPACE; break;
case Keyboard::Return: vkey = VK_RETURN; break;
case Keyboard::BackSpace: vkey = VK_BACK; break;
case Keyboard::Tab: vkey = VK_TAB; break;
case Keyboard::PageUp: vkey = VK_PRIOR; break;
case Keyboard::PageDown: vkey = VK_NEXT; break;
case Keyboard::End: vkey = VK_END; break;
case Keyboard::Home: vkey = VK_HOME; break;
case Keyboard::Insert: vkey = VK_INSERT; break;
case Keyboard::Delete: vkey = VK_DELETE; break;
case Keyboard::Add: vkey = VK_ADD; break;
case Keyboard::Subtract: vkey = VK_SUBTRACT; break;
case Keyboard::Multiply: vkey = VK_MULTIPLY; break;
case Keyboard::Divide: vkey = VK_DIVIDE; break;
case Keyboard::Left: vkey = VK_LEFT; break;
case Keyboard::Right: vkey = VK_RIGHT; break;
case Keyboard::Up: vkey = VK_UP; break;
case Keyboard::Down: vkey = VK_DOWN; break;
case Keyboard::Numpad0: vkey = VK_NUMPAD0; break;
case Keyboard::Numpad1: vkey = VK_NUMPAD1; break;
case Keyboard::Numpad2: vkey = VK_NUMPAD2; break;
case Keyboard::Numpad3: vkey = VK_NUMPAD3; break;
case Keyboard::Numpad4: vkey = VK_NUMPAD4; break;
case Keyboard::Numpad5: vkey = VK_NUMPAD5; break;
case Keyboard::Numpad6: vkey = VK_NUMPAD6; break;
case Keyboard::Numpad7: vkey = VK_NUMPAD7; break;
case Keyboard::Numpad8: vkey = VK_NUMPAD8; break;
case Keyboard::Numpad9: vkey = VK_NUMPAD9; break;
case Keyboard::F1: vkey = VK_F1; break;
case Keyboard::F2: vkey = VK_F2; break;
case Keyboard::F3: vkey = VK_F3; break;
case Keyboard::F4: vkey = VK_F4; break;
case Keyboard::F5: vkey = VK_F5; break;
case Keyboard::F6: vkey = VK_F6; break;
case Keyboard::F7: vkey = VK_F7; break;
case Keyboard::F8: vkey = VK_F8; break;
case Keyboard::F9: vkey = VK_F9; break;
case Keyboard::F10: vkey = VK_F10; break;
case Keyboard::F11: vkey = VK_F11; break;
case Keyboard::F12: vkey = VK_F12; break;
case Keyboard::F13: vkey = VK_F13; break;
case Keyboard::F14: vkey = VK_F14; break;
case Keyboard::F15: vkey = VK_F15; break;
case Keyboard::Pause: vkey = VK_PAUSE; break;
}
return (GetAsyncKeyState(vkey) & 0x8000) != 0;
}
////////////////////////////////////////////////////////////
@ -74,10 +181,10 @@ Keyboard::Scancode InputImpl::unlocalize(Keyboard::Key code)
////////////////////////////////////////////////////////////
String InputImpl::getDescription(Keyboard::Scancode code)
{
LONG lparam = sfScanToWin(code);
WORD winCode = sfScanToWin(code);
const int bufSize(1024);
WCHAR name[bufSize];
int result = GetKeyNameText(lparam, name, bufSize);
int result = GetKeyNameText(winCode << 16, name, bufSize);
if (result > 0)
{
return name;
@ -181,7 +288,7 @@ Vector2i InputImpl::getTouchPosition(unsigned int /*finger*/, const WindowBase&
}
////////////////////////////////////////////////////////////
LONG InputImpl::sfScanToWin(Keyboard::Scancode code)
WORD InputImpl::sfScanToWin(Keyboard::Scancode code)
{
// Windows scan codes
// Reference: https://msdn.microsoft.com/en-us/library/aa299374(v=vs.60).aspx
@ -225,99 +332,98 @@ LONG InputImpl::sfScanToWin(Keyboard::Scancode code)
case Keyboard::ScanNum9: return 10;
case Keyboard::ScanNum0: return 11;
case Keyboard::ScanEnter: return 28;
case Keyboard::ScanEscape: return 1;
case Keyboard::ScanBackspace: return 14;
case Keyboard::ScanTab: return 15;
case Keyboard::ScanSpace: return 57;
case Keyboard::ScanHyphen: return 12;
case Keyboard::ScanEquals: return 13;
case Keyboard::ScanLBracket: return 26;
case Keyboard::ScanRBracket: return 27;
case Keyboard::ScanBackslash: return 43;
case Keyboard::ScanDash: return 41;
case Keyboard::ScanSemicolon: return 39;
case Keyboard::ScanQuote: return 40;
//case Keyboard::ScanGraveAccent: return ? ? ?
case Keyboard::ScanComma: return 51;
case Keyboard::ScanPeriod: return 52;
case Keyboard::ScanSlash: return 53;
case Keyboard::ScanEnter: return 28;
case Keyboard::ScanEscape: return 1;
case Keyboard::ScanBackspace: return 14;
case Keyboard::ScanTab: return 15;
case Keyboard::ScanSpace: return 57;
case Keyboard::ScanHyphen: return 12;
case Keyboard::ScanEquals: return 13;
case Keyboard::ScanLBracket: return 26;
case Keyboard::ScanRBracket: return 27;
case Keyboard::ScanBackslash: return 43;
case Keyboard::ScanDash: return 41;
case Keyboard::ScanSemicolon: return 39;
case Keyboard::ScanQuote: return 40;
//case Keyboard::ScanGraveAccent: return ? ? ?
case Keyboard::ScanComma: return 51;
case Keyboard::ScanPeriod: return 52;
case Keyboard::ScanSlash: return 53;
case Keyboard::ScanF1: return 59;
case Keyboard::ScanF2: return 60;
case Keyboard::ScanF3: return 61;
case Keyboard::ScanF4: return 62;
case Keyboard::ScanF5: return 63;
case Keyboard::ScanF6: return 64;
case Keyboard::ScanF7: return 65;
case Keyboard::ScanF8: return 66;
case Keyboard::ScanF9: return 67;
case Keyboard::ScanF10: return 68;
case Keyboard::ScanF11: return MAKELONG(87, KF_EXTENDED);
case Keyboard::ScanF12: return MAKELONG(88, KF_EXTENDED);
//case Keyboard::ScanF13: return ???
//case Keyboard::ScanF14: return ???
//case Keyboard::ScanF15: return ???
case Keyboard::ScanF1: return 59;
case Keyboard::ScanF2: return 60;
case Keyboard::ScanF3: return 61;
case Keyboard::ScanF4: return 62;
case Keyboard::ScanF5: return 63;
case Keyboard::ScanF6: return 64;
case Keyboard::ScanF7: return 65;
case Keyboard::ScanF8: return 66;
case Keyboard::ScanF9: return 67;
case Keyboard::ScanF10: return 68;
case Keyboard::ScanF11: return KF_EXTENDED | 87;
case Keyboard::ScanF12: return KF_EXTENDED | 88;
//case Keyboard::ScanF13: return ???
//case Keyboard::ScanF14: return ???
//case Keyboard::ScanF15: return ???
case Keyboard::ScanCapsLock: return 58;
case Keyboard::ScanPrintScreen: return 55;
case Keyboard::ScanScrollLock: return 70;
//case Keyboard::ScanPause: return ???;
case Keyboard::ScanInsert: return 82;
case Keyboard::ScanHome: return 71;
case Keyboard::ScanPageUp: return 73;
case Keyboard::ScanDelete: return 83;
case Keyboard::ScanEnd: return 79;
case Keyboard::ScanPageDown: return 81;
case Keyboard::ScanRight: return 77;
case Keyboard::ScanLeft: return 75;
case Keyboard::ScanDown: return 80;
case Keyboard::ScanUp: return 72;
case Keyboard::ScanNumLock: return 69;
case Keyboard::ScanDivide: return 53;
//case Keyboard::ScanMultiply: return ??? ;
case Keyboard::ScanMinus: return 74;
case Keyboard::ScanPlus: return 78;
case Keyboard::ScanCapsLock: return 58;
case Keyboard::ScanPrintScreen: return 55 | KF_EXTENDED;
case Keyboard::ScanScrollLock: return 70;
case Keyboard::ScanPause: return 69;
case Keyboard::ScanInsert: return 82 | KF_EXTENDED;
case Keyboard::ScanHome: return 71 | KF_EXTENDED;
case Keyboard::ScanPageUp: return 73 | KF_EXTENDED;
case Keyboard::ScanDelete: return 83 | KF_EXTENDED;
case Keyboard::ScanEnd: return 79 | KF_EXTENDED;
case Keyboard::ScanPageDown: return 81 | KF_EXTENDED;
case Keyboard::ScanRight: return 77 | KF_EXTENDED;
case Keyboard::ScanLeft: return 75 | KF_EXTENDED;
case Keyboard::ScanDown: return 80 | KF_EXTENDED;
case Keyboard::ScanUp: return 72 | KF_EXTENDED;
case Keyboard::ScanNumLock: return 69 | KF_EXTENDED;
case Keyboard::ScanDivide: return 53;
case Keyboard::ScanMultiply: return 55;
case Keyboard::ScanMinus: return 74;
case Keyboard::ScanPlus: return 78;
//case Keyboard::ScanPadEquals: return ???;
case Keyboard::ScanNumpadEnter: return MAKELONG(28, KF_EXTENDED);
case Keyboard::ScanDecimal: return MAKELONG(83, KF_EXTENDED);
case Keyboard::ScanNumpadEnter: return KF_EXTENDED | 28;
case Keyboard::ScanDecimal: return 83;
// Num pad keys except 5 have the extended bit (0x100) set
case Keyboard::ScanNumpad1: return MAKELONG(79, KF_EXTENDED);
case Keyboard::ScanNumpad2: return MAKELONG(80, KF_EXTENDED);
case Keyboard::ScanNumpad3: return MAKELONG(81, KF_EXTENDED);
case Keyboard::ScanNumpad4: return MAKELONG(75, KF_EXTENDED);
case Keyboard::ScanNumpad1: return 79;
case Keyboard::ScanNumpad2: return 80;
case Keyboard::ScanNumpad3: return 81 ;
case Keyboard::ScanNumpad4: return 75 ;
case Keyboard::ScanNumpad5: return 76;
case Keyboard::ScanNumpad6: return MAKELONG(77, KF_EXTENDED);
case Keyboard::ScanNumpad7: return MAKELONG(71, KF_EXTENDED);
case Keyboard::ScanNumpad8: return MAKELONG(72, KF_EXTENDED);
case Keyboard::ScanNumpad9: return MAKELONG(73, KF_EXTENDED);
case Keyboard::ScanNumpad0: return MAKELONG(82, KF_EXTENDED);
case Keyboard::ScanNumpad6: return 77 ;
case Keyboard::ScanNumpad7: return 71 ;
case Keyboard::ScanNumpad8: return 72 ;
case Keyboard::ScanNumpad9: return 73 ;
case Keyboard::ScanNumpad0: return 82 ;
//case Keyboard::ScanReverseSolidus: return ? ? ? ;
//case Keyboard::ScanApplication: return ? ? ? ;
//case Keyboard::ScanExecute: return ? ? ? ;
//case Keyboard::ScanHelp: return ? ? ? ;
//case Keyboard::ScanMenu: return ? ? ? ;
//case Keyboard::ScanSelect: return ? ? ? ;
//case Keyboard::ScanStop: return ? ? ? ;
//case Keyboard::ScanAgain: return ? ? ? ;
//case Keyboard::ScanUndo: return ? ? ? ;
//case Keyboard::ScanCut: return ? ? ? ;
//case Keyboard::ScanCopy: return ? ? ? ;
//case Keyboard::ScanPaste: return ? ? ? ;
//case Keyboard::ScanFind: return ? ? ? ;
//case Keyboard::ScanMute: return ? ? ? ;
//case Keyboard::ScanVolumeUp: return ? ? ? ;
//case Keyboard::ScanVolumeDown: return ? ? ? ;
case Keyboard::ScanLControl: return 29;
case Keyboard::ScanLShift: return 42;
case Keyboard::ScanLAlt: return 56;
//case Keyboard::ScanLSystem: return ? ? ? ;
case Keyboard::ScanRControl: return MAKELONG(29 ,KF_EXTENDED);
case Keyboard::ScanRShift: return 54;
case Keyboard::ScanRAlt: return 56;
//case Keyboard::ScanRSystem: return ? ? ? ;
//case Keyboard::ScanReverseSolidus: return ? ? ? ;
//case Keyboard::ScanApplication: return ? ? ? ;
//case Keyboard::ScanExecute: return ? ? ? ;
//case Keyboard::ScanHelp: return ? ? ? ;
case Keyboard::ScanMenu: return 93 | KF_EXTENDED;
//case Keyboard::ScanSelect: return ? ? ? ;
//case Keyboard::ScanStop: return ? ? ? ;
//case Keyboard::ScanAgain: return ? ? ? ;
//case Keyboard::ScanUndo: return ? ? ? ;
//case Keyboard::ScanCut: return ? ? ? ;
//case Keyboard::ScanCopy: return ? ? ? ;
//case Keyboard::ScanPaste: return ? ? ? ;
//case Keyboard::ScanFind: return ? ? ? ;
//case Keyboard::ScanMute: return ? ? ? ;
//case Keyboard::ScanVolumeUp: return ? ? ? ;
//case Keyboard::ScanVolumeDown: return ? ? ? ;
case Keyboard::ScanLControl: return 29;
case Keyboard::ScanLShift: return 42;
case Keyboard::ScanLAlt: return 56;
case Keyboard::ScanLSystem: return 91 | KF_EXTENDED ;
case Keyboard::ScanRControl: return KF_EXTENDED | 29;
case Keyboard::ScanRShift: return 54;
case Keyboard::ScanRAlt: return 56;
//case Keyboard::ScanRSystem: return ? ? ? ;
default: return 0; // Not sure what to return here?
}

View file

@ -180,7 +180,7 @@ public:
private:
static LONG sfScanToWin(Keyboard::Scancode code);
static WORD sfScanToWin(Keyboard::Scancode code);
};
} // namespace priv

View file

@ -620,7 +620,7 @@ Keyboard::Scancode WindowImplWin32::toScancode(LPARAM flags)
case 52: return Keyboard::ScanPeriod;
case 53: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::ScanDivide : Keyboard::ScanForwardSlash;
case 54: return Keyboard::ScanRShift;
case 55: return Keyboard::ScanPrintScreen;
case 55: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::ScanPrintScreen : Keyboard::ScanMultiply;
case 56: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::ScanRAlt : Keyboard::ScanLAlt;
case 57: return Keyboard::ScanSpace;
case 58: return Keyboard::ScanCapsLock;
@ -636,7 +636,7 @@ Keyboard::Scancode WindowImplWin32::toScancode(LPARAM flags)
case 68: return Keyboard::ScanF10;
case 87: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::ScanUnknown : Keyboard::ScanF11;
case 88: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::ScanUnknown : Keyboard::ScanF12;
case 69: return Keyboard::ScanNumLock;
case 69: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::ScanNumLock : Keyboard::ScanPause;
case 70: return Keyboard::ScanScrollLock;
case 71: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::ScanHome : Keyboard::ScanNumpad7;
case 72: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::ScanUp : Keyboard::ScanNumpad8;
@ -650,7 +650,10 @@ Keyboard::Scancode WindowImplWin32::toScancode(LPARAM flags)
case 80: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::ScanDown : Keyboard::ScanNumpad2;
case 81: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::ScanPageDown : Keyboard::ScanNumpad3;
case 82: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::ScanInsert : Keyboard::ScanNumpad0;
case 83: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::ScanDecimal : Keyboard::ScanNumpad4;
case 83: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::ScanDelete : Keyboard::ScanDecimal;
case 91: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::ScanLSystem : Keyboard::ScanUnknown;
case 93: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::ScanMenu : Keyboard::ScanUnknown;
default: return Keyboard::ScanUnknown;
}
@ -830,7 +833,7 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
event.key.shift = HIWORD(GetKeyState(VK_SHIFT)) != 0;
event.key.system = HIWORD(GetKeyState(VK_LWIN)) || HIWORD(GetKeyState(VK_RWIN));
event.key.scancode = toScancode(lParam);
event.key.code = virtualKeyCodeToSF(wParam, lParam, event.key.scancode);
event.key.code = virtualKeyCodeToSF(wParam, lParam);
pushEvent(event);
}
break;
@ -847,7 +850,7 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
event.key.shift = HIWORD(GetKeyState(VK_SHIFT)) != 0;
event.key.system = HIWORD(GetKeyState(VK_LWIN)) || HIWORD(GetKeyState(VK_RWIN));
event.key.scancode = toScancode(lParam);
event.key.code = virtualKeyCodeToSF(wParam, lParam, event.key.scancode);
event.key.code = virtualKeyCodeToSF(wParam, lParam);
pushEvent(event);
break;
}
@ -1098,7 +1101,7 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
////////////////////////////////////////////////////////////
Keyboard::Key WindowImplWin32::virtualKeyCodeToSF(WPARAM key, LPARAM flags, Keyboard::Scancode code)
Keyboard::Key WindowImplWin32::virtualKeyCodeToSF(WPARAM key, LPARAM flags)
{
switch (key)
{
@ -1106,7 +1109,8 @@ Keyboard::Key WindowImplWin32::virtualKeyCodeToSF(WPARAM key, LPARAM flags, Keyb
case VK_SHIFT:
{
static UINT lShift = MapVirtualKeyW(VK_LSHIFT, MAPVK_VK_TO_VSC);
return code == lShift ? Keyboard::LShift : Keyboard::RShift;
UINT scancode = static_cast<UINT>((flags & (0xFF << 16)) >> 16);
return scancode == lShift ? Keyboard::LShift : Keyboard::RShift;
}
// Check the "extended" flag to distinguish between left and right alt

View file

@ -254,7 +254,7 @@ private:
/// \return SFML key code corresponding to the key
///
////////////////////////////////////////////////////////////
static Keyboard::Key virtualKeyCodeToSF(WPARAM key, LPARAM flags, Keyboard::Scancode code);
static Keyboard::Key virtualKeyCodeToSF(WPARAM key, LPARAM flags);
////////////////////////////////////////////////////////////
/// \brief Convert win32 message flags to scancode