Initial Windows implementation

This commit is contained in:
jonathan.r.paton@googlemail.com 2017-09-28 20:28:42 +01:00 committed by Lukas Dürrenberger
parent 34197ba5b5
commit a34d48c42d
5 changed files with 454 additions and 156 deletions

View File

@ -29,7 +29,6 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Window/Export.hpp> #include <SFML/Window/Export.hpp>
#include <SFML/System/String.hpp>
namespace sf namespace sf
@ -318,158 +317,6 @@ public:
ScanCodeCount ///< Keep last -- the total number of scancodes ScanCodeCount ///< Keep last -- the total number of scancodes
}; };
////////////////////////////////////////////////////////////
/// \brief Scancodes
///
/// The enumerators are bound to a physical key and do *not* depend
/// on the keyboard layout used by the operating system. Usually, the AT-101
/// keyboard can be used as reference for the physical position of the keys.
///
/// The scancodes are based on a subset of Table 12: Keyboard/Keypad Page
/// of Universal Serial Bus (USB): HID Usage Tables, v1.12.
///
/// \todo When porting this for SFML 3, remove the `s` prefix and use
/// enum class.
///
////////////////////////////////////////////////////////////
enum Scancode
{
ScanUnknown = -1, ///< Represents any scancode not present in this enum
ScanA = 0, ///< Keyboard a and A key
ScanB, ///< Keyboard b and B key
ScanC, ///< Keyboard c and C key
ScanD, ///< Keyboard d and D key
ScanE, ///< Keyboard e and E key
ScanF, ///< Keyboard f and F key
ScanG, ///< Keyboard g and G key
ScanH, ///< Keyboard h and H key
ScanI, ///< Keyboard i and I key
ScanJ, ///< Keyboard j and J key
ScanK, ///< Keyboard k and K key
ScanL, ///< Keyboard l and L key
ScanM, ///< Keyboard m and M key
ScanN, ///< Keyboard n and N key
ScanO, ///< Keyboard o and O key
ScanP, ///< Keyboard p and P key
ScanQ, ///< Keyboard q and Q key
ScanR, ///< Keyboard r and R key
ScanS, ///< Keyboard s and S key
ScanT, ///< Keyboard t and T key
ScanU, ///< Keyboard u and U key
ScanV, ///< Keyboard v and V key
ScanW, ///< Keyboard w and W key
ScanX, ///< Keyboard x and X key
ScanY, ///< Keyboard y and Y key
ScanZ, ///< Keyboard z and Z key
ScanNum1, ///< Keyboard 1 and ! key
ScanNum2, ///< Keyboard 2 and @ key
ScanNum3, ///< Keyboard 3 and # key
ScanNum4, ///< Keyboard 4 and $ key
ScanNum5, ///< Keyboard 5 and % key
ScanNum6, ///< Keyboard 6 and ^ key
ScanNum7, ///< Keyboard 7 and & key
ScanNum8, ///< Keyboard 8 and * key
ScanNum9, ///< Keyboard 9 and ) key
ScanNum0, ///< Keyboard 0 and ) key
ScanEnter, ///< Keyboard Return (ENTER) key
ScanEscape, ///< Keyboard Escape key
ScanBackspace, ///< Keyboard Backspace key
// TODO above it's BackSpace, but is it correct? What do we use here?
ScanTab, ///< Keyboard Tab key
ScanSpace, ///< Keyboard Space key
ScanHyphen, ///< Keyboard - and _ key
ScanEquals, ///< Keyboard = and +
ScanLBracket, ///< Keyboard [ and { key
ScanRBracket, ///< Keyboard ] and } key
ScanBackslash, ///< Keyboard \ and | key
// TODO capitalisation
ScanDash, ///< Keyboard Non-US # and ~
ScanSemicolon, ///< Keyboard ; and : key
// TODO capitalisation
ScanQuote, ///< Keyboard ' and " key
ScanGraveAccent, ///< Keyboard ` and ~ key
ScanComma, ///< Keyboard , and < key
ScanPeriod, ///< Keyboard . and > key
ScanForwardSlash, ///< Keyboard / and ? key
ScanF1, ///< Keyboard F1 key
ScanF2, ///< Keyboard F2 key
ScanF3, ///< Keyboard F3 key
ScanF4, ///< Keyboard F4 key
ScanF5, ///< Keyboard F5 key
ScanF6, ///< Keyboard F6 key
ScanF7, ///< Keyboard F7 key
ScanF8, ///< Keyboard F8 key
ScanF9, ///< Keyboard F9 key
ScanF10, ///< Keyboard F10 key
ScanF11, ///< Keyboard F11 key
ScanF12, ///< Keyboard F12 key
ScanF13, ///< Keyboard F13 key
ScanF14, ///< Keyboard F14 key
ScanF15, ///< Keyboard F15 key
ScanCapsLock, ///< Keyboard Caps Lock key
ScanPrintScreen, ///< Keyboard Print Screen key
ScanScrollLock, ///< Keyboard Scroll Lock key
ScanPause, ///< Keyboard Pause key
ScanInsert, ///< Keyboard Insert key
ScanHome, ///< Keyboard Home key
ScanPageUp, ///< Keyboard Page Up key
ScanDelete, ///< Keyboard Delete Forward key
ScanEnd, ///< Keyboard End key
ScanPageDown, ///< Keyboard Page Down key
ScanRight, ///< Keyboard Right Arrow key
ScanLeft, ///< Keyboard Left Arrow key
ScanDown, ///< Keyboard Down Arrow key
ScanUp, ///< Keyboard Up Arrow key
ScanNumLock, ///< Keypad Num Lock and Clear key
ScanDivide, ///< Keypad / key
ScanMultiply, ///< Keypad * key
ScanMinus, ///< Keypad - key
ScanPlus, ///< Keypad + key
ScanPadEquals, ///< keypad = key, probably Mac only
ScanReturn, ///< Keypad Enter (return) key
ScanDecimal, ///< Keypad . and Delete key
ScanNumpad1, ///< Keypad 1 and End key
ScanNumpad2, ///< Keypad 2 and Down Arrow key
ScanNumpad3, ///< Keypad 3 and Page Down key
ScanNumpad4, ///< Keypad 4 and Left Arrow key
ScanNumpad5, ///< Keypad 5 key
ScanNumpad6, ///< Keypad 6 and Right Arrow key
ScanNumpad7, ///< Keypad 7 and Home key
ScanNumpad8, ///< Keypad 8 and Up Arrow key
ScanNumpad9, ///< Keypad 9 and Page Up key
ScanNumpad0, ///< Keypad 0 and Insert key
ScanReverseSolidus, ///< Keyboard Non-US \ and | key
// FIXME what is this one? Might need better name. The doc says:
// - Typically near the Left-Shift key in AT-102 implementations.
// - Typical language mappings: Belg:<\> FrCa:«°» Dan:<\> Dutch:]|[ Fren:<> Ger:<|> Ital:<> LatAm:<> Nor:<> Span:<> Swed:<|> Swiss:<\> UK:\| Brazil: \|.
// What is the difference with "regular" \ and | key?
ScanApplication, ///< Keyboard Application key
ScanExecute, ///< Keyboard Execute key
ScanHelp, ///< Keyboard Help key
ScanMenu, ///< Keyboard Menu key
ScanSelect, ///< Keyboard Select key
ScanStop, ///< Keyboard Stop key
ScanAgain, ///< Keyboard Again key
ScanUndo, ///< Keyboard Undo key
ScanCut, ///< Keyboard Cut key
ScanCopy, ///< Keyboard Copy key
ScanPaste, ///< Keyboard Paste key
ScanFind, ///< Keyboard Find key
ScanMute, ///< Keyboard Mute key
ScanVolumeUp, ///< Keyboard Volume Up key
ScanVolumeDown, ///< Keyboard Volume Down key
ScanLControl, ///< Keyboard Left Control key
ScanLShift, ///< Keyboard Left Shift key
ScanLAlt, ///< Keyboard Left Alt key
ScanLSystem, ///< Keyboard Left System key
ScanRControl, ///< Keyboard Right Control key
ScanRShift, ///< Keyboard Right Shift key
ScanRAlt, ///< Keyboard Right Alt key
ScanRSystem, ///< Keyboard Right System key
ScanCodeCount ///< Keep last -- the total number of scancodes
};
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Check if a key is pressed /// \brief Check if a key is pressed
/// ///

