mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 04:41:05 +08:00
Align and fix mappings and general logic
- Aligned mappings - ScanDash -> ScanHyphen - Numpad keys include Numpad - *Equals -> *Equal - Key 29/42 are Backslash - Key 45 is Non-US Backslash - Add additional media & more scancodes - Rename ScanAgain to ScanRedo - Rename ScanMute to ScanVolumeMute - Add the missing F-key mappings for macOS - Fix mapping in Windows code - Correctly handle numpad keys on Windows for isKeyPressed - Refactorings - Use mapping for Linux from different key config - Refactor some mapping code - Fix map initialization - Layout independent keys also don't have unicode characters, so it makes more sense to translate them first and use unicode as fallback - Fix iteration limits on Windows - Consistently use 'Scancode' instead of 'ScanCode' everywhere - Use 'delocalize' instead of 'unlocalize' - Fix conversion warnings - Remove unused mapping function - Hide parameters for non-applicable iOS functions - Update documentation - Add Android InputImpl scancode function stubs
This commit is contained in:
parent
5bf4982239
commit
39b8d67262
@ -94,18 +94,18 @@ public:
|
||||
LControl, //!< The left Control key
|
||||
LShift, //!< The left Shift key
|
||||
LAlt, //!< The left Alt key
|
||||
LSystem, //!< The left OS specific key: window (Windows and Linux), apple (MacOS X), ...
|
||||
LSystem, //!< The left OS specific key: window (Windows and Linux), apple (macOS), ...
|
||||
RControl, //!< The right Control key
|
||||
RShift, //!< The right Shift key
|
||||
RAlt, //!< The right Alt key
|
||||
RSystem, //!< The right OS specific key: window (Windows and Linux), apple (MacOS X), ...
|
||||
RSystem, //!< The right OS specific key: window (Windows and Linux), apple (macOS), ...
|
||||
Menu, //!< The Menu key
|
||||
LBracket, //!< The [ key
|
||||
RBracket, //!< The ] key
|
||||
Semicolon, //!< The ; key
|
||||
Comma, //!< The , key
|
||||
Period, //!< The . key
|
||||
Quote, //!< The ' key
|
||||
Apostrophe, //!< The ' key
|
||||
Slash, //!< The / key
|
||||
Backslash, //!< The \ key
|
||||
Tilde, //!< The ~ key
|
||||
@ -160,11 +160,12 @@ public:
|
||||
|
||||
// Deprecated values:
|
||||
|
||||
Dash = Hyphen, //!< \deprecated Use Hyphen instead
|
||||
BackSpace = Backspace, //!< \deprecated Use Backspace instead
|
||||
BackSlash = Backslash, //!< \deprecated Use Backslash instead
|
||||
SemiColon = Semicolon, //!< \deprecated Use Semicolon instead
|
||||
Return = Enter //!< \deprecated Use Enter instead
|
||||
Dash = Hyphen, //!< \deprecated Use Hyphen instead
|
||||
BackSpace = Backspace, //!< \deprecated Use Backspace instead
|
||||
BackSlash = Backslash, //!< \deprecated Use Backslash instead
|
||||
SemiColon = Semicolon, //!< \deprecated Use Semicolon instead
|
||||
Return = Enter, //!< \deprecated Use Enter instead
|
||||
Quote = Apostrophe //!< \deprecated Use Apostrophe instead
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -174,147 +175,164 @@ public:
|
||||
/// 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 `Scan` 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 Enter/Return key
|
||||
ScanEscape, ///< Keyboard Escape key
|
||||
ScanBackspace, ///< Keyboard Backspace key
|
||||
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
|
||||
ScanDash, ///< Keyboard Non-US # and ~
|
||||
// TODO hyphen vs minus vs dash
|
||||
ScanSemicolon, ///< Keyboard ; and : key
|
||||
ScanQuote, ///< Keyboard ' and " key
|
||||
ScanGraveAccent, ///< Keyboard ` and ~ key
|
||||
ScanComma, ///< Keyboard , and < key
|
||||
ScanPeriod, ///< Keyboard . and > key
|
||||
ScanSlash, ///< 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
|
||||
ScanNumpadEquals, ///< keypad = key, probably Mac only
|
||||
ScanNumpadEnter, ///< 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
|
||||
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 Enter/Return key
|
||||
ScanEscape, //!< Keyboard Escape key
|
||||
ScanBackspace, //!< Keyboard Backspace key
|
||||
ScanTab, //!< Keyboard Tab key
|
||||
ScanSpace, //!< Keyboard Space key
|
||||
ScanHyphen, //!< Keyboard - and _ key
|
||||
ScanEqual, //!< Keyboard = and +
|
||||
ScanLBracket, //!< Keyboard [ and { key
|
||||
ScanRBracket, //!< Keyboard ] and } key
|
||||
// For US keyboards mapped to key 29 (Microsoft Keyboard Scan Code Specification)
|
||||
// For Non-US keyboards mapped to key 42 (Microsoft Keyboard Scan Code Specification)
|
||||
// Typical language mappings: Belg:£µ` FrCa:<>} Dan:*' Dutch:`´ Fren:µ* Ger:'# Ital:§ù LatAm:[}` Nor:*@ Span:ç} Swed:*' Swiss:$£} UK:~# Brazil:}]
|
||||
ScanBackslash, //!< Keyboard \ and | key OR various keys for Non-US keyboards
|
||||
ScanSemicolon, //!< Keyboard ; and : key
|
||||
ScanApostrophe, //!< Keyboard ' and " key
|
||||
ScanGrave, //!< Keyboard ` and ~ key
|
||||
ScanComma, //!< Keyboard , and < key
|
||||
ScanPeriod, //!< Keyboard . and > key
|
||||
ScanSlash, //!< 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
|
||||
ScanF16, //!< Keyboard F16 key
|
||||
ScanF17, //!< Keyboard F17 key
|
||||
ScanF18, //!< Keyboard F18 key
|
||||
ScanF19, //!< Keyboard F19 key
|
||||
ScanF20, //!< Keyboard F20 key
|
||||
ScanF21, //!< Keyboard F21 key
|
||||
ScanF22, //!< Keyboard F22 key
|
||||
ScanF23, //!< Keyboard F23 key
|
||||
ScanF24, //!< Keyboard F24 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
|
||||
ScanNumpadDivide, //!< Keypad / key
|
||||
ScanNumpadMultiply, //!< Keypad * key
|
||||
ScanNumpadMinus, //!< Keypad - key
|
||||
ScanNumpadPlus, //!< Keypad + key
|
||||
ScanNumpadEqual, //!< keypad = key
|
||||
ScanNumpadEnter, //!< Keypad Enter/Return key
|
||||
ScanNumpadDecimal, //!< 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
|
||||
// For US keyboards doesn't exist
|
||||
// For Non-US keyboards mapped to key 45 (Microsoft Keyboard Scan Code Specification)
|
||||
// Typical language mappings: Belg:<\> FrCa:«°» Dan:<\> Dutch:]|[ Fren:<> Ger:<|> Ital:<> LatAm:<> Nor:<> Span:<> Swed:<|> Swiss:<\> UK:\| Brazil: \|.
|
||||
ScanNonUsBackslash, //!< Keyboard Non-US \ and | key
|
||||
ScanApplication, //!< Keyboard Application key
|
||||
ScanExecute, //!< Keyboard Execute key
|
||||
ScanModeChange, //!< Keyboard Mode Change key
|
||||
ScanHelp, //!< Keyboard Help key
|
||||
ScanMenu, //!< Keyboard Menu key
|
||||
ScanSelect, //!< Keyboard Select key
|
||||
ScanRedo, //!< Keyboard Redo key
|
||||
ScanUndo, //!< Keyboard Undo key
|
||||
ScanCut, //!< Keyboard Cut key
|
||||
ScanCopy, //!< Keyboard Copy key
|
||||
ScanPaste, //!< Keyboard Paste key
|
||||
ScanVolumeMute, //!< Keyboard Volume Mute key
|
||||
ScanVolumeUp, //!< Keyboard Volume Up key
|
||||
ScanVolumeDown, //!< Keyboard Volume Down key
|
||||
ScanMediaPlayPause, //!< Keyboard Media Play Pause key
|
||||
ScanMediaStop, //!< Keyboard Media Stop key
|
||||
ScanMediaNextTrack, //!< Keyboard Media Next Track key
|
||||
ScanMediaPreviousTrack, //!< Keyboard Media Previous Track 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
|
||||
ScanBack, //!< Keyboard Back key
|
||||
ScanForward, //!< Keyboard Forward key
|
||||
ScanRefresh, //!< Keyboard Refresh key
|
||||
ScanStop, //!< Keyboard Stop key
|
||||
ScanSearch, //!< Keyboard Search key
|
||||
ScanFavorites, //!< Keyboard Favorites key
|
||||
ScanHomePage, //!< Keyboard Home Page key
|
||||
ScanLaunchApplication1, //!< Keyboard Launch Application 1 key
|
||||
ScanLaunchApplication2, //!< Keyboard Launch Application 2 key
|
||||
ScanLaunchMail, //!< Keyboard Launch Mail key
|
||||
ScanLaunchMediaSelect, //!< Keyboard Launch Media Select key
|
||||
|
||||
ScanCodeCount ///< Keep last -- the total number of scancodes
|
||||
ScancodeCount //!< Keep last -- the total number of scancodes
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -347,7 +365,7 @@ public:
|
||||
/// sf::Keyboard::Unknown when the scancode cannot be mapped
|
||||
/// to a Key.
|
||||
///
|
||||
/// \see unlocalize
|
||||
/// \see delocalize
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Key localize(Scancode code);
|
||||
@ -355,25 +373,25 @@ public:
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Identify the physical key corresponding to a logical one
|
||||
///
|
||||
/// \param key Key to "unlocalize"
|
||||
/// \param key Key to "delocalize"
|
||||
///
|
||||
/// \return The scancode corresponding to the key under the current
|
||||
/// keyboard layout used by the operating system, or
|
||||
/// sf::Keyboard::ScanUnknown when the key cannot be mapped
|
||||
/// to a Keyboard::Scancode.
|
||||
/// to a sf::Keyboard::Scancode.
|
||||
///
|
||||
/// \see localize
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Scancode unlocalize(Key key);
|
||||
static Scancode delocalize(Key key);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Provide a string representation for a given scancode
|
||||
///
|
||||
/// From a high level point of view, this conversion corresponds
|
||||
/// somewhat to the string available through sf::Event::TextEvent
|
||||
/// when the given physical key is pressed by the user, when no
|
||||
/// modifiers are involved.
|
||||
/// The returned string is a short, non-technical description of
|
||||
/// the key represented with the given scancode. Most effectively
|
||||
/// used in user interfaces, as the description for the key takes
|
||||
/// the users keyboard layout into consideration.
|
||||
///
|
||||
/// \warning The result is OS-dependent: for example, sf::Keyboard::ScanLSystem
|
||||
/// is "Left Meta" on Linux, "Left Windows" on Windows and
|
||||
@ -442,6 +460,10 @@ public:
|
||||
/// {
|
||||
/// // quit...
|
||||
/// }
|
||||
/// else if (sf::Keyboard::isKeyPressed(sf::Keyboard::ScanGrave))
|
||||
/// {
|
||||
/// // open in-game command line (if it's not already open)
|
||||
/// }
|
||||
/// \endcode
|
||||
///
|
||||
/// \see sf::Joystick, sf::Mouse, sf::Touch
|
||||
|
@ -43,6 +43,30 @@ bool InputImpl::isKeyPressed(Keyboard::Key /* key */)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InputImpl::isKeyPressed(Keyboard::Scancode /* codes */)
|
||||
{
|
||||
// Not applicable
|
||||
return false;
|
||||
}
|
||||
|
||||
Keyboard::Key InputImpl::localize(Keyboard::Scancode /* code */)
|
||||
{
|
||||
// Not applicable
|
||||
return Keyboard::Unknown;
|
||||
}
|
||||
|
||||
Keyboard::Scancode InputImpl::delocalize(Keyboard::Key /* key */)
|
||||
{
|
||||
// Not applicable
|
||||
return Keyboard::ScanUnknown;
|
||||
}
|
||||
|
||||
String InputImpl::getDescription(Keyboard::Scancode /* code */)
|
||||
{
|
||||
// Not applicable
|
||||
return "";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void InputImpl::setVirtualKeyboardVisible(bool visible)
|
||||
{
|
||||
|
@ -63,13 +63,13 @@ public:
|
||||
static Keyboard::Key localize(Keyboard::Scancode code);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \copydoc sf::Keyboard::unlocalize
|
||||
/// \copydoc sf::Keyboard::delocalize
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Keyboard::Scancode unlocalize(Keyboard::Key key);
|
||||
static Keyboard::Scancode delocalize(Keyboard::Key key);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \copydoc sf::Keyboard::localizedRepresentation
|
||||
/// \copydoc sf::Keyboard::getDescription
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static String getDescription(Keyboard::Scancode code);
|
||||
|
@ -51,9 +51,9 @@ Keyboard::Key Keyboard::localize(Scancode code)
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Keyboard::Scancode Keyboard::unlocalize(Key key)
|
||||
Keyboard::Scancode Keyboard::delocalize(Key key)
|
||||
{
|
||||
return priv::InputImpl::unlocalize(key);
|
||||
return priv::InputImpl::delocalize(key);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -141,17 +141,25 @@ public:
|
||||
Keyboard::Key localize(Keyboard::Scancode code);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \copydoc sf::Keyboard::unlocalize
|
||||
/// \copydoc sf::Keyboard::delocalize
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Keyboard::Scancode unlocalize(Keyboard::Key key);
|
||||
Keyboard::Scancode delocalize(Keyboard::Key key);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \copydoc sf::Keyboard::localizedRepresentation
|
||||
/// \copydoc sf::Keyboard::getDescription
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
String localizedRepresentation(Keyboard::Scancode code);
|
||||
String getDescription(Keyboard::Scancode code);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Regenerate the mappings from/to Key and Scancode.
|
||||
///
|
||||
/// This function is public to allow regular update calls
|
||||
/// from the manager in case there's a keyboard layout change.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void buildMappings();
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -205,17 +213,6 @@ private:
|
||||
////////////////////////////////////////////////////////////
|
||||
void loadKey(IOHIDElementRef key);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Regenerate the mappings from/to Key and Scancode.
|
||||
///
|
||||
/// It is public to allow regular callback to forward the
|
||||
/// information to the manager.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
public:
|
||||
void buildMappings();
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Release all resources
|
||||
///
|
||||
@ -233,7 +230,7 @@ private:
|
||||
///
|
||||
/// \param page HID page like kHIDPage_GenericDesktop
|
||||
/// \param usage HID usage page like kHIDUsage_GD_Keyboard or kHIDUsage_GD_Mouse
|
||||
/// \return a retained, non-emtpy CFSetRef of IOHIDDeviceRef or NULL
|
||||
/// \return a retained, non-empty CFSetRef of IOHIDDeviceRef or NULL
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CFSetRef copyDevices(UInt32 page, UInt32 usage);
|
||||
@ -254,8 +251,8 @@ private:
|
||||
/// \brief Convert a HID key usage to its corresponding scancode
|
||||
///
|
||||
/// \param usage Any kHIDUsage_Keyboard* usage
|
||||
/// \return the scancode associate with the given HID key usage
|
||||
/// or sUnknown if it is associate with no scancode.
|
||||
/// \return the scancode associated with the given HID key usage
|
||||
/// or ScanUnknown if it is associated with no scancode.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Keyboard::Scancode usageToScancode(UInt32 usage);
|
||||
@ -267,7 +264,7 @@ private:
|
||||
static UInt8 scanToVirtualCode(Keyboard::Scancode code);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Fallback convertion for key that aren't expected to be impacted
|
||||
/// Fallback convertion for keys which aren't expected to be impacted
|
||||
/// by the layout. Can return Unknown.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -279,9 +276,9 @@ private:
|
||||
// Member data
|
||||
////////////////////////////////////////////////////////////
|
||||
IOHIDManagerRef m_manager; ///< Underlying HID Manager
|
||||
IOHIDElements m_keys[Keyboard::ScanCodeCount]; ///< All the keys on any connected keyboard
|
||||
IOHIDElements m_keys[Keyboard::ScancodeCount]; ///< All the keys on any connected keyboard
|
||||
Keyboard::Scancode m_keyToScancodeMapping[Keyboard::KeyCount]; ///< Mapping from Key to Scancode
|
||||
Keyboard::Key m_scancodeToKeyMapping[Keyboard::ScanCodeCount]; ///< Mapping from Scancode to Key
|
||||
Keyboard::Key m_scancodeToKeyMapping[Keyboard::ScancodeCount]; ///< Mapping from Scancode to Key
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// m_keys' index corresponds to sf::Keyboard::Scancode enum.
|
||||
|
@ -96,7 +96,7 @@ CFDictionaryRef HIDInputManager::copyDevicesMask(UInt32 page, UInt32 usage)
|
||||
////////////////////////////////////////////////////////////
|
||||
bool HIDInputManager::isKeyPressed(Keyboard::Key key)
|
||||
{
|
||||
return isKeyPressed(unlocalize(key));
|
||||
return isKeyPressed(delocalize(key));
|
||||
}
|
||||
|
||||
|
||||
@ -116,7 +116,7 @@ Keyboard::Key HIDInputManager::localize(Keyboard::Scancode code)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Keyboard::Scancode HIDInputManager::unlocalize(Keyboard::Key key)
|
||||
Keyboard::Scancode HIDInputManager::delocalize(Keyboard::Key key)
|
||||
{
|
||||
// TODO ensure mapping is still valid
|
||||
return m_keyToScancodeMapping[key];
|
||||
@ -124,13 +124,9 @@ Keyboard::Scancode HIDInputManager::unlocalize(Keyboard::Key key)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String HIDInputManager::localizedRepresentation(Keyboard::Scancode code)
|
||||
String HIDInputManager::getDescription(Keyboard::Scancode code)
|
||||
{
|
||||
UniChar unicode = toUnicode(localize(code));
|
||||
if (unicode != 0x00)
|
||||
return sf::String(static_cast<Uint32>(unicode));
|
||||
|
||||
// Fallback to our best guess for the keys that are known to be independent of the layout.
|
||||
// Phase 1: Get names for layout independent keys
|
||||
switch (code)
|
||||
{
|
||||
case sf::Keyboard::ScanEnter: return "Enter";
|
||||
@ -154,6 +150,15 @@ String HIDInputManager::localizedRepresentation(Keyboard::Scancode code)
|
||||
case sf::Keyboard::ScanF13: return "F13";
|
||||
case sf::Keyboard::ScanF14: return "F14";
|
||||
case sf::Keyboard::ScanF15: return "F15";
|
||||
case sf::Keyboard::ScanF16: return "F16";
|
||||
case sf::Keyboard::ScanF17: return "F17";
|
||||
case sf::Keyboard::ScanF18: return "F18";
|
||||
case sf::Keyboard::ScanF19: return "F19";
|
||||
case sf::Keyboard::ScanF20: return "F20";
|
||||
case sf::Keyboard::ScanF21: return "F21";
|
||||
case sf::Keyboard::ScanF22: return "F22";
|
||||
case sf::Keyboard::ScanF23: return "F23";
|
||||
case sf::Keyboard::ScanF24: return "F24";
|
||||
|
||||
case sf::Keyboard::ScanCapsLock: return "CapsLock";
|
||||
case sf::Keyboard::ScanPrintScreen: return "PrintScreen";
|
||||
@ -172,14 +177,14 @@ String HIDInputManager::localizedRepresentation(Keyboard::Scancode code)
|
||||
case sf::Keyboard::ScanDown: return "Down Arrow";
|
||||
case sf::Keyboard::ScanUp: return "Up Arrow";
|
||||
|
||||
case sf::Keyboard::ScanNumLock: return "NumLock";
|
||||
case sf::Keyboard::ScanDivide: return "Divide (Numpad)";
|
||||
case sf::Keyboard::ScanMultiply: return "Multiply (Numpad)";
|
||||
case sf::Keyboard::ScanMinus: return "Minux (Numpad)";
|
||||
case sf::Keyboard::ScanPlus: return "Plus (Numpad)";
|
||||
case sf::Keyboard::ScanNumpadEquals: return "Equals (Numpad)";
|
||||
case sf::Keyboard::ScanNumpadEnter: return "Enter (Numpad)";
|
||||
case sf::Keyboard::ScanDecimal: return "Decimal (Numpad)";
|
||||
case sf::Keyboard::ScanNumLock: return "NumLock";
|
||||
case sf::Keyboard::ScanNumpadDivide: return "Divide (Numpad)";
|
||||
case sf::Keyboard::ScanNumpadMultiply: return "Multiply (Numpad)";
|
||||
case sf::Keyboard::ScanNumpadMinus: return "Minus (Numpad)";
|
||||
case sf::Keyboard::ScanNumpadPlus: return "Plus (Numpad)";
|
||||
case sf::Keyboard::ScanNumpadEqual: return "Equal (Numpad)";
|
||||
case sf::Keyboard::ScanNumpadEnter: return "Enter (Numpad)";
|
||||
case sf::Keyboard::ScanNumpadDecimal: return "Decimal (Numpad)";
|
||||
|
||||
case sf::Keyboard::ScanNumpad0: return "0 (Numpad)";
|
||||
case sf::Keyboard::ScanNumpad1: return "1 (Numpad)";
|
||||
@ -198,26 +203,35 @@ String HIDInputManager::localizedRepresentation(Keyboard::Scancode code)
|
||||
case sf::Keyboard::ScanMenu: return "Menu";
|
||||
case sf::Keyboard::ScanSelect: return "Select";
|
||||
case sf::Keyboard::ScanStop: return "Stop";
|
||||
case sf::Keyboard::ScanAgain: return "Again";
|
||||
case sf::Keyboard::ScanRedo: return "Redo";
|
||||
case sf::Keyboard::ScanUndo: return "Undo";
|
||||
case sf::Keyboard::ScanCut: return "Cut";
|
||||
case sf::Keyboard::ScanCopy: return "Copy";
|
||||
case sf::Keyboard::ScanPaste: return "Paste";
|
||||
case sf::Keyboard::ScanFind: return "Find";
|
||||
case sf::Keyboard::ScanMute: return "Mute";
|
||||
case sf::Keyboard::ScanSearch: return "Search";
|
||||
case sf::Keyboard::ScanVolumeMute: return "Volume Mute";
|
||||
case sf::Keyboard::ScanVolumeUp: return "Volume Up";
|
||||
case sf::Keyboard::ScanVolumeDown: return "Volume Down";
|
||||
|
||||
case sf::Keyboard::ScanLControl: return "Control (Left)";
|
||||
case sf::Keyboard::ScanLShift: return "Shift (Left)";
|
||||
case sf::Keyboard::ScanLAlt: return "Alt (Left)";
|
||||
case sf::Keyboard::ScanLSystem: return "Command (Left)";
|
||||
case sf::Keyboard::ScanRControl: return "Control (Right)";
|
||||
case sf::Keyboard::ScanRShift: return "Shift (Right)";
|
||||
case sf::Keyboard::ScanRAlt: return "Alt (Right)";
|
||||
case sf::Keyboard::ScanRSystem: return "Command (Right)";
|
||||
case sf::Keyboard::ScanLControl: return "Left Control";
|
||||
case sf::Keyboard::ScanLShift: return "Left Shift";
|
||||
case sf::Keyboard::ScanLAlt: return "Left Alt";
|
||||
case sf::Keyboard::ScanLSystem: return "Left Command";
|
||||
case sf::Keyboard::ScanRControl: return "Right Control";
|
||||
case sf::Keyboard::ScanRShift: return "Right Shift";
|
||||
case sf::Keyboard::ScanRAlt: return "Right Alt";
|
||||
case sf::Keyboard::ScanRSystem: return "Right Command";
|
||||
|
||||
default: return "Unknown Scancode"; // no guess good enough possible.
|
||||
default:
|
||||
{
|
||||
// Phase 2: Try to convert the key to unicode
|
||||
UniChar unicode = toUnicode(localize(code));
|
||||
if (unicode != 0x00)
|
||||
return sf::String(static_cast<Uint32>(unicode));
|
||||
}
|
||||
|
||||
// Phase 3: Return final fallback
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
@ -329,9 +343,9 @@ void HIDInputManager::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;
|
||||
m_keyToScancodeMapping[i] = Keyboard::ScanUnknown;
|
||||
for (int i = 0; i < Keyboard::ScancodeCount; ++i)
|
||||
m_scancodeToKeyMapping[i] = Keyboard::Unknown;
|
||||
|
||||
// Get the current keyboard layout
|
||||
TISInputSourceRef tis = TISCopyCurrentKeyboardLayoutInputSource();
|
||||
@ -344,11 +358,11 @@ void HIDInputManager::buildMappings()
|
||||
return;
|
||||
}
|
||||
|
||||
UCKeyboardLayout* layout = reinterpret_cast<UCKeyboardLayout*>(CFDataGetBytePtr(layoutData));
|
||||
UCKeyboardLayout* layout = reinterpret_cast<UCKeyboardLayout*>(const_cast<UInt8*>(CFDataGetBytePtr(layoutData)));
|
||||
|
||||
// For each scancode having a IOHIDElement, we translate the corresponding
|
||||
// virtual code to a localized Key.
|
||||
for (int i = 0; i < Keyboard::ScanCodeCount; ++i)
|
||||
for (int i = 0; i < Keyboard::ScancodeCount; ++i)
|
||||
{
|
||||
Keyboard::Scancode scan = static_cast<Keyboard::Scancode>(i);
|
||||
UInt8 virtualCode = scanToVirtualCode(scan);
|
||||
@ -364,8 +378,8 @@ void HIDInputManager::buildMappings()
|
||||
|
||||
// Use current layout for translation
|
||||
OSStatus error = UCKeyTranslate(
|
||||
layout, virtualCode, kUCKeyActionDown, modifiers, LMGetKbdType(),
|
||||
kUCKeyTranslateNoDeadKeysBit, &deadKeyState, MAX_LENGTH, &length, string
|
||||
layout, virtualCode, kUCKeyActionDown, modifiers, LMGetKbdType(),
|
||||
kUCKeyTranslateNoDeadKeysBit, &deadKeyState, MAX_LENGTH, &length, string
|
||||
);
|
||||
|
||||
if (error != noErr)
|
||||
@ -375,9 +389,11 @@ void HIDInputManager::buildMappings()
|
||||
}
|
||||
|
||||
Keyboard::Key code = (length > 0) ? localizedKey(string[0]) : Keyboard::Unknown;
|
||||
if (code == Keyboard::Unknown) code = localizedKeyFallback(scan);
|
||||
|
||||
if (code == Keyboard::Unknown) continue;
|
||||
if (code == Keyboard::Unknown)
|
||||
code = localizedKeyFallback(scan);
|
||||
if (code == Keyboard::Unknown)
|
||||
continue;
|
||||
|
||||
// Register the bi-mapping
|
||||
m_keyToScancodeMapping[code] = scan;
|
||||
@ -513,14 +529,14 @@ sf::Keyboard::Scancode HIDInputManager::usageToScancode(UInt32 usage)
|
||||
case kHIDUsage_KeyboardTab: return sf::Keyboard::ScanTab;
|
||||
case kHIDUsage_KeyboardSpacebar: return sf::Keyboard::ScanSpace;
|
||||
case kHIDUsage_KeyboardHyphen: return sf::Keyboard::ScanHyphen;
|
||||
case kHIDUsage_KeyboardEqualSign: return sf::Keyboard::ScanEquals;
|
||||
case kHIDUsage_KeyboardEqualSign: return sf::Keyboard::ScanEqual;
|
||||
case kHIDUsage_KeyboardOpenBracket: return sf::Keyboard::ScanLBracket;
|
||||
case kHIDUsage_KeyboardCloseBracket: return sf::Keyboard::ScanRBracket;
|
||||
case kHIDUsage_KeyboardBackslash: return sf::Keyboard::ScanBackslash;
|
||||
case kHIDUsage_KeyboardNonUSPound: return sf::Keyboard::ScanDash;
|
||||
case kHIDUsage_KeyboardNonUSPound: return sf::Keyboard::ScanBackslash;
|
||||
case kHIDUsage_KeyboardSemicolon: return sf::Keyboard::ScanSemicolon;
|
||||
case kHIDUsage_KeyboardQuote: return sf::Keyboard::ScanQuote;
|
||||
case kHIDUsage_KeyboardGraveAccentAndTilde: return sf::Keyboard::ScanGraveAccent;
|
||||
case kHIDUsage_KeyboardQuote: return sf::Keyboard::ScanApostrophe;
|
||||
case kHIDUsage_KeyboardGraveAccentAndTilde: return sf::Keyboard::ScanGrave;
|
||||
case kHIDUsage_KeyboardComma: return sf::Keyboard::ScanComma;
|
||||
case kHIDUsage_KeyboardPeriod: return sf::Keyboard::ScanPeriod;
|
||||
case kHIDUsage_KeyboardSlash: return sf::Keyboard::ScanSlash;
|
||||
@ -554,12 +570,14 @@ sf::Keyboard::Scancode HIDInputManager::usageToScancode(UInt32 usage)
|
||||
case kHIDUsage_KeyboardDownArrow: return sf::Keyboard::ScanDown;
|
||||
case kHIDUsage_KeyboardUpArrow: return sf::Keyboard::ScanUp;
|
||||
|
||||
case kHIDUsage_KeypadNumLock: return sf::Keyboard::ScanNumLock;
|
||||
case kHIDUsage_KeypadSlash: return sf::Keyboard::ScanDivide;
|
||||
case kHIDUsage_KeypadAsterisk: return sf::Keyboard::ScanMultiply;
|
||||
case kHIDUsage_KeypadHyphen: return sf::Keyboard::ScanMinus;
|
||||
case kHIDUsage_KeypadPlus: return sf::Keyboard::ScanPlus;
|
||||
case kHIDUsage_KeypadEnter: return sf::Keyboard::ScanEnter;
|
||||
case kHIDUsage_KeypadNumLock: return sf::Keyboard::ScanNumLock;
|
||||
case kHIDUsage_KeypadSlash: return sf::Keyboard::ScanNumpadDivide;
|
||||
case kHIDUsage_KeypadAsterisk: return sf::Keyboard::ScanNumpadMultiply;
|
||||
case kHIDUsage_KeypadHyphen: return sf::Keyboard::ScanNumpadMinus;
|
||||
case kHIDUsage_KeypadPlus: return sf::Keyboard::ScanNumpadPlus;
|
||||
case kHIDUsage_KeypadEqualSign: return sf::Keyboard::ScanNumpadEqual;
|
||||
case kHIDUsage_KeypadEnter: return sf::Keyboard::ScanNumpadEnter;
|
||||
case kHIDUsage_KeypadPeriod: return sf::Keyboard::ScanNumpadDecimal;
|
||||
|
||||
case kHIDUsage_Keypad1: return sf::Keyboard::ScanNumpad1;
|
||||
case kHIDUsage_Keypad2: return sf::Keyboard::ScanNumpad2;
|
||||
@ -572,38 +590,36 @@ sf::Keyboard::Scancode HIDInputManager::usageToScancode(UInt32 usage)
|
||||
case kHIDUsage_Keypad9: return sf::Keyboard::ScanNumpad9;
|
||||
case kHIDUsage_Keypad0: return sf::Keyboard::ScanNumpad0;
|
||||
|
||||
case kHIDUsage_KeypadPeriod: return sf::Keyboard::ScanDecimal;
|
||||
case kHIDUsage_KeyboardNonUSBackslash: return sf::Keyboard::ScanReverseSolidus;
|
||||
case kHIDUsage_KeyboardNonUSBackslash: return sf::Keyboard::ScanNonUsBackslash;
|
||||
case kHIDUsage_KeyboardApplication: return sf::Keyboard::ScanApplication;
|
||||
case kHIDUsage_KeyboardPower: return sf::Keyboard::ScanUnknown;
|
||||
case kHIDUsage_KeypadEqualSign: return sf::Keyboard::ScanNumpadEquals;
|
||||
|
||||
case kHIDUsage_KeyboardF13: return sf::Keyboard::ScanF13;
|
||||
case kHIDUsage_KeyboardF14: return sf::Keyboard::ScanF14;
|
||||
case kHIDUsage_KeyboardF15: return sf::Keyboard::ScanF15;
|
||||
case kHIDUsage_KeyboardF16: return sf::Keyboard::ScanUnknown;
|
||||
case kHIDUsage_KeyboardF17: return sf::Keyboard::ScanUnknown;
|
||||
case kHIDUsage_KeyboardF18: return sf::Keyboard::ScanUnknown;
|
||||
case kHIDUsage_KeyboardF19: return sf::Keyboard::ScanUnknown;
|
||||
case kHIDUsage_KeyboardF20: return sf::Keyboard::ScanUnknown;
|
||||
case kHIDUsage_KeyboardF21: return sf::Keyboard::ScanUnknown;
|
||||
case kHIDUsage_KeyboardF22: return sf::Keyboard::ScanUnknown;
|
||||
case kHIDUsage_KeyboardF23: return sf::Keyboard::ScanUnknown;
|
||||
case kHIDUsage_KeyboardF24: return sf::Keyboard::ScanUnknown;
|
||||
case kHIDUsage_KeyboardF16: return sf::Keyboard::ScanF16;
|
||||
case kHIDUsage_KeyboardF17: return sf::Keyboard::ScanF17;
|
||||
case kHIDUsage_KeyboardF18: return sf::Keyboard::ScanF18;
|
||||
case kHIDUsage_KeyboardF19: return sf::Keyboard::ScanF19;
|
||||
case kHIDUsage_KeyboardF20: return sf::Keyboard::ScanF20;
|
||||
case kHIDUsage_KeyboardF21: return sf::Keyboard::ScanF21;
|
||||
case kHIDUsage_KeyboardF22: return sf::Keyboard::ScanF22;
|
||||
case kHIDUsage_KeyboardF23: return sf::Keyboard::ScanF23;
|
||||
case kHIDUsage_KeyboardF24: return sf::Keyboard::ScanF24;
|
||||
|
||||
case kHIDUsage_KeyboardExecute: return sf::Keyboard::ScanExecute;
|
||||
case kHIDUsage_KeyboardHelp: return sf::Keyboard::ScanHelp;
|
||||
case kHIDUsage_KeyboardMenu: return sf::Keyboard::ScanMenu;
|
||||
case kHIDUsage_KeyboardSelect: return sf::Keyboard::ScanSelect;
|
||||
case kHIDUsage_KeyboardStop: return sf::Keyboard::ScanStop;
|
||||
case kHIDUsage_KeyboardAgain: return sf::Keyboard::ScanAgain;
|
||||
case kHIDUsage_KeyboardAgain: return sf::Keyboard::ScanRedo;
|
||||
case kHIDUsage_KeyboardUndo: return sf::Keyboard::ScanUndo;
|
||||
case kHIDUsage_KeyboardCut: return sf::Keyboard::ScanCut;
|
||||
case kHIDUsage_KeyboardCopy: return sf::Keyboard::ScanCopy;
|
||||
case kHIDUsage_KeyboardPaste: return sf::Keyboard::ScanPaste;
|
||||
case kHIDUsage_KeyboardFind: return sf::Keyboard::ScanFind;
|
||||
case kHIDUsage_KeyboardFind: return sf::Keyboard::ScanSearch;
|
||||
|
||||
case kHIDUsage_KeyboardMute: return sf::Keyboard::ScanMute;
|
||||
case kHIDUsage_KeyboardMute: return sf::Keyboard::ScanVolumeMute;
|
||||
case kHIDUsage_KeyboardVolumeUp: return sf::Keyboard::ScanVolumeUp;
|
||||
case kHIDUsage_KeyboardVolumeDown: return sf::Keyboard::ScanVolumeDown;
|
||||
|
||||
@ -1000,15 +1016,15 @@ Keyboard::Scancode HIDInputManager::nonLocalizedKey(UniChar virtualKeycode)
|
||||
case 0x33: return sf::Keyboard::ScanBackspace;
|
||||
case 0x30: return sf::Keyboard::ScanTab;
|
||||
case 0x31: return sf::Keyboard::ScanSpace;
|
||||
// case 0x27: return sf::Keyboard::ScanHyphen; // TODO 0x27 is for Quote
|
||||
case 0x18: return sf::Keyboard::ScanEquals;
|
||||
|
||||
case 0x18: return sf::Keyboard::ScanEqual;
|
||||
case 0x21: return sf::Keyboard::ScanLBracket;
|
||||
case 0x1e: return sf::Keyboard::ScanRBracket;
|
||||
case 0x2a: return sf::Keyboard::ScanBackslash;
|
||||
case 0x1b: return sf::Keyboard::ScanDash;
|
||||
case 0x1b: return sf::Keyboard::ScanHyphen;
|
||||
case 0x29: return sf::Keyboard::ScanSemicolon;
|
||||
case 0x27: return sf::Keyboard::ScanQuote;
|
||||
case 0x32: return sf::Keyboard::ScanGraveAccent;
|
||||
case 0x27: return sf::Keyboard::ScanApostrophe;
|
||||
case 0x32: return sf::Keyboard::ScanGrave;
|
||||
case 0x2b: return sf::Keyboard::ScanComma;
|
||||
case 0x2f: return sf::Keyboard::ScanPeriod;
|
||||
case 0x2c: return sf::Keyboard::ScanSlash;
|
||||
@ -1029,6 +1045,19 @@ Keyboard::Scancode HIDInputManager::nonLocalizedKey(UniChar virtualKeycode)
|
||||
case 0x6b: return sf::Keyboard::ScanF14;
|
||||
case 0x71: return sf::Keyboard::ScanF15;
|
||||
|
||||
case 0x6A: return sf::Keyboard::ScanF16;
|
||||
case 0x40: return sf::Keyboard::ScanF17;
|
||||
case 0x4F: return sf::Keyboard::ScanF18;
|
||||
case 0x50: return sf::Keyboard::ScanF19;
|
||||
case 0x5A: return sf::Keyboard::ScanF20;
|
||||
|
||||
/* TODO Those are missing:
|
||||
* case 0x: return sf::Keyboard::ScanF21;
|
||||
* case 0x: return sf::Keyboard::ScanF22;
|
||||
* case 0x: return sf::Keyboard::ScanF23;
|
||||
* case 0x: return sf::Keyboard::ScanF24;
|
||||
*/
|
||||
|
||||
case 0x39: return sf::Keyboard::ScanCapsLock;
|
||||
|
||||
/* TODO Those are missing:
|
||||
@ -1050,13 +1079,13 @@ Keyboard::Scancode HIDInputManager::nonLocalizedKey(UniChar virtualKeycode)
|
||||
case 0x7e: return sf::Keyboard::ScanUp;
|
||||
|
||||
case 0x47: return sf::Keyboard::ScanNumLock;
|
||||
case 0x4b: return sf::Keyboard::ScanDivide;
|
||||
case 0x43: return sf::Keyboard::ScanMultiply;
|
||||
case 0x4e: return sf::Keyboard::ScanMinus;
|
||||
case 0x45: return sf::Keyboard::ScanPlus;
|
||||
case 0x51: return sf::Keyboard::ScanNumpadEquals;
|
||||
case 0x4b: return sf::Keyboard::ScanNumpadDivide;
|
||||
case 0x43: return sf::Keyboard::ScanNumpadMultiply;
|
||||
case 0x4e: return sf::Keyboard::ScanNumpadMinus;
|
||||
case 0x45: return sf::Keyboard::ScanNumpadPlus;
|
||||
case 0x51: return sf::Keyboard::ScanNumpadEqual;
|
||||
case 0x4c: return sf::Keyboard::ScanNumpadEnter;
|
||||
case 0x41: return sf::Keyboard::ScanDecimal;
|
||||
case 0x41: return sf::Keyboard::ScanNumpadDecimal;
|
||||
|
||||
case 0x53: return sf::Keyboard::ScanNumpad1;
|
||||
case 0x54: return sf::Keyboard::ScanNumpad2;
|
||||
@ -1070,24 +1099,24 @@ Keyboard::Scancode HIDInputManager::nonLocalizedKey(UniChar virtualKeycode)
|
||||
case 0x52: return sf::Keyboard::ScanNumpad0;
|
||||
|
||||
/* TODO Those are missing:
|
||||
* case 0x: return sf::Keyboard::ScanReverseSolidus;
|
||||
* case 0x: return sf::Keyboard::ScanNonUsBackslash;
|
||||
* case 0x: return sf::Keyboard::ScanApplication;
|
||||
* case 0x: return sf::Keyboard::ScanExecute;
|
||||
* case 0x72: return sf::Keyboard::ScanHelp; // 0x72 is for Insert
|
||||
* case 0x: return sf::Keyboard::ScanHelp;
|
||||
* case 0x: return sf::Keyboard::ScanMenu;
|
||||
* case 0x: return sf::Keyboard::ScanSelect;
|
||||
* case 0x: return sf::Keyboard::ScanStop;
|
||||
* case 0x: return sf::Keyboard::ScanAgain;
|
||||
* case 0x: return sf::Keyboard::ScanRedo;
|
||||
* case 0x: return sf::Keyboard::ScanUndo;
|
||||
* case 0x: return sf::Keyboard::ScanCut;
|
||||
* case 0x: return sf::Keyboard::ScanCopy;
|
||||
* case 0x: return sf::Keyboard::ScanPaste;
|
||||
* case 0x: return sf::Keyboard::ScanFind;
|
||||
* case 0x: return sf::Keyboard::ScanSearch;
|
||||
*/
|
||||
|
||||
case 0x4a: return sf::Keyboard::ScanMute;
|
||||
case 0x48: return sf::Keyboard::ScanVolumeUp;
|
||||
case 0x49: return sf::Keyboard::ScanVolumeDown;
|
||||
case 0x4a: return sf::Keyboard::ScanVolumeMute;
|
||||
case 0x48: return sf::Keyboard::ScanVolumeUp;
|
||||
case 0x49: return sf::Keyboard::ScanVolumeDown;
|
||||
|
||||
/* NOTE Those are symmetric so we leave them out.
|
||||
* Thankfully handled through modifiers and not virtual codes.
|
||||
@ -1101,7 +1130,7 @@ Keyboard::Scancode HIDInputManager::nonLocalizedKey(UniChar virtualKeycode)
|
||||
* case 0x37: return sf::Keyboard::ScanRSystem;
|
||||
*/
|
||||
|
||||
default: return sf::Keyboard::ScanUnknown;
|
||||
default: return sf::Keyboard::ScanUnknown;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1155,16 +1184,14 @@ UInt8 HIDInputManager::scanToVirtualCode(Keyboard::Scancode code)
|
||||
case sf::Keyboard::ScanTab: return 0x30;
|
||||
case sf::Keyboard::ScanSpace: return 0x31;
|
||||
|
||||
// case sf::Keyboard::ScanHyphen: return 0; // 0x27 is for Quote
|
||||
|
||||
case sf::Keyboard::ScanEquals: return 0x18;
|
||||
case sf::Keyboard::ScanEqual: return 0x18;
|
||||
case sf::Keyboard::ScanLBracket: return 0x21;
|
||||
case sf::Keyboard::ScanRBracket: return 0x1e;
|
||||
case sf::Keyboard::ScanBackslash: return 0x2a;
|
||||
case sf::Keyboard::ScanDash: return 0x1b;
|
||||
case sf::Keyboard::ScanHyphen: return 0x1b;
|
||||
case sf::Keyboard::ScanSemicolon: return 0x29;
|
||||
case sf::Keyboard::ScanQuote: return 0x27;
|
||||
case sf::Keyboard::ScanGraveAccent: return 0x32;
|
||||
case sf::Keyboard::ScanApostrophe: return 0x27;
|
||||
case sf::Keyboard::ScanGrave: return 0x32;
|
||||
case sf::Keyboard::ScanComma: return 0x2b;
|
||||
case sf::Keyboard::ScanPeriod: return 0x2f;
|
||||
case sf::Keyboard::ScanSlash: return 0x2c;
|
||||
@ -1204,14 +1231,14 @@ UInt8 HIDInputManager::scanToVirtualCode(Keyboard::Scancode code)
|
||||
case sf::Keyboard::ScanDown: return 0x7d;
|
||||
case sf::Keyboard::ScanUp: return 0x7e;
|
||||
|
||||
case sf::Keyboard::ScanNumLock: return 0x47;
|
||||
case sf::Keyboard::ScanDivide: return 0x4b;
|
||||
case sf::Keyboard::ScanMultiply: return 0x43;
|
||||
case sf::Keyboard::ScanMinus: return 0x4e;
|
||||
case sf::Keyboard::ScanPlus: return 0x45;
|
||||
case sf::Keyboard::ScanNumpadEquals: return 0x51;
|
||||
case sf::Keyboard::ScanNumpadEnter: return 0x4c;
|
||||
case sf::Keyboard::ScanDecimal: return 0x41;
|
||||
case sf::Keyboard::ScanNumLock: return 0x47;
|
||||
case sf::Keyboard::ScanNumpadDivide: return 0x4b;
|
||||
case sf::Keyboard::ScanNumpadMultiply: return 0x43;
|
||||
case sf::Keyboard::ScanNumpadMinus: return 0x4e;
|
||||
case sf::Keyboard::ScanNumpadPlus: return 0x45;
|
||||
case sf::Keyboard::ScanNumpadEqual: return 0x51;
|
||||
case sf::Keyboard::ScanNumpadEnter: return 0x4c;
|
||||
case sf::Keyboard::ScanNumpadDecimal: return 0x41;
|
||||
|
||||
case sf::Keyboard::ScanNumpad1: return 0x53;
|
||||
case sf::Keyboard::ScanNumpad2: return 0x54;
|
||||
@ -1225,22 +1252,22 @@ UInt8 HIDInputManager::scanToVirtualCode(Keyboard::Scancode code)
|
||||
case sf::Keyboard::ScanNumpad0: return 0x52;
|
||||
|
||||
/* TODO Those are missing:
|
||||
* case sf::Keyboard::ScanReverseSolidus: return 0;
|
||||
* case sf::Keyboard::ScanNonUsBackslash: return 0;
|
||||
* case sf::Keyboard::ScanApplication: return 0;
|
||||
* case sf::Keyboard::ScanExecute: return 0;
|
||||
* case sf::Keyboard::ScanHelp: return 0;
|
||||
* case sf::Keyboard::ScanMenu: return 0;
|
||||
* case sf::Keyboard::ScanSelect: return 0;
|
||||
* case sf::Keyboard::ScanStop: return 0;
|
||||
* case sf::Keyboard::ScanAgain: return 0;
|
||||
* case sf::Keyboard::ScanRedo: return 0;
|
||||
* case sf::Keyboard::ScanUndo: return 0;
|
||||
* case sf::Keyboard::ScanCut: return 0;
|
||||
* case sf::Keyboard::ScanCopy: return 0;
|
||||
* case sf::Keyboard::ScanPaste: return 0;
|
||||
* case sf::Keyboard::ScanFind: return 0;
|
||||
* case sf::Keyboard::ScanSearch: return 0;
|
||||
*/
|
||||
|
||||
case sf::Keyboard::ScanMute: return 0x4a;
|
||||
case sf::Keyboard::ScanVolumeMute: return 0x4a;
|
||||
case sf::Keyboard::ScanVolumeUp: return 0x48;
|
||||
case sf::Keyboard::ScanVolumeDown: return 0x49;
|
||||
|
||||
@ -1298,10 +1325,10 @@ Keyboard::Key HIDInputManager::localizedKeyFallback(Keyboard::Scancode code)
|
||||
case sf::Keyboard::ScanDown: return sf::Keyboard::Down;
|
||||
case sf::Keyboard::ScanUp: return sf::Keyboard::Up;
|
||||
|
||||
case sf::Keyboard::ScanDivide: return sf::Keyboard::Divide;
|
||||
case sf::Keyboard::ScanMultiply: return sf::Keyboard::Multiply;
|
||||
case sf::Keyboard::ScanMinus: return sf::Keyboard::Subtract;
|
||||
case sf::Keyboard::ScanPlus: return sf::Keyboard::Add;
|
||||
case sf::Keyboard::ScanNumpadDivide: return sf::Keyboard::Divide;
|
||||
case sf::Keyboard::ScanNumpadMultiply: return sf::Keyboard::Multiply;
|
||||
case sf::Keyboard::ScanNumpadMinus: return sf::Keyboard::Subtract;
|
||||
case sf::Keyboard::ScanNumpadPlus: return sf::Keyboard::Add;
|
||||
|
||||
case sf::Keyboard::ScanNumpad0: return sf::Keyboard::Numpad1;
|
||||
case sf::Keyboard::ScanNumpad1: return sf::Keyboard::Numpad2;
|
||||
|
@ -64,13 +64,13 @@ public:
|
||||
static Keyboard::Key localize(Keyboard::Scancode code);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \copydoc sf::Keyboard::unlocalize
|
||||
/// \copydoc sf::Keyboard::delocalize
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Keyboard::Scancode unlocalize(Keyboard::Key key);
|
||||
static Keyboard::Scancode delocalize(Keyboard::Key key);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \copydoc sf::Keyboard::localizedRepresentation
|
||||
/// \copydoc sf::Keyboard::getDescription
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static String getDescription(Keyboard::Scancode code);
|
||||
|
@ -144,16 +144,16 @@ Keyboard::Key InputImpl::localize(Keyboard::Scancode code)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Keyboard::Scancode InputImpl::unlocalize(Keyboard::Key key)
|
||||
Keyboard::Scancode InputImpl::delocalize(Keyboard::Key key)
|
||||
{
|
||||
return HIDInputManager::getInstance().unlocalize(key);
|
||||
return HIDInputManager::getInstance().delocalize(key);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String InputImpl::getDescription(Keyboard::Scancode code)
|
||||
{
|
||||
return HIDInputManager::getInstance().localizedRepresentation(code);
|
||||
return HIDInputManager::getInstance().getDescription(code);
|
||||
}
|
||||
|
||||
|
||||
|
@ -42,14 +42,13 @@ bool InputImpl::isKeyPressed(Keyboard::Key key)
|
||||
return KeyboardImpl::isKeyPressed(key);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool InputImpl::isKeyPressed(Keyboard::Scancode code)
|
||||
{
|
||||
return KeyboardImpl::isKeyPressed(code);
|
||||
}
|
||||
|
||||
// Open a connection with the X server
|
||||
Display* display = OpenDisplay();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Keyboard::Key InputImpl::localize(Keyboard::Scancode code)
|
||||
@ -57,13 +56,11 @@ Keyboard::Key InputImpl::localize(Keyboard::Scancode code)
|
||||
return KeyboardImpl::localize(code);
|
||||
}
|
||||
|
||||
// Close the connection with the X server
|
||||
CloseDisplay(display);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Keyboard::Scancode InputImpl::unlocalize(Keyboard::Key key)
|
||||
Keyboard::Scancode InputImpl::delocalize(Keyboard::Key key)
|
||||
{
|
||||
return KeyboardImpl::unlocalize(key);
|
||||
return KeyboardImpl::delocalize(key);
|
||||
}
|
||||
|
||||
|
||||
|
@ -63,13 +63,13 @@ public:
|
||||
static Keyboard::Key localize(Keyboard::Scancode code);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \copydoc sf::Keyboard::unlocalize
|
||||
/// \copydoc sf::Keyboard::delocalize
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Keyboard::Scancode unlocalize(Keyboard::Key key);
|
||||
static Keyboard::Scancode delocalize(Keyboard::Key key);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \copydoc sf::Keyboard::localizedRepresentation
|
||||
/// \copydoc sf::Keyboard::getDescription
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static String getDescription(Keyboard::Scancode code);
|
||||
|
@ -1,7 +1,7 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org)
|
||||
// Copyright (C) 2007-2021 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
|
@ -1,7 +1,7 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org)
|
||||
// Copyright (C) 2007-2021 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
|
@ -1,7 +1,7 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org)
|
||||
// Copyright (C) 2007-2021 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
|
@ -1,7 +1,7 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org)
|
||||
// Copyright (C) 2007-2021 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
|
@ -1,7 +1,7 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org)
|
||||
// Copyright (C) 2007-2021 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
@ -34,21 +34,24 @@
|
||||
#include <X11/keysym.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/XKBlib.h>
|
||||
#include <cstring> // strcmp
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
const KeyCode NullKeyCode = 0;
|
||||
KeyCode scancodeToKeycode[sf::Keyboard::ScanCodeCount]; ///< Mapping of SFML scancode to X11 KeyCode
|
||||
sf::Keyboard::Scancode keycodeToScancode[256]; ///< Mapping of X11 KeyCode to SFML scancode
|
||||
bool isMappingInitialized = false;
|
||||
const int MaxKeyCode = 256;
|
||||
KeyCode scancodeToKeycode[sf::Keyboard::ScancodeCount]; ///< Mapping of SFML scancode to X11 KeyCode
|
||||
sf::Keyboard::Scancode keycodeToScancode[MaxKeyCode]; ///< Mapping of X11 KeyCode to SFML scancode
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool isValidKeycode(KeyCode keycode)
|
||||
{
|
||||
// Valid key code range is [8,255], according to the Xlib manual
|
||||
return (keycode >= 8) || (keycode <= 255);
|
||||
return (keycode >= 8);
|
||||
}
|
||||
|
||||
|
||||
@ -60,8 +63,7 @@ sf::Keyboard::Scancode translateKeyCode(Display* display, KeyCode keycode)
|
||||
|
||||
// Try secondary keysym, for numeric keypad keys
|
||||
// Note: This way we always force "NumLock = ON", which is intentional
|
||||
// since the returned key code should correspond to a physical
|
||||
// location.
|
||||
// since the returned key code should correspond to a physical location.
|
||||
KeySym keySym = XkbKeycodeToKeysym(display, keycode, 0, 1);
|
||||
|
||||
switch (keySym)
|
||||
@ -76,10 +78,10 @@ sf::Keyboard::Scancode translateKeyCode(Display* display, KeyCode keycode)
|
||||
case XK_KP_7: return sf::Keyboard::ScanNumpad7;
|
||||
case XK_KP_8: return sf::Keyboard::ScanNumpad8;
|
||||
case XK_KP_9: return sf::Keyboard::ScanNumpad9;
|
||||
case XK_KP_Separator: return sf::Keyboard::ScanDecimal;
|
||||
case XK_KP_Decimal: return sf::Keyboard::ScanDecimal;
|
||||
case XK_KP_Equal: return sf::Keyboard::ScanPadEquals;
|
||||
case XK_KP_Enter: return sf::Keyboard::ScanReturn;
|
||||
case XK_KP_Separator: return sf::Keyboard::ScanNumpadDecimal;
|
||||
case XK_KP_Decimal: return sf::Keyboard::ScanNumpadDecimal;
|
||||
case XK_KP_Equal: return sf::Keyboard::ScanNumpadEqual;
|
||||
case XK_KP_Enter: return sf::Keyboard::ScanNumpadEnter;
|
||||
default: break;
|
||||
}
|
||||
|
||||
@ -89,38 +91,52 @@ sf::Keyboard::Scancode translateKeyCode(Display* display, KeyCode keycode)
|
||||
|
||||
switch (keySym)
|
||||
{
|
||||
case XK_Return: return sf::Keyboard::ScanEnter;
|
||||
case XK_Escape: return sf::Keyboard::ScanEscape;
|
||||
case XK_BackSpace: return sf::Keyboard::ScanBackspace;
|
||||
case XK_Tab: return sf::Keyboard::ScanTab;
|
||||
case XK_Shift_L: return sf::Keyboard::ScanLShift;
|
||||
case XK_Shift_R: return sf::Keyboard::ScanRShift;
|
||||
case XK_Control_L: return sf::Keyboard::ScanLControl;
|
||||
case XK_Control_R: return sf::Keyboard::ScanRControl;
|
||||
case XK_Meta_L: return sf::Keyboard::ScanLAlt;
|
||||
case XK_Alt_L: return sf::Keyboard::ScanLAlt;
|
||||
case XK_Mode_switch: return sf::Keyboard::ScanRAlt; // Mapped to Alt_R on many keyboards
|
||||
case XK_ISO_Level3_Shift: return sf::Keyboard::ScanRAlt; // AltGr on at least some machines
|
||||
case XK_Meta_R: return sf::Keyboard::ScanRAlt;
|
||||
case XK_ISO_Level3_Shift: // AltGr on at least some machines
|
||||
case XK_Alt_R: return sf::Keyboard::ScanRAlt;
|
||||
case XK_Meta_L:
|
||||
case XK_Super_L: return sf::Keyboard::ScanLSystem;
|
||||
case XK_Meta_R:
|
||||
case XK_Super_R: return sf::Keyboard::ScanRSystem;
|
||||
case XK_Menu: return sf::Keyboard::ScanMenu;
|
||||
|
||||
case XK_Num_Lock: return sf::Keyboard::ScanNumLock;
|
||||
case XK_Caps_Lock: return sf::Keyboard::ScanCapsLock;
|
||||
case XK_Execute: return sf::Keyboard::ScanExecute;
|
||||
case XK_Hyper_R: return sf::Keyboard::ScanApplication;
|
||||
case XK_Select: return sf::Keyboard::ScanSelect;
|
||||
case XK_Cancel: return sf::Keyboard::ScanStop;
|
||||
case XK_Redo: return sf::Keyboard::ScanRedo;
|
||||
case XK_Undo: return sf::Keyboard::ScanUndo;
|
||||
case XK_Find: return sf::Keyboard::ScanSearch;
|
||||
case XK_Mode_switch: return sf::Keyboard::ScanModeChange;
|
||||
|
||||
case XK_Print: return sf::Keyboard::ScanPrintScreen;
|
||||
case XK_Scroll_Lock: return sf::Keyboard::ScanScrollLock;
|
||||
case XK_Pause: return sf::Keyboard::ScanPause;
|
||||
case XK_Delete: return sf::Keyboard::ScanDelete;
|
||||
case XK_BackSpace: return sf::Keyboard::ScanBackspace;
|
||||
case XK_Return: return sf::Keyboard::ScanEnter;
|
||||
case XK_Pause:
|
||||
case XK_Break: return sf::Keyboard::ScanPause;
|
||||
|
||||
case XK_Delete:
|
||||
case XK_Clear: return sf::Keyboard::ScanDelete;
|
||||
case XK_Home: return sf::Keyboard::ScanHome;
|
||||
case XK_End: return sf::Keyboard::ScanEnd;
|
||||
case XK_Page_Up: return sf::Keyboard::ScanPageUp;
|
||||
case XK_Page_Down: return sf::Keyboard::ScanPageDown;
|
||||
case XK_Insert: return sf::Keyboard::ScanInsert;
|
||||
|
||||
case XK_Left: return sf::Keyboard::ScanLeft;
|
||||
case XK_Right: return sf::Keyboard::ScanRight;
|
||||
case XK_Down: return sf::Keyboard::ScanDown;
|
||||
case XK_Up: return sf::Keyboard::ScanUp;
|
||||
|
||||
case XK_F1: return sf::Keyboard::ScanF1;
|
||||
case XK_F2: return sf::Keyboard::ScanF2;
|
||||
case XK_F3: return sf::Keyboard::ScanF3;
|
||||
@ -136,13 +152,21 @@ sf::Keyboard::Scancode translateKeyCode(Display* display, KeyCode keycode)
|
||||
case XK_F13: return sf::Keyboard::ScanF13;
|
||||
case XK_F14: return sf::Keyboard::ScanF14;
|
||||
case XK_F15: return sf::Keyboard::ScanF15;
|
||||
// TODO: add scancodes for F16-F25 when they're added in Scancode enum
|
||||
case XK_F16: return sf::Keyboard::ScanF16;
|
||||
case XK_F17: return sf::Keyboard::ScanF17;
|
||||
case XK_F18: return sf::Keyboard::ScanF18;
|
||||
case XK_F19: return sf::Keyboard::ScanF19;
|
||||
case XK_F20: return sf::Keyboard::ScanF20;
|
||||
case XK_F21: return sf::Keyboard::ScanF21;
|
||||
case XK_F22: return sf::Keyboard::ScanF22;
|
||||
case XK_F23: return sf::Keyboard::ScanF23;
|
||||
case XK_F24: return sf::Keyboard::ScanF24;
|
||||
|
||||
// Numeric keypad
|
||||
case XK_KP_Divide: return sf::Keyboard::ScanDivide;
|
||||
case XK_KP_Multiply: return sf::Keyboard::ScanMultiply;
|
||||
case XK_KP_Subtract: return sf::Keyboard::ScanMinus;
|
||||
case XK_KP_Add: return sf::Keyboard::ScanPlus;
|
||||
case XK_KP_Divide: return sf::Keyboard::ScanNumpadDivide;
|
||||
case XK_KP_Multiply: return sf::Keyboard::ScanNumpadMultiply;
|
||||
case XK_KP_Subtract: return sf::Keyboard::ScanNumpadMinus;
|
||||
case XK_KP_Add: return sf::Keyboard::ScanNumpadPlus;
|
||||
|
||||
// These should have been detected in secondary keysym test above!
|
||||
case XK_KP_Insert: return sf::Keyboard::ScanNumpad0;
|
||||
@ -154,40 +178,67 @@ sf::Keyboard::Scancode translateKeyCode(Display* display, KeyCode keycode)
|
||||
case XK_KP_Home: return sf::Keyboard::ScanNumpad7;
|
||||
case XK_KP_Up: return sf::Keyboard::ScanNumpad8;
|
||||
case XK_KP_Page_Up: return sf::Keyboard::ScanNumpad9;
|
||||
case XK_KP_Delete: return sf::Keyboard::ScanDecimal;
|
||||
case XK_KP_Equal: return sf::Keyboard::ScanPadEquals;
|
||||
case XK_KP_Enter: return sf::Keyboard::ScanReturn;
|
||||
case XK_KP_Delete: return sf::Keyboard::ScanNumpadDecimal;
|
||||
case XK_KP_Equal: return sf::Keyboard::ScanNumpadEqual;
|
||||
case XK_KP_Enter: return sf::Keyboard::ScanNumpadEnter;
|
||||
|
||||
// Last resort: Check for printable keys (should not happen if the XKB
|
||||
// extension is available). This will give a layout dependent mapping
|
||||
// (which is wrong, and we may miss some keys, especially on non-US
|
||||
// keyboards), but it's better than nothing...
|
||||
case XK_a: return sf::Keyboard::ScanA;
|
||||
case XK_b: return sf::Keyboard::ScanB;
|
||||
case XK_c: return sf::Keyboard::ScanC;
|
||||
case XK_d: return sf::Keyboard::ScanD;
|
||||
case XK_e: return sf::Keyboard::ScanE;
|
||||
case XK_f: return sf::Keyboard::ScanF;
|
||||
case XK_g: return sf::Keyboard::ScanG;
|
||||
case XK_h: return sf::Keyboard::ScanH;
|
||||
case XK_i: return sf::Keyboard::ScanI;
|
||||
case XK_j: return sf::Keyboard::ScanJ;
|
||||
case XK_k: return sf::Keyboard::ScanK;
|
||||
case XK_l: return sf::Keyboard::ScanL;
|
||||
case XK_m: return sf::Keyboard::ScanM;
|
||||
case XK_n: return sf::Keyboard::ScanN;
|
||||
case XK_o: return sf::Keyboard::ScanO;
|
||||
case XK_p: return sf::Keyboard::ScanP;
|
||||
case XK_q: return sf::Keyboard::ScanQ;
|
||||
case XK_r: return sf::Keyboard::ScanR;
|
||||
case XK_s: return sf::Keyboard::ScanS;
|
||||
case XK_t: return sf::Keyboard::ScanT;
|
||||
case XK_u: return sf::Keyboard::ScanU;
|
||||
case XK_v: return sf::Keyboard::ScanV;
|
||||
case XK_w: return sf::Keyboard::ScanW;
|
||||
case XK_x: return sf::Keyboard::ScanX;
|
||||
case XK_y: return sf::Keyboard::ScanY;
|
||||
case XK_z: return sf::Keyboard::ScanZ;
|
||||
case XK_a:
|
||||
case XK_A: return sf::Keyboard::ScanA;
|
||||
case XK_b:
|
||||
case XK_B: return sf::Keyboard::ScanB;
|
||||
case XK_c:
|
||||
case XK_C: return sf::Keyboard::ScanC;
|
||||
case XK_d:
|
||||
case XK_D: return sf::Keyboard::ScanD;
|
||||
case XK_e:
|
||||
case XK_E: return sf::Keyboard::ScanE;
|
||||
case XK_f:
|
||||
case XK_F: return sf::Keyboard::ScanF;
|
||||
case XK_g:
|
||||
case XK_G: return sf::Keyboard::ScanG;
|
||||
case XK_h:
|
||||
case XK_H: return sf::Keyboard::ScanH;
|
||||
case XK_i:
|
||||
case XK_I: return sf::Keyboard::ScanI;
|
||||
case XK_j:
|
||||
case XK_J: return sf::Keyboard::ScanJ;
|
||||
case XK_k:
|
||||
case XK_K: return sf::Keyboard::ScanK;
|
||||
case XK_l:
|
||||
case XK_L: return sf::Keyboard::ScanL;
|
||||
case XK_m:
|
||||
case XK_M: return sf::Keyboard::ScanM;
|
||||
case XK_n:
|
||||
case XK_N: return sf::Keyboard::ScanN;
|
||||
case XK_o:
|
||||
case XK_O: return sf::Keyboard::ScanO;
|
||||
case XK_p:
|
||||
case XK_P: return sf::Keyboard::ScanP;
|
||||
case XK_q:
|
||||
case XK_Q: return sf::Keyboard::ScanQ;
|
||||
case XK_r:
|
||||
case XK_R: return sf::Keyboard::ScanR;
|
||||
case XK_s:
|
||||
case XK_S: return sf::Keyboard::ScanS;
|
||||
case XK_t:
|
||||
case XK_T: return sf::Keyboard::ScanT;
|
||||
case XK_u:
|
||||
case XK_U: return sf::Keyboard::ScanU;
|
||||
case XK_v:
|
||||
case XK_V: return sf::Keyboard::ScanV;
|
||||
case XK_w:
|
||||
case XK_W: return sf::Keyboard::ScanW;
|
||||
case XK_x:
|
||||
case XK_X: return sf::Keyboard::ScanX;
|
||||
case XK_y:
|
||||
case XK_Y: return sf::Keyboard::ScanY;
|
||||
case XK_z:
|
||||
case XK_Z: return sf::Keyboard::ScanZ;
|
||||
|
||||
case XK_1: return sf::Keyboard::ScanNum1;
|
||||
case XK_2: return sf::Keyboard::ScanNum2;
|
||||
case XK_3: return sf::Keyboard::ScanNum3;
|
||||
@ -198,119 +249,258 @@ sf::Keyboard::Scancode translateKeyCode(Display* display, KeyCode keycode)
|
||||
case XK_8: return sf::Keyboard::ScanNum8;
|
||||
case XK_9: return sf::Keyboard::ScanNum9;
|
||||
case XK_0: return sf::Keyboard::ScanNum0;
|
||||
|
||||
case XK_space: return sf::Keyboard::ScanSpace;
|
||||
case XK_minus: return sf::Keyboard::ScanHyphen;
|
||||
case XK_equal: return sf::Keyboard::ScanEquals;
|
||||
case XK_equal: return sf::Keyboard::ScanEqual;
|
||||
case XK_bracketleft: return sf::Keyboard::ScanLBracket;
|
||||
case XK_bracketright: return sf::Keyboard::ScanRBracket;
|
||||
case XK_backslash: return sf::Keyboard::ScanBackslash;
|
||||
case XK_semicolon: return sf::Keyboard::ScanSemicolon;
|
||||
case XK_apostrophe: return sf::Keyboard::ScanQuote;
|
||||
case XK_grave: return sf::Keyboard::ScanGraveAccent;
|
||||
case XK_apostrophe: return sf::Keyboard::ScanApostrophe;
|
||||
case XK_grave: return sf::Keyboard::ScanGrave;
|
||||
case XK_comma: return sf::Keyboard::ScanComma;
|
||||
case XK_period: return sf::Keyboard::ScanPeriod;
|
||||
case XK_slash: return sf::Keyboard::ScanForwardSlash;
|
||||
case XK_less: return sf::Keyboard::ScanReverseSolidus;
|
||||
case XK_slash: return sf::Keyboard::ScanSlash;
|
||||
case XK_less: return sf::Keyboard::ScanNonUsBackslash;
|
||||
|
||||
default: return sf::Keyboard::ScanUnknown;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
std::map<std::string, sf::Keyboard::Scancode> GetNameScancodeMap()
|
||||
{
|
||||
std::map<std::string, sf::Keyboard::Scancode> mapping;
|
||||
|
||||
mapping.insert(std::make_pair("LSGT", sf::Keyboard::ScanNonUsBackslash));
|
||||
|
||||
mapping.insert(std::make_pair("TLDE", sf::Keyboard::ScanGrave));
|
||||
mapping.insert(std::make_pair("AE01", sf::Keyboard::ScanNum1));
|
||||
mapping.insert(std::make_pair("AE02", sf::Keyboard::ScanNum2));
|
||||
mapping.insert(std::make_pair("AE03", sf::Keyboard::ScanNum3));
|
||||
mapping.insert(std::make_pair("AE04", sf::Keyboard::ScanNum4));
|
||||
mapping.insert(std::make_pair("AE05", sf::Keyboard::ScanNum5));
|
||||
mapping.insert(std::make_pair("AE06", sf::Keyboard::ScanNum6));
|
||||
mapping.insert(std::make_pair("AE07", sf::Keyboard::ScanNum7));
|
||||
mapping.insert(std::make_pair("AE08", sf::Keyboard::ScanNum8));
|
||||
mapping.insert(std::make_pair("AE09", sf::Keyboard::ScanNum9));
|
||||
mapping.insert(std::make_pair("AE10", sf::Keyboard::ScanNum0));
|
||||
mapping.insert(std::make_pair("AE11", sf::Keyboard::ScanHyphen));
|
||||
mapping.insert(std::make_pair("AE12", sf::Keyboard::ScanEqual));
|
||||
mapping.insert(std::make_pair("BKSP", sf::Keyboard::ScanBackspace));
|
||||
mapping.insert(std::make_pair("TAB", sf::Keyboard::ScanTab));
|
||||
mapping.insert(std::make_pair("AD01", sf::Keyboard::ScanQ));
|
||||
mapping.insert(std::make_pair("AD02", sf::Keyboard::ScanW));
|
||||
mapping.insert(std::make_pair("AD03", sf::Keyboard::ScanE));
|
||||
mapping.insert(std::make_pair("AD04", sf::Keyboard::ScanR));
|
||||
mapping.insert(std::make_pair("AD05", sf::Keyboard::ScanT));
|
||||
mapping.insert(std::make_pair("AD06", sf::Keyboard::ScanY));
|
||||
mapping.insert(std::make_pair("AD07", sf::Keyboard::ScanU));
|
||||
mapping.insert(std::make_pair("AD08", sf::Keyboard::ScanI));
|
||||
mapping.insert(std::make_pair("AD09", sf::Keyboard::ScanO));
|
||||
mapping.insert(std::make_pair("AD10", sf::Keyboard::ScanP));
|
||||
mapping.insert(std::make_pair("AD11", sf::Keyboard::ScanLBracket));
|
||||
mapping.insert(std::make_pair("AD12", sf::Keyboard::ScanRBracket));
|
||||
mapping.insert(std::make_pair("BKSL", sf::Keyboard::ScanBackslash));
|
||||
mapping.insert(std::make_pair("RTRN", sf::Keyboard::ScanEnter));
|
||||
|
||||
mapping.insert(std::make_pair("CAPS", sf::Keyboard::ScanCapsLock));
|
||||
mapping.insert(std::make_pair("AC01", sf::Keyboard::ScanA));
|
||||
mapping.insert(std::make_pair("AC02", sf::Keyboard::ScanS));
|
||||
mapping.insert(std::make_pair("AC03", sf::Keyboard::ScanD));
|
||||
mapping.insert(std::make_pair("AC04", sf::Keyboard::ScanF));
|
||||
mapping.insert(std::make_pair("AC05", sf::Keyboard::ScanG));
|
||||
mapping.insert(std::make_pair("AC06", sf::Keyboard::ScanH));
|
||||
mapping.insert(std::make_pair("AC07", sf::Keyboard::ScanJ));
|
||||
mapping.insert(std::make_pair("AC08", sf::Keyboard::ScanK));
|
||||
mapping.insert(std::make_pair("AC09", sf::Keyboard::ScanL));
|
||||
mapping.insert(std::make_pair("AC10", sf::Keyboard::ScanSemicolon));
|
||||
mapping.insert(std::make_pair("AC11", sf::Keyboard::ScanApostrophe));
|
||||
mapping.insert(std::make_pair("AC12", sf::Keyboard::ScanBackslash));
|
||||
|
||||
mapping.insert(std::make_pair("LFSH", sf::Keyboard::ScanLShift));
|
||||
mapping.insert(std::make_pair("AB01", sf::Keyboard::ScanZ));
|
||||
mapping.insert(std::make_pair("AB02", sf::Keyboard::ScanX));
|
||||
mapping.insert(std::make_pair("AB03", sf::Keyboard::ScanC));
|
||||
mapping.insert(std::make_pair("AB04", sf::Keyboard::ScanV));
|
||||
mapping.insert(std::make_pair("AB05", sf::Keyboard::ScanB));
|
||||
mapping.insert(std::make_pair("AB06", sf::Keyboard::ScanN));
|
||||
mapping.insert(std::make_pair("AB07", sf::Keyboard::ScanM));
|
||||
mapping.insert(std::make_pair("AB08", sf::Keyboard::ScanComma));
|
||||
mapping.insert(std::make_pair("AB09", sf::Keyboard::ScanPeriod));
|
||||
mapping.insert(std::make_pair("AB10", sf::Keyboard::ScanSlash));
|
||||
mapping.insert(std::make_pair("RTSH", sf::Keyboard::ScanRShift));
|
||||
|
||||
mapping.insert(std::make_pair("LCTL", sf::Keyboard::ScanLControl));
|
||||
mapping.insert(std::make_pair("LALT", sf::Keyboard::ScanLAlt));
|
||||
mapping.insert(std::make_pair("SPCE", sf::Keyboard::ScanSpace));
|
||||
mapping.insert(std::make_pair("RCTL", sf::Keyboard::ScanRControl));
|
||||
mapping.insert(std::make_pair("RALT", sf::Keyboard::ScanRAlt));
|
||||
mapping.insert(std::make_pair("LVL3", sf::Keyboard::ScanRAlt));
|
||||
mapping.insert(std::make_pair("ALGR", sf::Keyboard::ScanRAlt));
|
||||
mapping.insert(std::make_pair("LWIN", sf::Keyboard::ScanLSystem));
|
||||
mapping.insert(std::make_pair("RWIN", sf::Keyboard::ScanRSystem));
|
||||
|
||||
mapping.insert(std::make_pair("HYPR", sf::Keyboard::ScanApplication));
|
||||
mapping.insert(std::make_pair("EXEC", sf::Keyboard::ScanExecute));
|
||||
mapping.insert(std::make_pair("MDSW", sf::Keyboard::ScanModeChange));
|
||||
mapping.insert(std::make_pair("MENU", sf::Keyboard::ScanMenu));
|
||||
mapping.insert(std::make_pair("COMP", sf::Keyboard::ScanMenu));
|
||||
mapping.insert(std::make_pair("SELE", sf::Keyboard::ScanSelect));
|
||||
|
||||
mapping.insert(std::make_pair("ESC", sf::Keyboard::ScanEscape));
|
||||
mapping.insert(std::make_pair("FK01", sf::Keyboard::ScanF1));
|
||||
mapping.insert(std::make_pair("FK02", sf::Keyboard::ScanF2));
|
||||
mapping.insert(std::make_pair("FK03", sf::Keyboard::ScanF3));
|
||||
mapping.insert(std::make_pair("FK04", sf::Keyboard::ScanF4));
|
||||
mapping.insert(std::make_pair("FK05", sf::Keyboard::ScanF5));
|
||||
mapping.insert(std::make_pair("FK06", sf::Keyboard::ScanF6));
|
||||
mapping.insert(std::make_pair("FK07", sf::Keyboard::ScanF7));
|
||||
mapping.insert(std::make_pair("FK08", sf::Keyboard::ScanF8));
|
||||
mapping.insert(std::make_pair("FK09", sf::Keyboard::ScanF9));
|
||||
mapping.insert(std::make_pair("FK10", sf::Keyboard::ScanF10));
|
||||
mapping.insert(std::make_pair("FK11", sf::Keyboard::ScanF11));
|
||||
mapping.insert(std::make_pair("FK12", sf::Keyboard::ScanF12));
|
||||
|
||||
mapping.insert(std::make_pair("PRSC", sf::Keyboard::ScanPrintScreen));
|
||||
mapping.insert(std::make_pair("SCLK", sf::Keyboard::ScanScrollLock));
|
||||
mapping.insert(std::make_pair("PAUS", sf::Keyboard::ScanPause));
|
||||
|
||||
mapping.insert(std::make_pair("INS", sf::Keyboard::ScanInsert));
|
||||
mapping.insert(std::make_pair("HOME", sf::Keyboard::ScanHome));
|
||||
mapping.insert(std::make_pair("PGUP", sf::Keyboard::ScanPageUp));
|
||||
mapping.insert(std::make_pair("DELE", sf::Keyboard::ScanDelete));
|
||||
mapping.insert(std::make_pair("END", sf::Keyboard::ScanEnd));
|
||||
mapping.insert(std::make_pair("PGDN", sf::Keyboard::ScanPageDown));
|
||||
|
||||
mapping.insert(std::make_pair("UP", sf::Keyboard::ScanUp));
|
||||
mapping.insert(std::make_pair("RGHT", sf::Keyboard::ScanRight));
|
||||
mapping.insert(std::make_pair("DOWN", sf::Keyboard::ScanDown));
|
||||
mapping.insert(std::make_pair("LEFT", sf::Keyboard::ScanLeft));
|
||||
|
||||
mapping.insert(std::make_pair("NMLK", sf::Keyboard::ScanNumLock));
|
||||
mapping.insert(std::make_pair("KPDV", sf::Keyboard::ScanNumpadDivide));
|
||||
mapping.insert(std::make_pair("KPMU", sf::Keyboard::ScanNumpadMultiply));
|
||||
mapping.insert(std::make_pair("KPSU", sf::Keyboard::ScanNumpadMinus));
|
||||
|
||||
mapping.insert(std::make_pair("KP7", sf::Keyboard::ScanNumpad7));
|
||||
mapping.insert(std::make_pair("KP8", sf::Keyboard::ScanNumpad8));
|
||||
mapping.insert(std::make_pair("KP9", sf::Keyboard::ScanNumpad9));
|
||||
mapping.insert(std::make_pair("KPAD", sf::Keyboard::ScanNumpadPlus));
|
||||
mapping.insert(std::make_pair("KP4", sf::Keyboard::ScanNumpad4));
|
||||
mapping.insert(std::make_pair("KP5", sf::Keyboard::ScanNumpad5));
|
||||
mapping.insert(std::make_pair("KP6", sf::Keyboard::ScanNumpad6));
|
||||
mapping.insert(std::make_pair("KP1", sf::Keyboard::ScanNumpad1));
|
||||
mapping.insert(std::make_pair("KP2", sf::Keyboard::ScanNumpad2));
|
||||
mapping.insert(std::make_pair("KP3", sf::Keyboard::ScanNumpad3));
|
||||
mapping.insert(std::make_pair("KPEN", sf::Keyboard::ScanNumpadEnter));
|
||||
mapping.insert(std::make_pair("KP0", sf::Keyboard::ScanNumpad0));
|
||||
mapping.insert(std::make_pair("KPDL", sf::Keyboard::ScanNumpadDecimal));
|
||||
mapping.insert(std::make_pair("KPEQ", sf::Keyboard::ScanNumpadEqual));
|
||||
|
||||
mapping.insert(std::make_pair("FK13", sf::Keyboard::ScanF13));
|
||||
mapping.insert(std::make_pair("FK14", sf::Keyboard::ScanF14));
|
||||
mapping.insert(std::make_pair("FK15", sf::Keyboard::ScanF15));
|
||||
mapping.insert(std::make_pair("FK16", sf::Keyboard::ScanF16));
|
||||
mapping.insert(std::make_pair("FK17", sf::Keyboard::ScanF17));
|
||||
mapping.insert(std::make_pair("FK18", sf::Keyboard::ScanF18));
|
||||
mapping.insert(std::make_pair("FK19", sf::Keyboard::ScanF19));
|
||||
mapping.insert(std::make_pair("FK20", sf::Keyboard::ScanF20));
|
||||
mapping.insert(std::make_pair("FK21", sf::Keyboard::ScanF21));
|
||||
mapping.insert(std::make_pair("FK22", sf::Keyboard::ScanF22));
|
||||
mapping.insert(std::make_pair("FK23", sf::Keyboard::ScanF23));
|
||||
mapping.insert(std::make_pair("FK24", sf::Keyboard::ScanF24));
|
||||
mapping.insert(std::make_pair("LMTA", sf::Keyboard::ScanLSystem));
|
||||
mapping.insert(std::make_pair("RMTA", sf::Keyboard::ScanRSystem));
|
||||
mapping.insert(std::make_pair("MUTE", sf::Keyboard::ScanVolumeMute));
|
||||
mapping.insert(std::make_pair("VOL-", sf::Keyboard::ScanVolumeDown));
|
||||
mapping.insert(std::make_pair("VOL+", sf::Keyboard::ScanVolumeUp));
|
||||
mapping.insert(std::make_pair("STOP", sf::Keyboard::ScanStop));
|
||||
mapping.insert(std::make_pair("REDO", sf::Keyboard::ScanRedo));
|
||||
mapping.insert(std::make_pair("AGAI", sf::Keyboard::ScanRedo));
|
||||
mapping.insert(std::make_pair("UNDO", sf::Keyboard::ScanUndo));
|
||||
mapping.insert(std::make_pair("COPY", sf::Keyboard::ScanCopy));
|
||||
mapping.insert(std::make_pair("PAST", sf::Keyboard::ScanPaste));
|
||||
mapping.insert(std::make_pair("FIND", sf::Keyboard::ScanSearch));
|
||||
mapping.insert(std::make_pair("CUT", sf::Keyboard::ScanCut));
|
||||
mapping.insert(std::make_pair("HELP", sf::Keyboard::ScanHelp));
|
||||
|
||||
mapping.insert(std::make_pair("I156", sf::Keyboard::ScanLaunchApplication1));
|
||||
mapping.insert(std::make_pair("I157", sf::Keyboard::ScanLaunchApplication2));
|
||||
mapping.insert(std::make_pair("I164", sf::Keyboard::ScanFavorites));
|
||||
mapping.insert(std::make_pair("I166", sf::Keyboard::ScanBack));
|
||||
mapping.insert(std::make_pair("I167", sf::Keyboard::ScanForward));
|
||||
mapping.insert(std::make_pair("I171", sf::Keyboard::ScanMediaNextTrack));
|
||||
mapping.insert(std::make_pair("I172", sf::Keyboard::ScanMediaPlayPause));
|
||||
mapping.insert(std::make_pair("I173", sf::Keyboard::ScanMediaPreviousTrack));
|
||||
mapping.insert(std::make_pair("I174", sf::Keyboard::ScanMediaStop));
|
||||
mapping.insert(std::make_pair("I180", sf::Keyboard::ScanHomePage));
|
||||
mapping.insert(std::make_pair("I181", sf::Keyboard::ScanRefresh));
|
||||
mapping.insert(std::make_pair("I223", sf::Keyboard::ScanLaunchMail));
|
||||
mapping.insert(std::make_pair("I234", sf::Keyboard::ScanLaunchMediaSelect));
|
||||
|
||||
return mapping;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void initMapping()
|
||||
void ensureMapping()
|
||||
{
|
||||
for (int i = 0; i < 256; ++i)
|
||||
static bool isMappingInitialized = false;
|
||||
|
||||
if (isMappingInitialized)
|
||||
return;
|
||||
|
||||
// Phase 1: Initialize mappings with default values
|
||||
for (int i = 0; i < sf::Keyboard::ScancodeCount; ++i)
|
||||
scancodeToKeycode[i] = NullKeyCode;
|
||||
|
||||
for (int i = 0; i < sf::Keyboard::ScanCodeCount; ++i)
|
||||
for (int i = 0; i < MaxKeyCode; ++i)
|
||||
keycodeToScancode[i] = sf::Keyboard::ScanUnknown;
|
||||
|
||||
// Phase 2: Get XKB names with key code
|
||||
Display* display = sf::priv::OpenDisplay();
|
||||
|
||||
// Find the X11 key code -> SFML key code mapping
|
||||
// This code was inspired by GLFW implementation
|
||||
|
||||
char name[XkbKeyNameLength + 1];
|
||||
XkbDescPtr desc = XkbGetMap(display, 0, XkbUseCoreKbd);
|
||||
XkbGetNames(display, XkbKeyNamesMask, desc);
|
||||
XkbDescPtr descriptor = XkbGetMap(display, 0, XkbUseCoreKbd);
|
||||
XkbGetNames(display, XkbKeyNamesMask, descriptor);
|
||||
|
||||
sf::Keyboard::Scancode sc;
|
||||
std::map<std::string, sf::Keyboard::Scancode> nameScancodeMap = GetNameScancodeMap();
|
||||
sf::Keyboard::Scancode scancode = sf::Keyboard::ScanUnknown;
|
||||
|
||||
for (int keycode = desc->min_key_code; keycode <= desc->max_key_code; ++keycode)
|
||||
for (int keycode = descriptor->min_key_code; keycode <= descriptor->max_key_code; ++keycode)
|
||||
{
|
||||
std::memcpy(name, desc->names->keys[keycode].name, XkbKeyNameLength);
|
||||
if (!isValidKeycode(static_cast<KeyCode>(keycode)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
std::memcpy(name, descriptor->names->keys[keycode].name, XkbKeyNameLength);
|
||||
name[XkbKeyNameLength] = '\0';
|
||||
|
||||
if (strcmp(name, "TLDE") == 0) sc = sf::Keyboard::ScanGraveAccent;
|
||||
else if (strcmp(name, "AE01") == 0) sc = sf::Keyboard::ScanNum1;
|
||||
else if (strcmp(name, "AE02") == 0) sc = sf::Keyboard::ScanNum2;
|
||||
else if (strcmp(name, "AE03") == 0) sc = sf::Keyboard::ScanNum3;
|
||||
else if (strcmp(name, "AE04") == 0) sc = sf::Keyboard::ScanNum4;
|
||||
else if (strcmp(name, "AE05") == 0) sc = sf::Keyboard::ScanNum5;
|
||||
else if (strcmp(name, "AE06") == 0) sc = sf::Keyboard::ScanNum6;
|
||||
else if (strcmp(name, "AE07") == 0) sc = sf::Keyboard::ScanNum7;
|
||||
else if (strcmp(name, "AE08") == 0) sc = sf::Keyboard::ScanNum8;
|
||||
else if (strcmp(name, "AE09") == 0) sc = sf::Keyboard::ScanNum9;
|
||||
else if (strcmp(name, "AE10") == 0) sc = sf::Keyboard::ScanNum0;
|
||||
else if (strcmp(name, "AE11") == 0) sc = sf::Keyboard::ScanDash;
|
||||
else if (strcmp(name, "AE12") == 0) sc = sf::Keyboard::ScanEquals;
|
||||
else if (strcmp(name, "TAB" ) == 0) sc = sf::Keyboard::ScanTab;
|
||||
else if (strcmp(name, "AD01") == 0) sc = sf::Keyboard::ScanQ;
|
||||
else if (strcmp(name, "AD02") == 0) sc = sf::Keyboard::ScanW;
|
||||
else if (strcmp(name, "AD03") == 0) sc = sf::Keyboard::ScanE;
|
||||
else if (strcmp(name, "AD04") == 0) sc = sf::Keyboard::ScanR;
|
||||
else if (strcmp(name, "AD05") == 0) sc = sf::Keyboard::ScanT;
|
||||
else if (strcmp(name, "AD06") == 0) sc = sf::Keyboard::ScanY;
|
||||
else if (strcmp(name, "AD07") == 0) sc = sf::Keyboard::ScanU;
|
||||
else if (strcmp(name, "AD08") == 0) sc = sf::Keyboard::ScanI;
|
||||
else if (strcmp(name, "AD09") == 0) sc = sf::Keyboard::ScanO;
|
||||
else if (strcmp(name, "AD10") == 0) sc = sf::Keyboard::ScanP;
|
||||
else if (strcmp(name, "AD11") == 0) sc = sf::Keyboard::ScanLBracket;
|
||||
else if (strcmp(name, "AD12") == 0) sc = sf::Keyboard::ScanRBracket;
|
||||
else if (strcmp(name, "BKSL") == 0) sc = sf::Keyboard::ScanBackslash;
|
||||
else if (strcmp(name, "AC01") == 0) sc = sf::Keyboard::ScanA;
|
||||
else if (strcmp(name, "AC02") == 0) sc = sf::Keyboard::ScanS;
|
||||
else if (strcmp(name, "AC03") == 0) sc = sf::Keyboard::ScanD;
|
||||
else if (strcmp(name, "AC04") == 0) sc = sf::Keyboard::ScanF;
|
||||
else if (strcmp(name, "AC05") == 0) sc = sf::Keyboard::ScanG;
|
||||
else if (strcmp(name, "AC06") == 0) sc = sf::Keyboard::ScanH;
|
||||
else if (strcmp(name, "AC07") == 0) sc = sf::Keyboard::ScanJ;
|
||||
else if (strcmp(name, "AC08") == 0) sc = sf::Keyboard::ScanK;
|
||||
else if (strcmp(name, "AC09") == 0) sc = sf::Keyboard::ScanL;
|
||||
else if (strcmp(name, "AC10") == 0) sc = sf::Keyboard::ScanSemicolon;
|
||||
else if (strcmp(name, "AC11") == 0) sc = sf::Keyboard::ScanQuote;
|
||||
else if (strcmp(name, "AB01") == 0) sc = sf::Keyboard::ScanZ;
|
||||
else if (strcmp(name, "AB02") == 0) sc = sf::Keyboard::ScanX;
|
||||
else if (strcmp(name, "AB03") == 0) sc = sf::Keyboard::ScanC;
|
||||
else if (strcmp(name, "AB04") == 0) sc = sf::Keyboard::ScanV;
|
||||
else if (strcmp(name, "AB05") == 0) sc = sf::Keyboard::ScanB;
|
||||
else if (strcmp(name, "AB06") == 0) sc = sf::Keyboard::ScanN;
|
||||
else if (strcmp(name, "AB07") == 0) sc = sf::Keyboard::ScanM;
|
||||
else if (strcmp(name, "AB08") == 0) sc = sf::Keyboard::ScanComma;
|
||||
else if (strcmp(name, "AB09") == 0) sc = sf::Keyboard::ScanPeriod;
|
||||
else if (strcmp(name, "AB10") == 0) sc = sf::Keyboard::ScanForwardSlash;
|
||||
else if (strcmp(name, "LSGT") == 0) sc = sf::Keyboard::ScanReverseSolidus;
|
||||
else sc = sf::Keyboard::ScanUnknown;
|
||||
std::map<std::string, sf::Keyboard::Scancode>::iterator mappedScancode = nameScancodeMap.find(std::string(name));
|
||||
scancode = sf::Keyboard::ScanUnknown;
|
||||
|
||||
if (isValidKeycode(keycode))
|
||||
{
|
||||
scancodeToKeycode[sc] = keycode;
|
||||
keycodeToScancode[keycode] = sc;
|
||||
}
|
||||
if (mappedScancode != nameScancodeMap.end())
|
||||
scancode = mappedScancode->second;
|
||||
|
||||
if (scancode != sf::Keyboard::ScanUnknown)
|
||||
scancodeToKeycode[scancode] = static_cast<KeyCode>(keycode);
|
||||
|
||||
keycodeToScancode[keycode] = scancode;
|
||||
}
|
||||
|
||||
XkbFreeNames(desc, XkbKeyNamesMask, True);
|
||||
XkbFreeKeyboard(desc, 0, True);
|
||||
XkbFreeNames(descriptor, XkbKeyNamesMask, True);
|
||||
XkbFreeKeyboard(descriptor, 0, True);
|
||||
|
||||
// Translate un-translated keycodes using traditional X11 KeySym lookups
|
||||
// Valid keycodes are [8;255], so we only initialize them
|
||||
for (int keycode = 8; keycode < 256; ++keycode)
|
||||
// Phase 3: Translate un-translated keycodes using traditional X11 KeySym lookups
|
||||
for (int keycode = 8; keycode < MaxKeyCode; ++keycode)
|
||||
{
|
||||
if (keycodeToScancode[keycode] == sf::Keyboard::ScanUnknown)
|
||||
if (keycodeToScancode[static_cast<KeyCode>(keycode)] == sf::Keyboard::ScanUnknown)
|
||||
{
|
||||
sf::Keyboard::Scancode sc = translateKeyCode(display, keycode);
|
||||
scancodeToKeycode[sc] = keycode;
|
||||
keycodeToScancode[keycode] = sc;
|
||||
scancode = translateKeyCode(display, static_cast<KeyCode>(keycode));
|
||||
scancodeToKeycode[scancode] = static_cast<KeyCode>(keycode);
|
||||
keycodeToScancode[keycode] = scancode;
|
||||
}
|
||||
}
|
||||
|
||||
@ -323,18 +513,19 @@ void initMapping()
|
||||
////////////////////////////////////////////////////////////
|
||||
KeyCode scancodeToKeyCode(sf::Keyboard::Scancode code)
|
||||
{
|
||||
if (!isMappingInitialized)
|
||||
initMapping();
|
||||
ensureMapping();
|
||||
|
||||
return scancodeToKeycode[code];
|
||||
if (code != sf::Keyboard::ScanUnknown)
|
||||
return scancodeToKeycode[code];
|
||||
|
||||
return NullKeyCode;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sf::Keyboard::Scancode keyCodeToScancode(KeyCode code)
|
||||
{
|
||||
if (!isMappingInitialized)
|
||||
initMapping();
|
||||
ensureMapping();
|
||||
|
||||
if (isValidKeycode(code))
|
||||
return keycodeToScancode[code];
|
||||
@ -421,7 +612,7 @@ bool KeyboardImpl::isKeyPressed(Keyboard::Scancode code)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Keyboard::Scancode KeyboardImpl::unlocalize(Keyboard::Key key)
|
||||
Keyboard::Scancode KeyboardImpl::delocalize(Keyboard::Key key)
|
||||
{
|
||||
KeyCode keycode = keyToKeyCode(key);
|
||||
return keyCodeToScancode(keycode);
|
||||
@ -443,13 +634,21 @@ String KeyboardImpl::getDescription(Keyboard::Scancode code)
|
||||
|
||||
// these scancodes actually correspond to keys with input
|
||||
// but we want to return their description, not their behaviour
|
||||
if (code == Keyboard::ScanEscape ||
|
||||
code == Keyboard::ScanEnter ||
|
||||
code == Keyboard::ScanReturn ||
|
||||
code == Keyboard::ScanTab ||
|
||||
code == Keyboard::ScanDelete ||
|
||||
code == Keyboard::ScanBackspace ||
|
||||
code == Keyboard::ScanSpace)
|
||||
if (code == Keyboard::ScanEnter ||
|
||||
code == Keyboard::ScanEscape ||
|
||||
code == Keyboard::ScanBackspace ||
|
||||
code == Keyboard::ScanTab ||
|
||||
code == Keyboard::ScanSpace ||
|
||||
code == Keyboard::ScanScrollLock ||
|
||||
code == Keyboard::ScanPause ||
|
||||
code == Keyboard::ScanDelete ||
|
||||
code == Keyboard::ScanNumpadDivide ||
|
||||
code == Keyboard::ScanNumpadMultiply ||
|
||||
code == Keyboard::ScanNumpadMinus ||
|
||||
code == Keyboard::ScanNumpadPlus ||
|
||||
code == Keyboard::ScanNumpadEqual ||
|
||||
code == Keyboard::ScanNumpadEnter ||
|
||||
code == Keyboard::ScanNumpadDecimal)
|
||||
{
|
||||
checkInput = false;
|
||||
}
|
||||
@ -466,91 +665,115 @@ String KeyboardImpl::getDescription(Keyboard::Scancode code)
|
||||
// Fallback to our best guess for the keys that are known to be independent of the layout.
|
||||
switch (code)
|
||||
{
|
||||
case Keyboard::ScanEnter: return "Enter";
|
||||
case Keyboard::ScanEscape: return "Escape";
|
||||
case Keyboard::ScanBackspace: return "Backspace";
|
||||
case Keyboard::ScanTab: return "Tab";
|
||||
case Keyboard::ScanSpace: return "Space";
|
||||
case Keyboard::ScanEnter: return "Enter";
|
||||
case Keyboard::ScanEscape: return "Escape";
|
||||
case Keyboard::ScanBackspace: return "Backspace";
|
||||
case Keyboard::ScanTab: return "Tab";
|
||||
case Keyboard::ScanSpace: return "Space";
|
||||
|
||||
case Keyboard::ScanF1: return "F1";
|
||||
case Keyboard::ScanF2: return "F2";
|
||||
case Keyboard::ScanF3: return "F3";
|
||||
case Keyboard::ScanF4: return "F4";
|
||||
case Keyboard::ScanF5: return "F5";
|
||||
case Keyboard::ScanF6: return "F6";
|
||||
case Keyboard::ScanF7: return "F7";
|
||||
case Keyboard::ScanF8: return "F8";
|
||||
case Keyboard::ScanF9: return "F9";
|
||||
case Keyboard::ScanF10: return "F10";
|
||||
case Keyboard::ScanF11: return "F11";
|
||||
case Keyboard::ScanF12: return "F12";
|
||||
case Keyboard::ScanF13: return "F13";
|
||||
case Keyboard::ScanF14: return "F14";
|
||||
case Keyboard::ScanF15: return "F15";
|
||||
// TODO: add F16-F25 once they're added in Scancode enum
|
||||
case Keyboard::ScanF1: return "F1";
|
||||
case Keyboard::ScanF2: return "F2";
|
||||
case Keyboard::ScanF3: return "F3";
|
||||
case Keyboard::ScanF4: return "F4";
|
||||
case Keyboard::ScanF5: return "F5";
|
||||
case Keyboard::ScanF6: return "F6";
|
||||
case Keyboard::ScanF7: return "F7";
|
||||
case Keyboard::ScanF8: return "F8";
|
||||
case Keyboard::ScanF9: return "F9";
|
||||
case Keyboard::ScanF10: return "F10";
|
||||
case Keyboard::ScanF11: return "F11";
|
||||
case Keyboard::ScanF12: return "F12";
|
||||
case Keyboard::ScanF13: return "F13";
|
||||
case Keyboard::ScanF14: return "F14";
|
||||
case Keyboard::ScanF15: return "F15";
|
||||
case Keyboard::ScanF16: return "F16";
|
||||
case Keyboard::ScanF17: return "F17";
|
||||
case Keyboard::ScanF18: return "F18";
|
||||
case Keyboard::ScanF19: return "F19";
|
||||
case Keyboard::ScanF20: return "F20";
|
||||
case Keyboard::ScanF21: return "F21";
|
||||
case Keyboard::ScanF22: return "F22";
|
||||
case Keyboard::ScanF23: return "F23";
|
||||
case Keyboard::ScanF24: return "F24";
|
||||
|
||||
case Keyboard::ScanCapsLock: return "CapsLock";
|
||||
case Keyboard::ScanPrintScreen: return "PrintScreen";
|
||||
case Keyboard::ScanScrollLock: return "ScrollLock";
|
||||
case Keyboard::ScanCapsLock: return "Caps Lock";
|
||||
case Keyboard::ScanPrintScreen: return "Print Screen";
|
||||
case Keyboard::ScanScrollLock: return "Scroll Lock";
|
||||
|
||||
case Keyboard::ScanPause: return "Pause";
|
||||
case Keyboard::ScanInsert: return "Insert";
|
||||
case Keyboard::ScanHome: return "Home";
|
||||
case Keyboard::ScanPageUp: return "PageUp";
|
||||
case Keyboard::ScanDelete: return "Delete";
|
||||
case Keyboard::ScanEnd: return "End";
|
||||
case Keyboard::ScanPageDown: return "PageDown";
|
||||
case Keyboard::ScanPause: return "Pause";
|
||||
case Keyboard::ScanInsert: return "Insert";
|
||||
case Keyboard::ScanHome: return "Home";
|
||||
case Keyboard::ScanPageUp: return "Page Up";
|
||||
case Keyboard::ScanDelete: return "Delete";
|
||||
case Keyboard::ScanEnd: return "End";
|
||||
case Keyboard::ScanPageDown: return "Page Down";
|
||||
|
||||
case Keyboard::ScanLeft: return "Left Arrow";
|
||||
case Keyboard::ScanRight: return "Right Arrow";
|
||||
case Keyboard::ScanDown: return "Down Arrow";
|
||||
case Keyboard::ScanUp: return "Up Arrow";
|
||||
case Keyboard::ScanLeft: return "Left Arrow";
|
||||
case Keyboard::ScanRight: return "Right Arrow";
|
||||
case Keyboard::ScanDown: return "Down Arrow";
|
||||
case Keyboard::ScanUp: return "Up Arrow";
|
||||
|
||||
case Keyboard::ScanNumLock: return "NumLock";
|
||||
case Keyboard::ScanDivide: return "Divide (Numpad)";
|
||||
case Keyboard::ScanMultiply: return "Multiply (Numpad)";
|
||||
case Keyboard::ScanMinus: return "Minux (Numpad)";
|
||||
case Keyboard::ScanPlus: return "Plus (Numpad)";
|
||||
case Keyboard::ScanPadEquals: return "Equals (Numpad)";
|
||||
case Keyboard::ScanReturn: return "Enter (Numpad)";
|
||||
case Keyboard::ScanDecimal: return "Decimal (Numpad)";
|
||||
case Keyboard::ScanNumLock: return "Num Lock";
|
||||
case Keyboard::ScanNumpadDivide: return "Divide (Numpad)";
|
||||
case Keyboard::ScanNumpadMultiply: return "Multiply (Numpad)";
|
||||
case Keyboard::ScanNumpadMinus: return "Minus (Numpad)";
|
||||
case Keyboard::ScanNumpadPlus: return "Plus (Numpad)";
|
||||
case Keyboard::ScanNumpadEqual: return "Equal (Numpad)";
|
||||
case Keyboard::ScanNumpadEnter: return "Enter (Numpad)";
|
||||
case Keyboard::ScanNumpadDecimal: return "Decimal (Numpad)";
|
||||
|
||||
case Keyboard::ScanNumpad0: return "0 (Numpad)";
|
||||
case Keyboard::ScanNumpad1: return "1 (Numpad)";
|
||||
case Keyboard::ScanNumpad2: return "2 (Numpad)";
|
||||
case Keyboard::ScanNumpad3: return "3 (Numpad)";
|
||||
case Keyboard::ScanNumpad4: return "4 (Numpad)";
|
||||
case Keyboard::ScanNumpad5: return "5 (Numpad)";
|
||||
case Keyboard::ScanNumpad6: return "6 (Numpad)";
|
||||
case Keyboard::ScanNumpad7: return "7 (Numpad)";
|
||||
case Keyboard::ScanNumpad8: return "8 (Numpad)";
|
||||
case Keyboard::ScanNumpad9: return "9 (Numpad)";
|
||||
case Keyboard::ScanNumpad0: return "0 (Numpad)";
|
||||
case Keyboard::ScanNumpad1: return "1 (Numpad)";
|
||||
case Keyboard::ScanNumpad2: return "2 (Numpad)";
|
||||
case Keyboard::ScanNumpad3: return "3 (Numpad)";
|
||||
case Keyboard::ScanNumpad4: return "4 (Numpad)";
|
||||
case Keyboard::ScanNumpad5: return "5 (Numpad)";
|
||||
case Keyboard::ScanNumpad6: return "6 (Numpad)";
|
||||
case Keyboard::ScanNumpad7: return "7 (Numpad)";
|
||||
case Keyboard::ScanNumpad8: return "8 (Numpad)";
|
||||
case Keyboard::ScanNumpad9: return "9 (Numpad)";
|
||||
|
||||
case Keyboard::ScanApplication: return "Application";
|
||||
case Keyboard::ScanExecute: return "Execute";
|
||||
case Keyboard::ScanHelp: return "Help";
|
||||
case Keyboard::ScanMenu: return "Menu";
|
||||
case Keyboard::ScanSelect: return "Select";
|
||||
case Keyboard::ScanStop: return "Stop";
|
||||
case Keyboard::ScanAgain: return "Again";
|
||||
case Keyboard::ScanUndo: return "Undo";
|
||||
case Keyboard::ScanCut: return "Cut";
|
||||
case Keyboard::ScanCopy: return "Copy";
|
||||
case Keyboard::ScanPaste: return "Paste";
|
||||
case Keyboard::ScanFind: return "Find";
|
||||
case Keyboard::ScanMute: return "Mute";
|
||||
case Keyboard::ScanVolumeUp: return "Volume Up";
|
||||
case Keyboard::ScanVolumeDown: return "Volume Down";
|
||||
case Keyboard::ScanApplication: return "Application";
|
||||
case Keyboard::ScanExecute: return "Execute";
|
||||
case Keyboard::ScanHelp: return "Help";
|
||||
case Keyboard::ScanMenu: return "Menu";
|
||||
case Keyboard::ScanSelect: return "Select";
|
||||
case Keyboard::ScanStop: return "Stop";
|
||||
case Keyboard::ScanRedo: return "Redo";
|
||||
case Keyboard::ScanUndo: return "Undo";
|
||||
case Keyboard::ScanCut: return "Cut";
|
||||
case Keyboard::ScanCopy: return "Copy";
|
||||
case Keyboard::ScanPaste: return "Paste";
|
||||
case Keyboard::ScanSearch: return "Search";
|
||||
|
||||
case Keyboard::ScanLControl: return "Left Control";
|
||||
case Keyboard::ScanLShift: return "Left Shift";
|
||||
case Keyboard::ScanLAlt: return "Left Meta";
|
||||
case Keyboard::ScanLSystem: return "Left Super";
|
||||
case Keyboard::ScanRControl: return "Right Control";
|
||||
case Keyboard::ScanRShift: return "Right Shift";
|
||||
case Keyboard::ScanRAlt: return "Right Meta";
|
||||
case Keyboard::ScanRSystem: return "Right Super";
|
||||
default: return "Unknown Scancode"; // no guess good enough possible.
|
||||
case Keyboard::ScanVolumeMute: return "Volume Mute";
|
||||
case Keyboard::ScanVolumeUp: return "Volume Up";
|
||||
case Keyboard::ScanVolumeDown: return "Volume Down";
|
||||
|
||||
case Keyboard::ScanLControl: return "Left Control";
|
||||
case Keyboard::ScanLShift: return "Left Shift";
|
||||
case Keyboard::ScanLAlt: return "Left Alt";
|
||||
case Keyboard::ScanLSystem: return "Left System";
|
||||
case Keyboard::ScanRControl: return "Right Control";
|
||||
case Keyboard::ScanRShift: return "Right Shift";
|
||||
case Keyboard::ScanRAlt: return "Right Alt";
|
||||
case Keyboard::ScanRSystem: return "Right System";
|
||||
|
||||
case Keyboard::ScanLaunchApplication1: return "Launch Application 1";
|
||||
case Keyboard::ScanLaunchApplication2: return "Launch Application 2";
|
||||
case Keyboard::ScanFavorites: return "Favorites";
|
||||
case Keyboard::ScanBack: return "Back";
|
||||
case Keyboard::ScanForward: return "Forward";
|
||||
case Keyboard::ScanMediaNextTrack: return "Media Next Track";
|
||||
case Keyboard::ScanMediaPlayPause: return "Media Play Pause";
|
||||
case Keyboard::ScanMediaPreviousTrack: return "Media Previous Track";
|
||||
case Keyboard::ScanMediaStop: return "Media Stop";
|
||||
case Keyboard::ScanHomePage: return "Home Page";
|
||||
case Keyboard::ScanRefresh: return "Refresh";
|
||||
case Keyboard::ScanLaunchMail: return "Launch Mail";
|
||||
case Keyboard::ScanLaunchMediaSelect: return "Launch Media Select";
|
||||
|
||||
default: return "Unknown Scancode";
|
||||
}
|
||||
}
|
||||
|
||||
@ -578,7 +801,7 @@ Keyboard::Key KeyboardImpl::getKeyFromEvent(XKeyEvent& event)
|
||||
////////////////////////////////////////////////////////////
|
||||
Keyboard::Scancode KeyboardImpl::getScancodeFromEvent(XKeyEvent& event)
|
||||
{
|
||||
return keyCodeToScancode(event.keycode);
|
||||
return keyCodeToScancode(static_cast<KeyCode>(event.keycode));
|
||||
}
|
||||
|
||||
} // namespace priv
|
||||
|
@ -1,7 +1,7 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2018 Laurent Gomila (laurent@sfml-dev.org)
|
||||
// Copyright (C) 2007-2021 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
@ -62,10 +62,10 @@ public:
|
||||
/// \copydoc sf::Keyboard::localize
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Keyboard::Scancode unlocalize(Keyboard::Key key);
|
||||
static Keyboard::Scancode delocalize(Keyboard::Key key);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \copydoc sf::Keyboard::unlocalize
|
||||
/// \copydoc sf::Keyboard::delocalize
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Keyboard::Key localize(Keyboard::Scancode code);
|
||||
|
@ -364,117 +364,6 @@ namespace
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
sf::Keyboard::Key keysymToSF(KeySym symbol)
|
||||
{
|
||||
switch (symbol)
|
||||
{
|
||||
case XK_Shift_L: return sf::Keyboard::LShift;
|
||||
case XK_Shift_R: return sf::Keyboard::RShift;
|
||||
case XK_Control_L: return sf::Keyboard::LControl;
|
||||
case XK_Control_R: return sf::Keyboard::RControl;
|
||||
case XK_Alt_L: return sf::Keyboard::LAlt;
|
||||
case XK_Alt_R: return sf::Keyboard::RAlt;
|
||||
case XK_Super_L: return sf::Keyboard::LSystem;
|
||||
case XK_Super_R: return sf::Keyboard::RSystem;
|
||||
case XK_Menu: return sf::Keyboard::Menu;
|
||||
case XK_Escape: return sf::Keyboard::Escape;
|
||||
case XK_semicolon: return sf::Keyboard::Semicolon;
|
||||
case XK_slash: return sf::Keyboard::Slash;
|
||||
case XK_equal: return sf::Keyboard::Equal;
|
||||
case XK_minus: return sf::Keyboard::Hyphen;
|
||||
case XK_bracketleft: return sf::Keyboard::LBracket;
|
||||
case XK_bracketright: return sf::Keyboard::RBracket;
|
||||
case XK_comma: return sf::Keyboard::Comma;
|
||||
case XK_period: return sf::Keyboard::Period;
|
||||
case XK_apostrophe: return sf::Keyboard::Quote;
|
||||
case XK_backslash: return sf::Keyboard::Backslash;
|
||||
case XK_grave: return sf::Keyboard::Tilde;
|
||||
case XK_space: return sf::Keyboard::Space;
|
||||
case XK_Return: return sf::Keyboard::Enter;
|
||||
case XK_KP_Enter: return sf::Keyboard::Enter;
|
||||
case XK_BackSpace: return sf::Keyboard::Backspace;
|
||||
case XK_Tab: return sf::Keyboard::Tab;
|
||||
case XK_Prior: return sf::Keyboard::PageUp;
|
||||
case XK_Next: return sf::Keyboard::PageDown;
|
||||
case XK_End: return sf::Keyboard::End;
|
||||
case XK_Home: return sf::Keyboard::Home;
|
||||
case XK_Insert: return sf::Keyboard::Insert;
|
||||
case XK_Delete: return sf::Keyboard::Delete;
|
||||
case XK_KP_Add: return sf::Keyboard::Add;
|
||||
case XK_KP_Subtract: return sf::Keyboard::Subtract;
|
||||
case XK_KP_Multiply: return sf::Keyboard::Multiply;
|
||||
case XK_KP_Divide: return sf::Keyboard::Divide;
|
||||
case XK_Pause: return sf::Keyboard::Pause;
|
||||
case XK_F1: return sf::Keyboard::F1;
|
||||
case XK_F2: return sf::Keyboard::F2;
|
||||
case XK_F3: return sf::Keyboard::F3;
|
||||
case XK_F4: return sf::Keyboard::F4;
|
||||
case XK_F5: return sf::Keyboard::F5;
|
||||
case XK_F6: return sf::Keyboard::F6;
|
||||
case XK_F7: return sf::Keyboard::F7;
|
||||
case XK_F8: return sf::Keyboard::F8;
|
||||
case XK_F9: return sf::Keyboard::F9;
|
||||
case XK_F10: return sf::Keyboard::F10;
|
||||
case XK_F11: return sf::Keyboard::F11;
|
||||
case XK_F12: return sf::Keyboard::F12;
|
||||
case XK_F13: return sf::Keyboard::F13;
|
||||
case XK_F14: return sf::Keyboard::F14;
|
||||
case XK_F15: return sf::Keyboard::F15;
|
||||
case XK_Left: return sf::Keyboard::Left;
|
||||
case XK_Right: return sf::Keyboard::Right;
|
||||
case XK_Up: return sf::Keyboard::Up;
|
||||
case XK_Down: return sf::Keyboard::Down;
|
||||
case XK_KP_Insert: return sf::Keyboard::Numpad0;
|
||||
case XK_KP_End: return sf::Keyboard::Numpad1;
|
||||
case XK_KP_Down: return sf::Keyboard::Numpad2;
|
||||
case XK_KP_Page_Down: return sf::Keyboard::Numpad3;
|
||||
case XK_KP_Left: return sf::Keyboard::Numpad4;
|
||||
case XK_KP_Begin: return sf::Keyboard::Numpad5;
|
||||
case XK_KP_Right: return sf::Keyboard::Numpad6;
|
||||
case XK_KP_Home: return sf::Keyboard::Numpad7;
|
||||
case XK_KP_Up: return sf::Keyboard::Numpad8;
|
||||
case XK_KP_Page_Up: return sf::Keyboard::Numpad9;
|
||||
case XK_a: return sf::Keyboard::A;
|
||||
case XK_b: return sf::Keyboard::B;
|
||||
case XK_c: return sf::Keyboard::C;
|
||||
case XK_d: return sf::Keyboard::D;
|
||||
case XK_e: return sf::Keyboard::E;
|
||||
case XK_f: return sf::Keyboard::F;
|
||||
case XK_g: return sf::Keyboard::G;
|
||||
case XK_h: return sf::Keyboard::H;
|
||||
case XK_i: return sf::Keyboard::I;
|
||||
case XK_j: return sf::Keyboard::J;
|
||||
case XK_k: return sf::Keyboard::K;
|
||||
case XK_l: return sf::Keyboard::L;
|
||||
case XK_m: return sf::Keyboard::M;
|
||||
case XK_n: return sf::Keyboard::N;
|
||||
case XK_o: return sf::Keyboard::O;
|
||||
case XK_p: return sf::Keyboard::P;
|
||||
case XK_q: return sf::Keyboard::Q;
|
||||
case XK_r: return sf::Keyboard::R;
|
||||
case XK_s: return sf::Keyboard::S;
|
||||
case XK_t: return sf::Keyboard::T;
|
||||
case XK_u: return sf::Keyboard::U;
|
||||
case XK_v: return sf::Keyboard::V;
|
||||
case XK_w: return sf::Keyboard::W;
|
||||
case XK_x: return sf::Keyboard::X;
|
||||
case XK_y: return sf::Keyboard::Y;
|
||||
case XK_z: return sf::Keyboard::Z;
|
||||
case XK_0: return sf::Keyboard::Num0;
|
||||
case XK_1: return sf::Keyboard::Num1;
|
||||
case XK_2: return sf::Keyboard::Num2;
|
||||
case XK_3: return sf::Keyboard::Num3;
|
||||
case XK_4: return sf::Keyboard::Num4;
|
||||
case XK_5: return sf::Keyboard::Num5;
|
||||
case XK_6: return sf::Keyboard::Num6;
|
||||
case XK_7: return sf::Keyboard::Num7;
|
||||
case XK_8: return sf::Keyboard::Num8;
|
||||
case XK_9: return sf::Keyboard::Num9;
|
||||
}
|
||||
|
||||
return sf::Keyboard::Unknown;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,437 +37,581 @@
|
||||
#include <SFML/Window/Win32/InputImpl.hpp>
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
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 InputImpl::m_scancodeToKeyMapping[Keyboard::ScancodeCount]; ///< Mapping from Scancode to Key
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Keyboard::Key winKeyToSfKey(int vkey)
|
||||
Keyboard::Key virtualKeyToSfKey(UINT virtualKey)
|
||||
{
|
||||
Keyboard::Key key;
|
||||
switch (vkey)
|
||||
switch (virtualKey)
|
||||
{
|
||||
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;
|
||||
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; break;
|
||||
case VK_OEM_7: key = Keyboard::Apostrophe; 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 sfKeyToVirtualKey(Keyboard::Key key)
|
||||
{
|
||||
int vkey = 0;
|
||||
int virtualKey = 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::Hyphen: vkey = VK_OEM_MINUS; break;
|
||||
case Keyboard::Space: vkey = VK_SPACE; break;
|
||||
case Keyboard::Enter: 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;
|
||||
default: virtualKey = 0; break;
|
||||
case Keyboard::A: virtualKey = 'A'; break;
|
||||
case Keyboard::B: virtualKey = 'B'; break;
|
||||
case Keyboard::C: virtualKey = 'C'; break;
|
||||
case Keyboard::D: virtualKey = 'D'; break;
|
||||
case Keyboard::E: virtualKey = 'E'; break;
|
||||
case Keyboard::F: virtualKey = 'F'; break;
|
||||
case Keyboard::G: virtualKey = 'G'; break;
|
||||
case Keyboard::H: virtualKey = 'H'; break;
|
||||
case Keyboard::I: virtualKey = 'I'; break;
|
||||
case Keyboard::J: virtualKey = 'J'; break;
|
||||
case Keyboard::K: virtualKey = 'K'; break;
|
||||
case Keyboard::L: virtualKey = 'L'; break;
|
||||
case Keyboard::M: virtualKey = 'M'; break;
|
||||
case Keyboard::N: virtualKey = 'N'; break;
|
||||
case Keyboard::O: virtualKey = 'O'; break;
|
||||
case Keyboard::P: virtualKey = 'P'; break;
|
||||
case Keyboard::Q: virtualKey = 'Q'; break;
|
||||
case Keyboard::R: virtualKey = 'R'; break;
|
||||
case Keyboard::S: virtualKey = 'S'; break;
|
||||
case Keyboard::T: virtualKey = 'T'; break;
|
||||
case Keyboard::U: virtualKey = 'U'; break;
|
||||
case Keyboard::V: virtualKey = 'V'; break;
|
||||
case Keyboard::W: virtualKey = 'W'; break;
|
||||
case Keyboard::X: virtualKey = 'X'; break;
|
||||
case Keyboard::Y: virtualKey = 'Y'; break;
|
||||
case Keyboard::Z: virtualKey = 'Z'; break;
|
||||
case Keyboard::Num0: virtualKey = '0'; break;
|
||||
case Keyboard::Num1: virtualKey = '1'; break;
|
||||
case Keyboard::Num2: virtualKey = '2'; break;
|
||||
case Keyboard::Num3: virtualKey = '3'; break;
|
||||
case Keyboard::Num4: virtualKey = '4'; break;
|
||||
case Keyboard::Num5: virtualKey = '5'; break;
|
||||
case Keyboard::Num6: virtualKey = '6'; break;
|
||||
case Keyboard::Num7: virtualKey = '7'; break;
|
||||
case Keyboard::Num8: virtualKey = '8'; break;
|
||||
case Keyboard::Num9: virtualKey = '9'; break;
|
||||
case Keyboard::Escape: virtualKey = VK_ESCAPE; break;
|
||||
case Keyboard::LControl: virtualKey = VK_LCONTROL; break;
|
||||
case Keyboard::LShift: virtualKey = VK_LSHIFT; break;
|
||||
case Keyboard::LAlt: virtualKey = VK_LMENU; break;
|
||||
case Keyboard::LSystem: virtualKey = VK_LWIN; break;
|
||||
case Keyboard::RControl: virtualKey = VK_RCONTROL; break;
|
||||
case Keyboard::RShift: virtualKey = VK_RSHIFT; break;
|
||||
case Keyboard::RAlt: virtualKey = VK_RMENU; break;
|
||||
case Keyboard::RSystem: virtualKey = VK_RWIN; break;
|
||||
case Keyboard::Menu: virtualKey = VK_APPS; break;
|
||||
case Keyboard::LBracket: virtualKey = VK_OEM_4; break;
|
||||
case Keyboard::RBracket: virtualKey = VK_OEM_6; break;
|
||||
case Keyboard::Semicolon: virtualKey = VK_OEM_1; break;
|
||||
case Keyboard::Comma: virtualKey = VK_OEM_COMMA; break;
|
||||
case Keyboard::Period: virtualKey = VK_OEM_PERIOD; break;
|
||||
case Keyboard::Apostrophe: virtualKey = VK_OEM_7; break;
|
||||
case Keyboard::Slash: virtualKey = VK_OEM_2; break;
|
||||
case Keyboard::Backslash: virtualKey = VK_OEM_5; break;
|
||||
case Keyboard::Tilde: virtualKey = VK_OEM_3; break;
|
||||
case Keyboard::Equal: virtualKey = VK_OEM_PLUS; break;
|
||||
case Keyboard::Hyphen: virtualKey = VK_OEM_MINUS; break;
|
||||
case Keyboard::Space: virtualKey = VK_SPACE; break;
|
||||
case Keyboard::Enter: virtualKey = VK_RETURN; break;
|
||||
case Keyboard::Backspace: virtualKey = VK_BACK; break;
|
||||
case Keyboard::Tab: virtualKey = VK_TAB; break;
|
||||
case Keyboard::PageUp: virtualKey = VK_PRIOR; break;
|
||||
case Keyboard::PageDown: virtualKey = VK_NEXT; break;
|
||||
case Keyboard::End: virtualKey = VK_END; break;
|
||||
case Keyboard::Home: virtualKey = VK_HOME; break;
|
||||
case Keyboard::Insert: virtualKey = VK_INSERT; break;
|
||||
case Keyboard::Delete: virtualKey = VK_DELETE; break;
|
||||
case Keyboard::Add: virtualKey = VK_ADD; break;
|
||||
case Keyboard::Subtract: virtualKey = VK_SUBTRACT; break;
|
||||
case Keyboard::Multiply: virtualKey = VK_MULTIPLY; break;
|
||||
case Keyboard::Divide: virtualKey = VK_DIVIDE; break;
|
||||
case Keyboard::Left: virtualKey = VK_LEFT; break;
|
||||
case Keyboard::Right: virtualKey = VK_RIGHT; break;
|
||||
case Keyboard::Up: virtualKey = VK_UP; break;
|
||||
case Keyboard::Down: virtualKey = VK_DOWN; break;
|
||||
case Keyboard::Numpad0: virtualKey = VK_NUMPAD0; break;
|
||||
case Keyboard::Numpad1: virtualKey = VK_NUMPAD1; break;
|
||||
case Keyboard::Numpad2: virtualKey = VK_NUMPAD2; break;
|
||||
case Keyboard::Numpad3: virtualKey = VK_NUMPAD3; break;
|
||||
case Keyboard::Numpad4: virtualKey = VK_NUMPAD4; break;
|
||||
case Keyboard::Numpad5: virtualKey = VK_NUMPAD5; break;
|
||||
case Keyboard::Numpad6: virtualKey = VK_NUMPAD6; break;
|
||||
case Keyboard::Numpad7: virtualKey = VK_NUMPAD7; break;
|
||||
case Keyboard::Numpad8: virtualKey = VK_NUMPAD8; break;
|
||||
case Keyboard::Numpad9: virtualKey = VK_NUMPAD9; break;
|
||||
case Keyboard::F1: virtualKey = VK_F1; break;
|
||||
case Keyboard::F2: virtualKey = VK_F2; break;
|
||||
case Keyboard::F3: virtualKey = VK_F3; break;
|
||||
case Keyboard::F4: virtualKey = VK_F4; break;
|
||||
case Keyboard::F5: virtualKey = VK_F5; break;
|
||||
case Keyboard::F6: virtualKey = VK_F6; break;
|
||||
case Keyboard::F7: virtualKey = VK_F7; break;
|
||||
case Keyboard::F8: virtualKey = VK_F8; break;
|
||||
case Keyboard::F9: virtualKey = VK_F9; break;
|
||||
case Keyboard::F10: virtualKey = VK_F10; break;
|
||||
case Keyboard::F11: virtualKey = VK_F11; break;
|
||||
case Keyboard::F12: virtualKey = VK_F12; break;
|
||||
case Keyboard::F13: virtualKey = VK_F13; break;
|
||||
case Keyboard::F14: virtualKey = VK_F14; break;
|
||||
case Keyboard::F15: virtualKey = VK_F15; break;
|
||||
case Keyboard::Pause: virtualKey = VK_PAUSE; break;
|
||||
}
|
||||
return vkey;
|
||||
return virtualKey;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
WORD sfScanToWin(Keyboard::Scancode code)
|
||||
WORD sfScanToWinScan(Keyboard::Scancode code)
|
||||
{
|
||||
// Convert an SFML scancode to a windows scancode
|
||||
// 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::ScanA: return 0x1E;
|
||||
case Keyboard::ScanB: return 0x30;
|
||||
case Keyboard::ScanC: return 0x2E;
|
||||
case Keyboard::ScanD: return 0x20;
|
||||
case Keyboard::ScanE: return 0x12;
|
||||
case Keyboard::ScanF: return 0x21;
|
||||
case Keyboard::ScanG: return 0x22;
|
||||
case Keyboard::ScanH: return 0x23;
|
||||
case Keyboard::ScanI: return 0x17;
|
||||
case Keyboard::ScanJ: return 0x24;
|
||||
case Keyboard::ScanK: return 0x25;
|
||||
case Keyboard::ScanL: return 0x26;
|
||||
case Keyboard::ScanM: return 0x32;
|
||||
case Keyboard::ScanN: return 0x31;
|
||||
case Keyboard::ScanO: return 0x18;
|
||||
case Keyboard::ScanP: return 0x19;
|
||||
case Keyboard::ScanQ: return 0x10;
|
||||
case Keyboard::ScanR: return 0x13;
|
||||
case Keyboard::ScanS: return 0x1F;
|
||||
case Keyboard::ScanT: return 0x14;
|
||||
case Keyboard::ScanU: return 0x16;
|
||||
case Keyboard::ScanV: return 0x2F;
|
||||
case Keyboard::ScanW: return 0x11;
|
||||
case Keyboard::ScanX: return 0x2D;
|
||||
case Keyboard::ScanY: return 0x15;
|
||||
case Keyboard::ScanZ: return 0x2C;
|
||||
|
||||
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::ScanNum1: return 0x02;
|
||||
case Keyboard::ScanNum2: return 0x03;
|
||||
case Keyboard::ScanNum3: return 0x04;
|
||||
case Keyboard::ScanNum4: return 0x05;
|
||||
case Keyboard::ScanNum5: return 0x06;
|
||||
case Keyboard::ScanNum6: return 0x07;
|
||||
case Keyboard::ScanNum7: return 0x08;
|
||||
case Keyboard::ScanNum8: return 0x09;
|
||||
case Keyboard::ScanNum9: return 0x0A;
|
||||
case Keyboard::ScanNum0: return 0x0B;
|
||||
|
||||
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 0x1C;
|
||||
case Keyboard::ScanEscape: return 0x01;
|
||||
case Keyboard::ScanBackspace: return 0x0E;
|
||||
case Keyboard::ScanTab: return 0x0F;
|
||||
case Keyboard::ScanSpace: return 0x39;
|
||||
case Keyboard::ScanHyphen: return 0x0C;
|
||||
case Keyboard::ScanEqual: return 0x0D;
|
||||
case Keyboard::ScanLBracket: return 0x1A;
|
||||
case Keyboard::ScanRBracket: return 0x1B;
|
||||
case Keyboard::ScanBackslash: return 0x2B;
|
||||
case Keyboard::ScanSemicolon: return 0x27;
|
||||
case Keyboard::ScanApostrophe: return 0x28;
|
||||
case Keyboard::ScanGrave: return 0x29;
|
||||
case Keyboard::ScanComma: return 0x33;
|
||||
case Keyboard::ScanPeriod: return 0x34;
|
||||
case Keyboard::ScanSlash: return 0x35;
|
||||
|
||||
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::ScanF1: return 0x3B;
|
||||
case Keyboard::ScanF2: return 0x3C;
|
||||
case Keyboard::ScanF3: return 0x3D;
|
||||
case Keyboard::ScanF4: return 0x3E;
|
||||
case Keyboard::ScanF5: return 0x3F;
|
||||
case Keyboard::ScanF6: return 0x40;
|
||||
case Keyboard::ScanF7: return 0x41;
|
||||
case Keyboard::ScanF8: return 0x42;
|
||||
case Keyboard::ScanF9: return 0x43;
|
||||
case Keyboard::ScanF10: return 0x44;
|
||||
case Keyboard::ScanF11: return 0x57;
|
||||
case Keyboard::ScanF12: return 0x58;
|
||||
case Keyboard::ScanF13: return 0x64;
|
||||
case Keyboard::ScanF14: return 0x65;
|
||||
case Keyboard::ScanF15: return 0x66;
|
||||
case Keyboard::ScanF16: return 0x67;
|
||||
case Keyboard::ScanF17: return 0x68;
|
||||
case Keyboard::ScanF18: return 0x69;
|
||||
case Keyboard::ScanF19: return 0x6A;
|
||||
case Keyboard::ScanF20: return 0x6B;
|
||||
case Keyboard::ScanF21: return 0x6C;
|
||||
case Keyboard::ScanF22: return 0x6D;
|
||||
case Keyboard::ScanF23: return 0x6E;
|
||||
case Keyboard::ScanF24: return 0x76;
|
||||
|
||||
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::ScanCapsLock: return 0x3A;
|
||||
case Keyboard::ScanPrintScreen: return 0xE037;
|
||||
case Keyboard::ScanScrollLock: return 0x46;
|
||||
case Keyboard::ScanPause: return 0x45;
|
||||
case Keyboard::ScanInsert: return 0xE052;
|
||||
case Keyboard::ScanHome: return 0xE047;
|
||||
case Keyboard::ScanPageUp: return 0xE049;
|
||||
case Keyboard::ScanDelete: return 0xE053;
|
||||
case Keyboard::ScanEnd: return 0xE04F;
|
||||
case Keyboard::ScanPageDown: return 0xE051;
|
||||
case Keyboard::ScanRight: return 0xE04D;
|
||||
case Keyboard::ScanLeft: return 0xE04B;
|
||||
case Keyboard::ScanDown: return 0xE050;
|
||||
case Keyboard::ScanUp: return 0xE048;
|
||||
case Keyboard::ScanNumLock: return 0xE045;
|
||||
|
||||
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::ScanNumpadDivide: return 0xE035;
|
||||
case Keyboard::ScanNumpadMultiply: return 0x37;
|
||||
case Keyboard::ScanNumpadMinus: return 0xA4;
|
||||
case Keyboard::ScanNumpadPlus: return 0x4E;
|
||||
case Keyboard::ScanNumpadEqual: return 0x7E;
|
||||
case Keyboard::ScanNumpadEnter: return 0xE01C;
|
||||
case Keyboard::ScanNumpadDecimal: return 0x53;
|
||||
|
||||
//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 ? ? ? ;
|
||||
case Keyboard::ScanNumpad1: return 0x4F;
|
||||
case Keyboard::ScanNumpad2: return 0x50;
|
||||
case Keyboard::ScanNumpad3: return 0x51;
|
||||
case Keyboard::ScanNumpad4: return 0x4B;
|
||||
case Keyboard::ScanNumpad5: return 0x4C;
|
||||
case Keyboard::ScanNumpad6: return 0x4D;
|
||||
case Keyboard::ScanNumpad7: return 0x47;
|
||||
case Keyboard::ScanNumpad8: return 0x48;
|
||||
case Keyboard::ScanNumpad9: return 0x49;
|
||||
case Keyboard::ScanNumpad0: return 0x52;
|
||||
|
||||
default: return 0; // Not sure what to return here?
|
||||
case Keyboard::ScanNonUsBackslash: return 0x56;
|
||||
// No known scancode for Keyboard::ScanApplication
|
||||
// No known scancode for Keyboard::ScanExecute
|
||||
// No known scancode for Keyboard::ScanModeChange
|
||||
case Keyboard::ScanHelp: return 0xE061;
|
||||
case Keyboard::ScanMenu: return 0xE05D;
|
||||
case Keyboard::ScanSelect: return 0xE01E;
|
||||
// No known scancode for Keyboard::ScanRedo
|
||||
// No known scancode for Keyboard::ScanUndo
|
||||
// No known scancode for Keyboard::ScanCut
|
||||
// No known scancode for Keyboard::ScanCopy
|
||||
// No known scancode for Keyboard::ScanPaste
|
||||
|
||||
case Keyboard::ScanVolumeMute: return 0xE020;
|
||||
case Keyboard::ScanVolumeUp: return 0xE02E;
|
||||
case Keyboard::ScanVolumeDown: return 0xE02C;
|
||||
case Keyboard::ScanMediaPlayPause: return 0xE022;
|
||||
case Keyboard::ScanMediaStop: return 0xE024;
|
||||
case Keyboard::ScanMediaNextTrack: return 0xE019;
|
||||
case Keyboard::ScanMediaPreviousTrack: return 0xE010;
|
||||
|
||||
case Keyboard::ScanLControl: return 0x1D;
|
||||
case Keyboard::ScanLShift: return 0x2A;
|
||||
case Keyboard::ScanLAlt: return 0x38;
|
||||
case Keyboard::ScanLSystem: return 0xE05B;
|
||||
case Keyboard::ScanRControl: return 0xE01D;
|
||||
case Keyboard::ScanRShift: return 0x36;
|
||||
case Keyboard::ScanRAlt: return 0xE038;
|
||||
case Keyboard::ScanRSystem: return 0xE05C;
|
||||
|
||||
case Keyboard::ScanBack: return 0xE06A;
|
||||
case Keyboard::ScanForward: return 0xE069;
|
||||
case Keyboard::ScanRefresh: return 0xE067;
|
||||
case Keyboard::ScanStop: return 0xE068;
|
||||
case Keyboard::ScanSearch: return 0xE065;
|
||||
case Keyboard::ScanFavorites: return 0xE066;
|
||||
case Keyboard::ScanHomePage: return 0xE030;
|
||||
|
||||
case Keyboard::ScanLaunchApplication1: return 0xE06B;
|
||||
case Keyboard::ScanLaunchApplication2: return 0xE021;
|
||||
case Keyboard::ScanLaunchMail: return 0xE06C;
|
||||
case Keyboard::ScanLaunchMediaSelect: return 0xE06D;
|
||||
|
||||
// Unable to map to a scancode
|
||||
default: return 0x0;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
InputImpl::InputImpl()
|
||||
WORD sfScanToWinScanExtended(Keyboard::Scancode code)
|
||||
{
|
||||
buildMappings();
|
||||
// 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::ScanPrintScreen: return 55 | 0xE100;
|
||||
case Keyboard::ScanInsert: return 82 | 0xE100;
|
||||
case Keyboard::ScanHome: return 71 | 0xE100;
|
||||
case Keyboard::ScanPageUp: return 73 | 0xE100;
|
||||
case Keyboard::ScanDelete: return 83 | 0xE100;
|
||||
case Keyboard::ScanEnd: return 79 | 0xE100;
|
||||
case Keyboard::ScanPageDown: return 81 | 0xE100;
|
||||
case Keyboard::ScanRight: return 77 | 0xE100;
|
||||
case Keyboard::ScanLeft: return 75 | 0xE100;
|
||||
case Keyboard::ScanDown: return 80 | 0xE100;
|
||||
case Keyboard::ScanUp: return 72 | 0xE100;
|
||||
case Keyboard::ScanNumLock: return 69 | 0xE100;
|
||||
case Keyboard::ScanNumpadEnter: return 28 | 0xE100;
|
||||
case Keyboard::ScanHelp: return 97 | 0xE100;
|
||||
case Keyboard::ScanMenu: return 93 | 0xE100;
|
||||
case Keyboard::ScanSelect: return 30 | 0xE100;
|
||||
case Keyboard::ScanVolumeMute: return 32 | 0xE100;
|
||||
case Keyboard::ScanVolumeUp: return 46 | 0xE100;
|
||||
case Keyboard::ScanVolumeDown: return 44 | 0xE100;
|
||||
case Keyboard::ScanMediaPlayPause: return 34 | 0xE100;
|
||||
case Keyboard::ScanMediaStop: return 36 | 0xE100;
|
||||
case Keyboard::ScanMediaNextTrack: return 25 | 0xE100;
|
||||
case Keyboard::ScanMediaPreviousTrack: return 16 | 0xE100;
|
||||
case Keyboard::ScanLSystem: return 91 | 0xE100;
|
||||
case Keyboard::ScanRControl: return 29 | 0xE100;
|
||||
case Keyboard::ScanRAlt: return 56 | 0xE100;
|
||||
case Keyboard::ScanRSystem: return 92 | 0xE100;
|
||||
case Keyboard::ScanBack: return 106 | 0xE100;
|
||||
case Keyboard::ScanForward: return 105 | 0xE100;
|
||||
case Keyboard::ScanRefresh: return 103 | 0xE100;
|
||||
case Keyboard::ScanStop: return 104 | 0xE100;
|
||||
case Keyboard::ScanSearch: return 101 | 0xE100;
|
||||
case Keyboard::ScanFavorites: return 102 | 0xE100;
|
||||
case Keyboard::ScanHomePage: return 48 | 0xE100;
|
||||
case Keyboard::ScanLaunchApplication1: return 107 | 0xE100;
|
||||
case Keyboard::ScanLaunchApplication2: return 33 | 0xE100;
|
||||
case Keyboard::ScanLaunchMail: return 108 | 0xE100;
|
||||
case Keyboard::ScanLaunchMediaSelect: return 109 | 0xE100;
|
||||
|
||||
// Use non-extended mapping
|
||||
default: return sfScanToWinScan(code);
|
||||
}
|
||||
}
|
||||
|
||||
UINT sfScanToVirtualKey(Keyboard::Scancode code)
|
||||
{
|
||||
WORD winScancode = sfScanToWinScan(code);
|
||||
|
||||
// Manually map non-extended key codes
|
||||
switch (code)
|
||||
{
|
||||
case Keyboard::ScanNumpad0:
|
||||
return VK_NUMPAD0;
|
||||
case Keyboard::ScanNumpad1:
|
||||
return VK_NUMPAD1;
|
||||
case Keyboard::ScanNumpad2:
|
||||
return VK_NUMPAD2;
|
||||
case Keyboard::ScanNumpad3:
|
||||
return VK_NUMPAD3;
|
||||
case Keyboard::ScanNumpad4:
|
||||
return VK_NUMPAD4;
|
||||
case Keyboard::ScanNumpad5:
|
||||
return VK_NUMPAD5;
|
||||
case Keyboard::ScanNumpad6:
|
||||
return VK_NUMPAD6;
|
||||
case Keyboard::ScanNumpad7:
|
||||
return VK_NUMPAD7;
|
||||
case Keyboard::ScanNumpad8:
|
||||
return VK_NUMPAD8;
|
||||
case Keyboard::ScanNumpad9:
|
||||
return VK_NUMPAD9;
|
||||
case Keyboard::ScanNumpadMinus:
|
||||
return VK_SUBTRACT;
|
||||
case Keyboard::ScanNumpadDecimal:
|
||||
return VK_DECIMAL;
|
||||
case Keyboard::ScanNumpadDivide:
|
||||
return VK_DIVIDE;
|
||||
case Keyboard::ScanPause:
|
||||
return VK_PAUSE;
|
||||
case Keyboard::ScanRControl:
|
||||
return VK_RCONTROL;
|
||||
case Keyboard::ScanRAlt:
|
||||
return VK_RMENU;
|
||||
default:
|
||||
return MapVirtualKey(winScancode, MAPVK_VSC_TO_VK_EX);
|
||||
}
|
||||
}
|
||||
|
||||
bool isValidScancode(Keyboard::Scancode code)
|
||||
{
|
||||
return code > Keyboard::ScanUnknown && code < Keyboard::ScancodeCount;
|
||||
}
|
||||
|
||||
bool isValidKey(Keyboard::Key key)
|
||||
{
|
||||
return key > Keyboard::Unknown && key < Keyboard::KeyCount;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void InputImpl::buildMappings()
|
||||
void InputImpl::ensureMappings()
|
||||
{
|
||||
// Reset the mappings
|
||||
static bool isMappingInitialized = false;
|
||||
|
||||
if (isMappingInitialized)
|
||||
return;
|
||||
|
||||
// Phase 1: Initialize mappings with default values
|
||||
for (int i = 0; i < Keyboard::KeyCount; ++i)
|
||||
m_keyToScancodeMapping[i] = Keyboard::ScanUnknown;
|
||||
for (int i = 0; i < Keyboard::ScanCodeCount; ++i)
|
||||
|
||||
for (int i = 0; i < Keyboard::ScancodeCount; ++i)
|
||||
m_scancodeToKeyMapping[i] = Keyboard::Unknown;
|
||||
|
||||
for (int i = 0; i < Keyboard::ScanCodeCount; ++i)
|
||||
// Phase 2: Translate scancode to virtual code to key names
|
||||
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);
|
||||
UINT virtualKey = sfScanToVirtualKey(scan);
|
||||
Keyboard::Key key = virtualKeyToSfKey(virtualKey);
|
||||
m_keyToScancodeMapping[key] = scan;
|
||||
m_scancodeToKeyMapping[scan] = key;
|
||||
}
|
||||
|
||||
isMappingInitialized = true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool InputImpl::isKeyPressed(Keyboard::Key key)
|
||||
{
|
||||
int vkey = sfKeyToWin(key);
|
||||
return (GetAsyncKeyState(vkey) & 0x8000) != 0;
|
||||
int virtualKey = sfKeyToVirtualKey(key);
|
||||
return (GetAsyncKeyState(virtualKey) & 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;
|
||||
UINT virtualKey = sfScanToVirtualKey(code);
|
||||
return (GetAsyncKeyState(static_cast<int>(virtualKey)) & KF_UP) != 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Keyboard::Key InputImpl::localize(Keyboard::Scancode code)
|
||||
{
|
||||
if (!isValidScancode(code))
|
||||
return Keyboard::Unknown;
|
||||
|
||||
ensureMappings();
|
||||
|
||||
return m_scancodeToKeyMapping[code];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Keyboard::Scancode InputImpl::unlocalize(Keyboard::Key key)
|
||||
Keyboard::Scancode InputImpl::delocalize(Keyboard::Key key)
|
||||
{
|
||||
if (!isValidKey(key))
|
||||
return Keyboard::ScanUnknown;
|
||||
|
||||
ensureMappings();
|
||||
|
||||
return m_keyToScancodeMapping[key];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
String InputImpl::getDescription(Keyboard::Scancode code)
|
||||
{
|
||||
WORD winCode = sfScanToWin(code);
|
||||
WORD winCode = sfScanToWinScanExtended(code);
|
||||
const int bufSize(1024);
|
||||
WCHAR name[bufSize];
|
||||
int result = GetKeyNameText(winCode << 16, name, bufSize);
|
||||
@ -488,18 +632,18 @@ void InputImpl::setVirtualKeyboardVisible(bool /*visible*/)
|
||||
////////////////////////////////////////////////////////////
|
||||
bool InputImpl::isMouseButtonPressed(Mouse::Button button)
|
||||
{
|
||||
int vkey = 0;
|
||||
int virtualKey = 0;
|
||||
switch (button)
|
||||
{
|
||||
case Mouse::Left: vkey = GetSystemMetrics(SM_SWAPBUTTON) ? VK_RBUTTON : VK_LBUTTON; break;
|
||||
case Mouse::Right: vkey = GetSystemMetrics(SM_SWAPBUTTON) ? VK_LBUTTON : VK_RBUTTON; break;
|
||||
case Mouse::Middle: vkey = VK_MBUTTON; break;
|
||||
case Mouse::XButton1: vkey = VK_XBUTTON1; break;
|
||||
case Mouse::XButton2: vkey = VK_XBUTTON2; break;
|
||||
default: vkey = 0; break;
|
||||
case Mouse::Left: virtualKey = GetSystemMetrics(SM_SWAPBUTTON) ? VK_RBUTTON : VK_LBUTTON; break;
|
||||
case Mouse::Right: virtualKey = GetSystemMetrics(SM_SWAPBUTTON) ? VK_LBUTTON : VK_RBUTTON; break;
|
||||
case Mouse::Middle: virtualKey = VK_MBUTTON; break;
|
||||
case Mouse::XButton1: virtualKey = VK_XBUTTON1; break;
|
||||
case Mouse::XButton2: virtualKey = VK_XBUTTON2; break;
|
||||
default: virtualKey = 0; break;
|
||||
}
|
||||
|
||||
return (GetAsyncKeyState(vkey) & 0x8000) != 0;
|
||||
return (GetAsyncKeyState(virtualKey) & 0x8000) != 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -42,12 +42,6 @@ namespace priv
|
||||
class InputImpl
|
||||
{
|
||||
public:
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Default constructor
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
InputImpl();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \copydoc sf::Keyboard::isKeyPressed(Key)
|
||||
///
|
||||
@ -67,10 +61,10 @@ public:
|
||||
static Keyboard::Key localize(Keyboard::Scancode code);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \copydoc sf::Keyboard::unlocalize
|
||||
/// \copydoc sf::Keyboard::delocalize
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Keyboard::Scancode unlocalize(Keyboard::Key key);
|
||||
static Keyboard::Scancode delocalize(Keyboard::Key key);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \copydoc sf::Keyboard::getDescription
|
||||
@ -184,16 +178,16 @@ public:
|
||||
private:
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Regenerate the mappings from/to Key and Scancode.
|
||||
/// Ensure the mappings are generated from/to Key and Scancode.
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void buildMappings();
|
||||
static void ensureMappings();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// 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
|
||||
static Keyboard::Key m_scancodeToKeyMapping[Keyboard::ScancodeCount]; ///< Mapping from Scancode to Key
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
@ -47,6 +47,8 @@
|
||||
#include <dbt.h>
|
||||
#include <vector>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
// MinGW lacks the definition of some Win32 constants
|
||||
#ifndef XBUTTON1
|
||||
@ -566,11 +568,17 @@ void WindowImplWin32::grabCursor(bool grabbed)
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Keyboard::Scancode WindowImplWin32::toScancode(LPARAM flags)
|
||||
Keyboard::Scancode WindowImplWin32::toScancode(WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
int code = ((flags & (0xFF << 16)) >> 16);
|
||||
int code = (lParam & (0xFF << 16)) >> 16;
|
||||
|
||||
// Windows scan codes
|
||||
// Retrieve the scancode from the VirtualKey for synthetic key messages
|
||||
if (code == 0)
|
||||
{
|
||||
code = static_cast<int>(MapVirtualKey(static_cast<UINT>(wParam), MAPVK_VK_TO_VSC));
|
||||
}
|
||||
|
||||
// Windows scancodes
|
||||
// Reference: https://msdn.microsoft.com/en-us/library/aa299374(v=vs.60).aspx
|
||||
switch (code)
|
||||
{
|
||||
@ -586,10 +594,10 @@ Keyboard::Scancode WindowImplWin32::toScancode(LPARAM flags)
|
||||
case 10: return Keyboard::ScanNum9;
|
||||
case 11: return Keyboard::ScanNum0;
|
||||
case 12: return Keyboard::ScanHyphen;
|
||||
case 13: return Keyboard::ScanEquals;
|
||||
case 13: return Keyboard::ScanEqual;
|
||||
case 14: return Keyboard::ScanBackspace;
|
||||
case 15: return Keyboard::ScanTab;
|
||||
case 16: return Keyboard::ScanQ;
|
||||
case 16: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanMediaPreviousTrack : Keyboard::ScanQ;
|
||||
case 17: return Keyboard::ScanW;
|
||||
case 18: return Keyboard::ScanE;
|
||||
case 19: return Keyboard::ScanR;
|
||||
@ -598,38 +606,38 @@ Keyboard::Scancode WindowImplWin32::toScancode(LPARAM flags)
|
||||
case 22: return Keyboard::ScanU;
|
||||
case 23: return Keyboard::ScanI;
|
||||
case 24: return Keyboard::ScanO;
|
||||
case 25: return Keyboard::ScanP;
|
||||
case 25: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanMediaNextTrack : 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 28: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanNumpadEnter : Keyboard::ScanEnter;
|
||||
case 29: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanRControl : Keyboard::ScanLControl;
|
||||
case 30: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanSelect : Keyboard::ScanA;
|
||||
case 31: return Keyboard::ScanS;
|
||||
case 32: return Keyboard::ScanD;
|
||||
case 33: return Keyboard::ScanF;
|
||||
case 34: return Keyboard::ScanG;
|
||||
case 32: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanVolumeMute : Keyboard::ScanD;
|
||||
case 33: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanLaunchApplication1 : Keyboard::ScanF;
|
||||
case 34: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanMediaPlayPause : Keyboard::ScanG;
|
||||
case 35: return Keyboard::ScanH;
|
||||
case 36: return Keyboard::ScanJ;
|
||||
case 36: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanMediaStop : 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 40: return Keyboard::ScanApostrophe;
|
||||
case 41: return Keyboard::ScanGrave;
|
||||
case 42: return Keyboard::ScanLShift;
|
||||
case 43: return Keyboard::ScanDash;
|
||||
case 43: return Keyboard::ScanBackslash;
|
||||
case 44: return Keyboard::ScanZ;
|
||||
case 45: return Keyboard::ScanX;
|
||||
case 46: return Keyboard::ScanC;
|
||||
case 46: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanVolumeDown : Keyboard::ScanC;
|
||||
case 47: return Keyboard::ScanV;
|
||||
case 48: return Keyboard::ScanB;
|
||||
case 48: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanVolumeUp : Keyboard::ScanB;
|
||||
case 49: return Keyboard::ScanN;
|
||||
case 50: return Keyboard::ScanM;
|
||||
case 50: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanHomePage : Keyboard::ScanM;
|
||||
case 51: return Keyboard::ScanComma;
|
||||
case 52: return Keyboard::ScanPeriod;
|
||||
case 53: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::ScanDivide : Keyboard::ScanSlash;
|
||||
case 53: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanNumpadDivide : 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 55: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanPrintScreen : Keyboard::ScanNumpadMultiply;
|
||||
case 56: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanRAlt : Keyboard::ScanLAlt;
|
||||
case 57: return Keyboard::ScanSpace;
|
||||
case 58: return Keyboard::ScanCapsLock;
|
||||
case 59: return Keyboard::ScanF1;
|
||||
@ -642,26 +650,44 @@ Keyboard::Scancode WindowImplWin32::toScancode(LPARAM flags)
|
||||
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 69: return (HIWORD(lParam) & 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 71: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanHome : Keyboard::ScanNumpad7;
|
||||
case 72: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanUp : Keyboard::ScanNumpad8;
|
||||
case 73: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanPageUp : Keyboard::ScanNumpad9;
|
||||
case 74: return Keyboard::ScanNumpadMinus;
|
||||
case 75: return (HIWORD(lParam) & 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 77: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanRight : Keyboard::ScanNumpad6;
|
||||
case 78: return Keyboard::ScanNumpadPlus;
|
||||
case 79: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanEnd : Keyboard::ScanNumpad1;
|
||||
case 80: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanDown : Keyboard::ScanNumpad2;
|
||||
case 81: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanPageDown : Keyboard::ScanNumpad3;
|
||||
case 82: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanInsert : Keyboard::ScanNumpad0;
|
||||
case 83: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanDelete : Keyboard::ScanNumpadDecimal;
|
||||
|
||||
case 91: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::ScanLSystem : Keyboard::ScanUnknown;
|
||||
case 93: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::ScanMenu : Keyboard::ScanUnknown;
|
||||
case 86: return Keyboard::ScanNonUsBackslash;
|
||||
case 87: return Keyboard::ScanF11;
|
||||
case 88: return Keyboard::ScanF12;
|
||||
|
||||
case 91: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanLSystem : Keyboard::ScanUnknown;
|
||||
case 92: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanRSystem : Keyboard::ScanUnknown;
|
||||
case 93: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanMenu : Keyboard::ScanUnknown;
|
||||
|
||||
case 99: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanHelp : Keyboard::ScanUnknown;
|
||||
case 100: return Keyboard::ScanF13;
|
||||
case 101: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanSearch : Keyboard::ScanF14;
|
||||
case 102: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanFavorites : Keyboard::ScanF15;
|
||||
case 103: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanRefresh : Keyboard::ScanF16;
|
||||
case 104: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanStop : Keyboard::ScanF17;
|
||||
case 105: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanForward : Keyboard::ScanF18;
|
||||
case 106: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanBack : Keyboard::ScanF19;
|
||||
case 107: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanLaunchApplication1 : Keyboard::ScanF20;
|
||||
case 108: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanLaunchMail : Keyboard::ScanF21;
|
||||
case 109: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::ScanLaunchMediaSelect : Keyboard::ScanF22;
|
||||
case 110: return Keyboard::ScanF23;
|
||||
|
||||
case 118: return Keyboard::ScanF24;
|
||||
|
||||
default: return Keyboard::ScanUnknown;
|
||||
}
|
||||
@ -835,12 +861,13 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
|
||||
if (m_keyRepeatEnabled || ((HIWORD(lParam) & KF_REPEAT) == 0))
|
||||
{
|
||||
Event event;
|
||||
event.type = Event::KeyPressed;
|
||||
event.key.alt = HIWORD(GetKeyState(VK_MENU)) != 0;
|
||||
event.key.control = HIWORD(GetKeyState(VK_CONTROL)) != 0;
|
||||
event.key.shift = HIWORD(GetKeyState(VK_SHIFT)) != 0;
|
||||
event.key.system = HIWORD(GetKeyState(VK_LWIN)) || HIWORD(GetKeyState(VK_RWIN));
|
||||
event.key.code = virtualKeyCodeToSF(wParam, lParam);
|
||||
event.type = Event::KeyPressed;
|
||||
event.key.alt = HIWORD(GetKeyState(VK_MENU)) != 0;
|
||||
event.key.control = HIWORD(GetKeyState(VK_CONTROL)) != 0;
|
||||
event.key.shift = HIWORD(GetKeyState(VK_SHIFT)) != 0;
|
||||
event.key.system = HIWORD(GetKeyState(VK_LWIN)) || HIWORD(GetKeyState(VK_RWIN));
|
||||
event.key.code = virtualKeyCodeToSF(wParam, lParam);
|
||||
event.key.scancode = toScancode(wParam, lParam);
|
||||
pushEvent(event);
|
||||
}
|
||||
break;
|
||||
@ -851,12 +878,13 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
|
||||
case WM_SYSKEYUP:
|
||||
{
|
||||
Event event;
|
||||
event.type = Event::KeyReleased;
|
||||
event.key.alt = HIWORD(GetKeyState(VK_MENU)) != 0;
|
||||
event.key.control = HIWORD(GetKeyState(VK_CONTROL)) != 0;
|
||||
event.key.shift = HIWORD(GetKeyState(VK_SHIFT)) != 0;
|
||||
event.key.system = HIWORD(GetKeyState(VK_LWIN)) || HIWORD(GetKeyState(VK_RWIN));
|
||||
event.key.code = virtualKeyCodeToSF(wParam, lParam);
|
||||
event.type = Event::KeyReleased;
|
||||
event.key.alt = HIWORD(GetKeyState(VK_MENU)) != 0;
|
||||
event.key.control = HIWORD(GetKeyState(VK_CONTROL)) != 0;
|
||||
event.key.shift = HIWORD(GetKeyState(VK_SHIFT)) != 0;
|
||||
event.key.system = HIWORD(GetKeyState(VK_LWIN)) || HIWORD(GetKeyState(VK_RWIN));
|
||||
event.key.code = virtualKeyCodeToSF(wParam, lParam);
|
||||
event.key.scancode = toScancode(wParam, lParam);
|
||||
pushEvent(event);
|
||||
break;
|
||||
}
|
||||
@ -1139,7 +1167,7 @@ Keyboard::Key WindowImplWin32::virtualKeyCodeToSF(WPARAM key, LPARAM flags)
|
||||
case VK_OEM_6: return Keyboard::RBracket;
|
||||
case VK_OEM_COMMA: return Keyboard::Comma;
|
||||
case VK_OEM_PERIOD: return Keyboard::Period;
|
||||
case VK_OEM_7: return Keyboard::Quote;
|
||||
case VK_OEM_7: return Keyboard::Apostrophe;
|
||||
case VK_OEM_5: return Keyboard::Backslash;
|
||||
case VK_OEM_3: return Keyboard::Tilde;
|
||||
case VK_ESCAPE: return Keyboard::Escape;
|
||||
|
@ -277,7 +277,7 @@ private:
|
||||
/// \return SFML scancode corresponding to the key
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Keyboard::Scancode toScancode(LPARAM flags);
|
||||
static Keyboard::Scancode toScancode(WPARAM wParam, LPARAM lParam);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Member data
|
||||
|
@ -63,13 +63,13 @@ public:
|
||||
static Keyboard::Key localize(Keyboard::Scancode code);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \copydoc sf::Keyboard::unlocalize
|
||||
/// \copydoc sf::Keyboard::delocalize
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static Keyboard::Scancode unlocalize(Keyboard::Key key);
|
||||
static Keyboard::Scancode delocalize(Keyboard::Key key);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \copydoc sf::Keyboard::localizedRepresentation
|
||||
/// \copydoc sf::Keyboard::getDescription
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static String getDescription(Keyboard::Scancode code);
|
||||
|
@ -43,6 +43,29 @@ bool InputImpl::isKeyPressed(Keyboard::Key /* key */)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InputImpl::isKeyPressed(Keyboard::Scancode /* codes */)
|
||||
{
|
||||
// Not applicable
|
||||
return false;
|
||||
}
|
||||
|
||||
Keyboard::Key InputImpl::localize(Keyboard::Scancode /* code */)
|
||||
{
|
||||
// Not applicable
|
||||
return Keyboard::Unknown;
|
||||
}
|
||||
|
||||
Keyboard::Scancode InputImpl::delocalize(Keyboard::Key /* key */)
|
||||
{
|
||||
// Not applicable
|
||||
return Keyboard::ScanUnknown;
|
||||
}
|
||||
|
||||
String InputImpl::getDescription(Keyboard::Scancode /* code */)
|
||||
{
|
||||
// Not applicable
|
||||
return "";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void InputImpl::setVirtualKeyboardVisible(bool visible)
|
||||
|
Loading…
Reference in New Issue
Block a user