View File

@ -43,7 +43,122 @@ namespace sf
namespace priv namespace priv
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool InputImpl::isKeyPressed(Keyboard::Key key) Keyboard::Scancode InputImpl::m_keyToScancodeMapping[Keyboard::KeyCount]; ///< Mapping from Key to Scancode
Keyboard::Key InputImpl::m_scancodeToKeyMapping[Keyboard::ScanCodeCount]; ///< Mapping from Scancode to Key
////////////////////////////////////////////////////////////
Keyboard::Key winKeyToSfKey(int vkey)
{
Keyboard::Key key;
switch (vkey)
{
default: key = Keyboard::Unknown; break;
case 'A': key = Keyboard::A; break;
case 'B': key = Keyboard::B; break;
case 'C': key = Keyboard::C; break;
case 'D': key = Keyboard::D; break;
case 'E': key = Keyboard::E; break;
case 'F': key = Keyboard::F; break;
case 'G': key = Keyboard::G; break;
case 'H': key = Keyboard::H; break;
case 'I': key = Keyboard::I; break;
case 'J': key = Keyboard::J; break;
case 'K': key = Keyboard::K; break;
case 'L': key = Keyboard::L; break;
case 'M': key = Keyboard::M; break;
case 'N': key = Keyboard::N; break;
case 'O': key = Keyboard::O; break;
case 'P': key = Keyboard::P; break;
case 'Q': key = Keyboard::Q; break;
case 'R': key = Keyboard::R; break;
case 'S': key = Keyboard::S; break;
case 'T': key = Keyboard::T; break;
case 'U': key = Keyboard::U; break;
case 'V': key = Keyboard::V; break;
case 'W': key = Keyboard::W; break;
case 'X': key = Keyboard::X; break;
case 'Y': key = Keyboard::Y; break;
case 'Z': key = Keyboard::Z; break;
case '0': key = Keyboard::Num0; break;
case '1': key = Keyboard::Num1; break;
case '2': key = Keyboard::Num2; break;
case '3': key = Keyboard::Num3; break;
case '4': key = Keyboard::Num4; break;
case '5': key = Keyboard::Num5; break;
case '6': key = Keyboard::Num6; break;
case '7': key = Keyboard::Num7; break;
case '8': key = Keyboard::Num8; break;
case '9': key = Keyboard::Num9; break;
case VK_ESCAPE: key = Keyboard::Escape; break;
case VK_LCONTROL: key = Keyboard::LControl; break;
case VK_LSHIFT: key = Keyboard::LShift; break;
case VK_LMENU: key = Keyboard::LAlt; break;
case VK_LWIN: key = Keyboard::LSystem; break;
case VK_RCONTROL: key = Keyboard::RControl; break;
case VK_RSHIFT: key = Keyboard::RShift; break;
case VK_RMENU: key = Keyboard::RAlt; break;
case VK_RWIN: key = Keyboard::RSystem; break;
case VK_APPS: key = Keyboard::Menu; break;
case VK_OEM_4: key = Keyboard::LBracket; break;
case VK_OEM_6: key = Keyboard::RBracket; break;
case VK_OEM_1: key = Keyboard::Semicolon; break;
case VK_OEM_COMMA: key = Keyboard::Comma; break;
case VK_OEM_PERIOD: key = Keyboard::Period; ;
case VK_OEM_7: key = Keyboard::Quote; break;
case VK_OEM_2: key = Keyboard::Slash; break;
case VK_OEM_5: key = Keyboard::Backslash; break;
case VK_OEM_3: key = Keyboard::Tilde; break;
case VK_OEM_PLUS: key = Keyboard::Equal; break;
case VK_OEM_MINUS: key = Keyboard::Hyphen; break;
case VK_SPACE: key = Keyboard::Space; break;
case VK_RETURN: key = Keyboard::Enter; break;
case VK_BACK: key = Keyboard::Backspace; break;
case VK_TAB: key = Keyboard::Tab; break;
case VK_PRIOR: key = Keyboard::PageUp; break;
case VK_NEXT: key = Keyboard::PageDown; break;
case VK_END: key = Keyboard::End; break;
case VK_HOME: key = Keyboard::Home; break;
case VK_INSERT: key = Keyboard::Insert; break;
case VK_DELETE: key = Keyboard::Delete; break;
case VK_ADD: key = Keyboard::Add; break;
case VK_SUBTRACT: key = Keyboard::Subtract; break;
case VK_MULTIPLY: key = Keyboard::Multiply; break;
case VK_DIVIDE: key = Keyboard::Divide; break;
case VK_LEFT: key = Keyboard::Left; break;
case VK_RIGHT: key = Keyboard::Right; break;
case VK_UP: key = Keyboard::Up; break;
case VK_DOWN: key = Keyboard::Down; break;
case VK_NUMPAD0: key = Keyboard::Numpad0; break;
case VK_NUMPAD1: key = Keyboard::Numpad1; break;
case VK_NUMPAD2: key = Keyboard::Numpad2; break;
case VK_NUMPAD3: key = Keyboard::Numpad3; break;
case VK_NUMPAD4: key = Keyboard::Numpad4; break;
case VK_NUMPAD5: key = Keyboard::Numpad5; break;
case VK_NUMPAD6: key = Keyboard::Numpad6; break;
case VK_NUMPAD7: key = Keyboard::Numpad7; break;
case VK_NUMPAD8: key = Keyboard::Numpad8; break;
case VK_NUMPAD9: key = Keyboard::Numpad9; break;
case VK_F1: key = Keyboard::F1; break;
case VK_F2: key = Keyboard::F2; break;
case VK_F3: key = Keyboard::F3; break;
case VK_F4: key = Keyboard::F4; break;
case VK_F5: key = Keyboard::F5; break;
case VK_F6: key = Keyboard::F6; break;
case VK_F7: key = Keyboard::F7; break;
case VK_F8: key = Keyboard::F8; break;
case VK_F9: key = Keyboard::F9; break;
case VK_F10: key = Keyboard::F10; break;
case VK_F11: key = Keyboard::F11; break;
case VK_F12: key = Keyboard::F12; break;
case VK_F13: key = Keyboard::F13; break;
case VK_F14: key = Keyboard::F14; break;
case VK_F15: key = Keyboard::F15; break;
case VK_PAUSE: key = Keyboard::Pause; break;
}
return key;
}
////////////////////////////////////////////////////////////
int sfKeyToWin(Keyboard::Key key)
{ {
int vkey = 0; int vkey = 0;
switch (key) switch (key)
@ -151,10 +266,217 @@ bool InputImpl::isKeyPressed(Keyboard::Key key)
case Keyboard::F15: vkey = VK_F15; break; case Keyboard::F15: vkey = VK_F15; break;
case Keyboard::Pause: vkey = VK_PAUSE; break; case Keyboard::Pause: vkey = VK_PAUSE; break;
} }
return vkey;
}
////////////////////////////////////////////////////////////
WORD sfScanToWin(Keyboard::Scancode code)
{
// Convert an SFML scancode to a windows scancode
// Reference: https://msdn.microsoft.com/en-us/library/aa299374(v=vs.60).aspx
switch (code)
{
case Keyboard::ScanA: return 30;
case Keyboard::ScanB: return 48;
case Keyboard::ScanC: return 46;
case Keyboard::ScanD: return 32;
case Keyboard::ScanE: return 18;
case Keyboard::ScanF: return 33;
case Keyboard::ScanG: return 34;
case Keyboard::ScanH: return 35;
case Keyboard::ScanI: return 23;
case Keyboard::ScanJ: return 36;
case Keyboard::ScanK: return 37;
case Keyboard::ScanL: return 38;
case Keyboard::ScanM: return 50;
case Keyboard::ScanN: return 49;
case Keyboard::ScanO: return 24;
case Keyboard::ScanP: return 25;
case Keyboard::ScanQ: return 16;
case Keyboard::ScanR: return 19;
case Keyboard::ScanS: return 31;
case Keyboard::ScanT: return 20;
case Keyboard::ScanU: return 22;
case Keyboard::ScanV: return 47;
case Keyboard::ScanW: return 17;
case Keyboard::ScanX: return 45;
case Keyboard::ScanY: return 21;
case Keyboard::ScanZ: return 44;
case Keyboard::ScanNum1: return 2;
case Keyboard::ScanNum2: return 3;
case Keyboard::ScanNum3: return 4;
case Keyboard::ScanNum4: return 5;
case Keyboard::ScanNum5: return 6;
case Keyboard::ScanNum6: return 7;
case Keyboard::ScanNum7: return 8;
case Keyboard::ScanNum8: return 9;
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::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 | 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 KF_EXTENDED | 28;
case Keyboard::ScanDecimal: return 83;
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 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 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?
}
}
////////////////////////////////////////////////////////////
InputImpl::InputImpl()
{
buildMappings();
}
////////////////////////////////////////////////////////////
void InputImpl::buildMappings()
{
// Reset the mappings
for (int i = 0; i < Keyboard::KeyCount; ++i)
m_keyToScancodeMapping[i] = Keyboard::ScanUnknown;
for (int i = 0; i < Keyboard::ScanCodeCount; ++i)
m_scancodeToKeyMapping[i] = Keyboard::Unknown;
for (int i = 0; i < Keyboard::ScanCodeCount; ++i)
{
Keyboard::Scancode scan = static_cast<Keyboard::Scancode>(i);
WORD winScanCode = sfScanToWin(scan);
UINT vkey = MapVirtualKey(winScanCode, MAPVK_VSC_TO_VK_EX);
Keyboard::Key key = winKeyToSfKey(vkey);
m_keyToScancodeMapping[key] = scan;
m_scancodeToKeyMapping[scan] = key;
}
}
////////////////////////////////////////////////////////////
bool InputImpl::isKeyPressed(Keyboard::Key key)
{
int vkey = sfKeyToWin(key);
return (GetAsyncKeyState(vkey) & 0x8000) != 0; return (GetAsyncKeyState(vkey) & 0x8000) != 0;
} }
////////////////////////////////////////////////////////////
bool InputImpl::isKeyPressed(Keyboard::Scancode code)
{
WORD winScanCode = sfScanToWin(code);
UINT vkey = MapVirtualKey(winScanCode, MAPVK_VSC_TO_VK_EX);
return (GetAsyncKeyState(vkey) & 0x8000) != 0;
}
////////////////////////////////////////////////////////////
Keyboard::Key InputImpl::localize(Keyboard::Scancode code)
{
return m_scancodeToKeyMapping[code];
}
////////////////////////////////////////////////////////////
Keyboard::Scancode InputImpl::unlocalize(Keyboard::Key key)
{
return m_keyToScancodeMapping[key];
}
////////////////////////////////////////////////////////////
String InputImpl::getDescription(Keyboard::Scancode code)
{
WORD winCode = sfScanToWin(code);
const int bufSize(1024);
WCHAR name[bufSize];
int result = GetKeyNameText(winCode << 16, name, bufSize);
if (result > 0)
{
return name;
}
return "Unknown";
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void InputImpl::setVirtualKeyboardVisible(bool /*visible*/) void InputImpl::setVirtualKeyboardVisible(bool /*visible*/)

View File

@ -31,7 +31,6 @@
#include <SFML/Window/Keyboard.hpp> #include <SFML/Window/Keyboard.hpp>
#include <SFML/Window/Mouse.hpp> #include <SFML/Window/Mouse.hpp>
namespace sf namespace sf
{ {
namespace priv namespace priv
@ -43,6 +42,11 @@ namespace priv
class InputImpl class InputImpl
{ {
public: public:
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
////////////////////////////////////////////////////////////
InputImpl();
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \copydoc sf::Keyboard::isKeyPressed(Key) /// \copydoc sf::Keyboard::isKeyPressed(Key)
@ -69,7 +73,7 @@ public:
static Keyboard::Scancode unlocalize(Keyboard::Key key); static Keyboard::Scancode unlocalize(Keyboard::Key key);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \copydoc sf::Keyboard::localizedRepresentation /// \copydoc sf::Keyboard::getDescription
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
static String getDescription(Keyboard::Scancode code); static String getDescription(Keyboard::Scancode code);
@ -176,6 +180,20 @@ public:
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
static Vector2i getTouchPosition(unsigned int finger, const WindowBase& relativeTo); static Vector2i getTouchPosition(unsigned int finger, const WindowBase& relativeTo);
private:
////////////////////////////////////////////////////////////
/// Regenerate the mappings from/to Key and Scancode.
///
////////////////////////////////////////////////////////////
void buildMappings();
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
static Keyboard::Scancode m_keyToScancodeMapping[Keyboard::KeyCount]; ///< Mapping from Key to Scancode
static Keyboard::Key m_scancodeToKeyMapping[Keyboard::ScanCodeCount]; ///< Mapping from Scancode to Key
}; };
} // namespace priv } // namespace priv

View File

@ -565,6 +565,107 @@ void WindowImplWin32::grabCursor(bool grabbed)
} }
} }
////////////////////////////////////////////////////////////
Keyboard::Scancode WindowImplWin32::toScancode(LPARAM flags)
{
int code = ((flags & (0xFF << 16)) >> 16);
// Windows scan codes
// Reference: https://msdn.microsoft.com/en-us/library/aa299374(v=vs.60).aspx
switch (code)
{
case 1: return Keyboard::ScanEscape;
case 2: return Keyboard::ScanNum1;
case 3: return Keyboard::ScanNum2;
case 4: return Keyboard::ScanNum3;
case 5: return Keyboard::ScanNum4;
case 6: return Keyboard::ScanNum5;
case 7: return Keyboard::ScanNum6;
case 8: return Keyboard::ScanNum7;
case 9: return Keyboard::ScanNum8;
case 10: return Keyboard::ScanNum9;
case 11: return Keyboard::ScanNum0;
case 12: return Keyboard::ScanHyphen;
case 13: return Keyboard::ScanEquals;
case 14: return Keyboard::ScanBackspace;
case 15: return Keyboard::ScanTab;
case 16: return Keyboard::ScanQ;
case 17: return Keyboard::ScanW;
case 18: return Keyboard::ScanE;
case 19: return Keyboard::ScanR;
case 20: return Keyboard::ScanT;
case 21: return Keyboard::ScanY;
case 22: return Keyboard::ScanU;
case 23: return Keyboard::ScanI;
case 24: return Keyboard::ScanO;
case 25: return Keyboard::ScanP;
case 26: return Keyboard::ScanLBracket;
case 27: return Keyboard::ScanRBracket;
case 28: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::ScanEnter : Keyboard::ScanNumpadEnter;
case 29: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::ScanRControl : Keyboard::ScanLControl;
case 30: return Keyboard::ScanA;
case 31: return Keyboard::ScanS;
case 32: return Keyboard::ScanD;
case 33: return Keyboard::ScanF;
case 34: return Keyboard::ScanG;
case 35: return Keyboard::ScanH;
case 36: return Keyboard::ScanJ;
case 37: return Keyboard::ScanK;
case 38: return Keyboard::ScanL;
case 39: return Keyboard::ScanSemicolon;
case 40: return Keyboard::ScanQuote;
case 41: return Keyboard::ScanBackslash;
case 42: return Keyboard::ScanLShift;
case 43: return Keyboard::ScanDash;
case 44: return Keyboard::ScanZ;
case 45: return Keyboard::ScanX;
case 46: return Keyboard::ScanC;
case 47: return Keyboard::ScanV;
case 48: return Keyboard::ScanB;
case 49: return Keyboard::ScanN;
case 50: return Keyboard::ScanM;
case 51: return Keyboard::ScanComma;
case 52: return Keyboard::ScanPeriod;
case 53: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::ScanDivide : Keyboard::ScanSlash;
case 54: return Keyboard::ScanRShift;
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;
case 59: return Keyboard::ScanF1;
case 60: return Keyboard::ScanF2;
case 61: return Keyboard::ScanF3;
case 62: return Keyboard::ScanF4;
case 63: return Keyboard::ScanF5;
case 64: return Keyboard::ScanF6;
case 65: return Keyboard::ScanF7;
case 66: return Keyboard::ScanF8;
case 67: return Keyboard::ScanF9;
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 (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;
case 73: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::ScanPageUp : Keyboard::ScanNumpad9;
case 74: return Keyboard::ScanMinus;
case 75: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::ScanLeft : Keyboard::ScanNumpad4;
case 76: return Keyboard::ScanNumpad5;
case 77: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::ScanRight : Keyboard::ScanNumpad6;
case 78: return Keyboard::ScanPlus;
case 79: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::ScanEnd : Keyboard::ScanNumpad1;
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::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;
}
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam) void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)

View File

@ -269,6 +269,16 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
static LRESULT CALLBACK globalOnEvent(HWND handle, UINT message, WPARAM wParam, LPARAM lParam); static LRESULT CALLBACK globalOnEvent(HWND handle, UINT message, WPARAM wParam, LPARAM lParam);
////////////////////////////////////////////////////////////
/// \brief Convert a Win32 scancode to an sfml scancode
///
/// \param flags input flags
///
/// \return SFML scancode corresponding to the key
///
////////////////////////////////////////////////////////////
static Keyboard::Scancode toScancode(LPARAM flags);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////