Convert scancodes into a scoped enumeration
This commit is contained in:
parent
17a8e9e2c2
commit
9f08d67dcc
@ -164,183 +164,166 @@ enum Key
|
|||||||
/// keyboard can be used as reference for the physical position of the keys.
|
/// keyboard can be used as reference for the physical position of the keys.
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
struct Scan
|
enum class Scan
|
||||||
{
|
{
|
||||||
// TODO: replace with enum class in SFML 3.
|
Unknown = -1, //!< Represents any scancode not present in this enum
|
||||||
// Clang warns us rightfully that Scancode names shadow Key names.
|
A = 0, //!< Keyboard a and A key
|
||||||
// A safer solution would be to use a C++11 scoped enumeration (enum class),
|
B, //!< Keyboard b and B key
|
||||||
// but it is not possible in SFML 2 which uses C++03.
|
C, //!< Keyboard c and C key
|
||||||
// For now, we just ignore those warnings.
|
D, //!< Keyboard d and D key
|
||||||
#if defined(__clang__)
|
E, //!< Keyboard e and E key
|
||||||
#pragma clang diagnostic push
|
F, //!< Keyboard f and F key
|
||||||
#pragma clang diagnostic ignored "-Wshadow"
|
G, //!< Keyboard g and G key
|
||||||
#endif
|
H, //!< Keyboard h and H key
|
||||||
|
I, //!< Keyboard i and I key
|
||||||
|
J, //!< Keyboard j and J key
|
||||||
|
K, //!< Keyboard k and K key
|
||||||
|
L, //!< Keyboard l and L key
|
||||||
|
M, //!< Keyboard m and M key
|
||||||
|
N, //!< Keyboard n and N key
|
||||||
|
O, //!< Keyboard o and O key
|
||||||
|
P, //!< Keyboard p and P key
|
||||||
|
Q, //!< Keyboard q and Q key
|
||||||
|
R, //!< Keyboard r and R key
|
||||||
|
S, //!< Keyboard s and S key
|
||||||
|
T, //!< Keyboard t and T key
|
||||||
|
U, //!< Keyboard u and U key
|
||||||
|
V, //!< Keyboard v and V key
|
||||||
|
W, //!< Keyboard w and W key
|
||||||
|
X, //!< Keyboard x and X key
|
||||||
|
Y, //!< Keyboard y and Y key
|
||||||
|
Z, //!< Keyboard z and Z key
|
||||||
|
Num1, //!< Keyboard 1 and ! key
|
||||||
|
Num2, //!< Keyboard 2 and @ key
|
||||||
|
Num3, //!< Keyboard 3 and # key
|
||||||
|
Num4, //!< Keyboard 4 and $ key
|
||||||
|
Num5, //!< Keyboard 5 and % key
|
||||||
|
Num6, //!< Keyboard 6 and ^ key
|
||||||
|
Num7, //!< Keyboard 7 and & key
|
||||||
|
Num8, //!< Keyboard 8 and * key
|
||||||
|
Num9, //!< Keyboard 9 and ) key
|
||||||
|
Num0, //!< Keyboard 0 and ) key
|
||||||
|
Enter, //!< Keyboard Enter/Return key
|
||||||
|
Escape, //!< Keyboard Escape key
|
||||||
|
Backspace, //!< Keyboard Backspace key
|
||||||
|
Tab, //!< Keyboard Tab key
|
||||||
|
Space, //!< Keyboard Space key
|
||||||
|
Hyphen, //!< Keyboard - and _ key
|
||||||
|
Equal, //!< Keyboard = and +
|
||||||
|
LBracket, //!< Keyboard [ and { key
|
||||||
|
RBracket, //!< 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:}]
|
||||||
|
Backslash, //!< Keyboard \ and | key OR various keys for Non-US keyboards
|
||||||
|
Semicolon, //!< Keyboard ; and : key
|
||||||
|
Apostrophe, //!< Keyboard ' and " key
|
||||||
|
Grave, //!< Keyboard ` and ~ key
|
||||||
|
Comma, //!< Keyboard , and < key
|
||||||
|
Period, //!< Keyboard . and > key
|
||||||
|
Slash, //!< Keyboard / and ? key
|
||||||
|
F1, //!< Keyboard F1 key
|
||||||
|
F2, //!< Keyboard F2 key
|
||||||
|
F3, //!< Keyboard F3 key
|
||||||
|
F4, //!< Keyboard F4 key
|
||||||
|
F5, //!< Keyboard F5 key
|
||||||
|
F6, //!< Keyboard F6 key
|
||||||
|
F7, //!< Keyboard F7 key
|
||||||
|
F8, //!< Keyboard F8 key
|
||||||
|
F9, //!< Keyboard F9 key
|
||||||
|
F10, //!< Keyboard F10 key
|
||||||
|
F11, //!< Keyboard F11 key
|
||||||
|
F12, //!< Keyboard F12 key
|
||||||
|
F13, //!< Keyboard F13 key
|
||||||
|
F14, //!< Keyboard F14 key
|
||||||
|
F15, //!< Keyboard F15 key
|
||||||
|
F16, //!< Keyboard F16 key
|
||||||
|
F17, //!< Keyboard F17 key
|
||||||
|
F18, //!< Keyboard F18 key
|
||||||
|
F19, //!< Keyboard F19 key
|
||||||
|
F20, //!< Keyboard F20 key
|
||||||
|
F21, //!< Keyboard F21 key
|
||||||
|
F22, //!< Keyboard F22 key
|
||||||
|
F23, //!< Keyboard F23 key
|
||||||
|
F24, //!< Keyboard F24 key
|
||||||
|
CapsLock, //!< Keyboard Caps %Lock key
|
||||||
|
PrintScreen, //!< Keyboard Print Screen key
|
||||||
|
ScrollLock, //!< Keyboard Scroll %Lock key
|
||||||
|
Pause, //!< Keyboard Pause key
|
||||||
|
Insert, //!< Keyboard Insert key
|
||||||
|
Home, //!< Keyboard Home key
|
||||||
|
PageUp, //!< Keyboard Page Up key
|
||||||
|
Delete, //!< Keyboard Delete Forward key
|
||||||
|
End, //!< Keyboard End key
|
||||||
|
PageDown, //!< Keyboard Page Down key
|
||||||
|
Right, //!< Keyboard Right Arrow key
|
||||||
|
Left, //!< Keyboard Left Arrow key
|
||||||
|
Down, //!< Keyboard Down Arrow key
|
||||||
|
Up, //!< Keyboard Up Arrow key
|
||||||
|
NumLock, //!< Keypad Num %Lock and Clear key
|
||||||
|
NumpadDivide, //!< Keypad / key
|
||||||
|
NumpadMultiply, //!< Keypad * key
|
||||||
|
NumpadMinus, //!< Keypad - key
|
||||||
|
NumpadPlus, //!< Keypad + key
|
||||||
|
NumpadEqual, //!< keypad = key
|
||||||
|
NumpadEnter, //!< Keypad Enter/Return key
|
||||||
|
NumpadDecimal, //!< Keypad . and Delete key
|
||||||
|
Numpad1, //!< Keypad 1 and End key
|
||||||
|
Numpad2, //!< Keypad 2 and Down Arrow key
|
||||||
|
Numpad3, //!< Keypad 3 and Page Down key
|
||||||
|
Numpad4, //!< Keypad 4 and Left Arrow key
|
||||||
|
Numpad5, //!< Keypad 5 key
|
||||||
|
Numpad6, //!< Keypad 6 and Right Arrow key
|
||||||
|
Numpad7, //!< Keypad 7 and Home key
|
||||||
|
Numpad8, //!< Keypad 8 and Up Arrow key
|
||||||
|
Numpad9, //!< Keypad 9 and Page Up key
|
||||||
|
Numpad0, //!< 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: \|.
|
||||||
|
NonUsBackslash, //!< Keyboard Non-US \ and | key
|
||||||
|
Application, //!< Keyboard Application key
|
||||||
|
Execute, //!< Keyboard Execute key
|
||||||
|
ModeChange, //!< Keyboard Mode Change key
|
||||||
|
Help, //!< Keyboard Help key
|
||||||
|
Menu, //!< Keyboard Menu key
|
||||||
|
Select, //!< Keyboard Select key
|
||||||
|
Redo, //!< Keyboard Redo key
|
||||||
|
Undo, //!< Keyboard Undo key
|
||||||
|
Cut, //!< Keyboard Cut key
|
||||||
|
Copy, //!< Keyboard Copy key
|
||||||
|
Paste, //!< Keyboard Paste key
|
||||||
|
VolumeMute, //!< Keyboard Volume Mute key
|
||||||
|
VolumeUp, //!< Keyboard Volume Up key
|
||||||
|
VolumeDown, //!< Keyboard Volume Down key
|
||||||
|
MediaPlayPause, //!< Keyboard Media Play Pause key
|
||||||
|
MediaStop, //!< Keyboard Media Stop key
|
||||||
|
MediaNextTrack, //!< Keyboard Media Next Track key
|
||||||
|
MediaPreviousTrack, //!< Keyboard Media Previous Track key
|
||||||
|
LControl, //!< Keyboard Left Control key
|
||||||
|
LShift, //!< Keyboard Left Shift key
|
||||||
|
LAlt, //!< Keyboard Left Alt key
|
||||||
|
LSystem, //!< Keyboard Left System key
|
||||||
|
RControl, //!< Keyboard Right Control key
|
||||||
|
RShift, //!< Keyboard Right Shift key
|
||||||
|
RAlt, //!< Keyboard Right Alt key
|
||||||
|
RSystem, //!< Keyboard Right System key
|
||||||
|
Back, //!< Keyboard Back key
|
||||||
|
Forward, //!< Keyboard Forward key
|
||||||
|
Refresh, //!< Keyboard Refresh key
|
||||||
|
Stop, //!< Keyboard Stop key
|
||||||
|
Search, //!< Keyboard Search key
|
||||||
|
Favorites, //!< Keyboard Favorites key
|
||||||
|
HomePage, //!< Keyboard Home Page key
|
||||||
|
LaunchApplication1, //!< Keyboard Launch Application 1 key
|
||||||
|
LaunchApplication2, //!< Keyboard Launch Application 2 key
|
||||||
|
LaunchMail, //!< Keyboard Launch Mail key
|
||||||
|
LaunchMediaSelect, //!< Keyboard Launch Media Select key
|
||||||
|
|
||||||
enum Scancode
|
ScancodeCount //!< Keep last -- the total number of scancodes
|
||||||
{
|
|
||||||
Unknown = -1, //!< Represents any scancode not present in this enum
|
|
||||||
A = 0, //!< Keyboard a and A key
|
|
||||||
B, //!< Keyboard b and B key
|
|
||||||
C, //!< Keyboard c and C key
|
|
||||||
D, //!< Keyboard d and D key
|
|
||||||
E, //!< Keyboard e and E key
|
|
||||||
F, //!< Keyboard f and F key
|
|
||||||
G, //!< Keyboard g and G key
|
|
||||||
H, //!< Keyboard h and H key
|
|
||||||
I, //!< Keyboard i and I key
|
|
||||||
J, //!< Keyboard j and J key
|
|
||||||
K, //!< Keyboard k and K key
|
|
||||||
L, //!< Keyboard l and L key
|
|
||||||
M, //!< Keyboard m and M key
|
|
||||||
N, //!< Keyboard n and N key
|
|
||||||
O, //!< Keyboard o and O key
|
|
||||||
P, //!< Keyboard p and P key
|
|
||||||
Q, //!< Keyboard q and Q key
|
|
||||||
R, //!< Keyboard r and R key
|
|
||||||
S, //!< Keyboard s and S key
|
|
||||||
T, //!< Keyboard t and T key
|
|
||||||
U, //!< Keyboard u and U key
|
|
||||||
V, //!< Keyboard v and V key
|
|
||||||
W, //!< Keyboard w and W key
|
|
||||||
X, //!< Keyboard x and X key
|
|
||||||
Y, //!< Keyboard y and Y key
|
|
||||||
Z, //!< Keyboard z and Z key
|
|
||||||
Num1, //!< Keyboard 1 and ! key
|
|
||||||
Num2, //!< Keyboard 2 and @ key
|
|
||||||
Num3, //!< Keyboard 3 and # key
|
|
||||||
Num4, //!< Keyboard 4 and $ key
|
|
||||||
Num5, //!< Keyboard 5 and % key
|
|
||||||
Num6, //!< Keyboard 6 and ^ key
|
|
||||||
Num7, //!< Keyboard 7 and & key
|
|
||||||
Num8, //!< Keyboard 8 and * key
|
|
||||||
Num9, //!< Keyboard 9 and ) key
|
|
||||||
Num0, //!< Keyboard 0 and ) key
|
|
||||||
Enter, //!< Keyboard Enter/Return key
|
|
||||||
Escape, //!< Keyboard Escape key
|
|
||||||
Backspace, //!< Keyboard Backspace key
|
|
||||||
Tab, //!< Keyboard Tab key
|
|
||||||
Space, //!< Keyboard Space key
|
|
||||||
Hyphen, //!< Keyboard - and _ key
|
|
||||||
Equal, //!< Keyboard = and +
|
|
||||||
LBracket, //!< Keyboard [ and { key
|
|
||||||
RBracket, //!< 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:}]
|
|
||||||
Backslash, //!< Keyboard \ and | key OR various keys for Non-US keyboards
|
|
||||||
Semicolon, //!< Keyboard ; and : key
|
|
||||||
Apostrophe, //!< Keyboard ' and " key
|
|
||||||
Grave, //!< Keyboard ` and ~ key
|
|
||||||
Comma, //!< Keyboard , and < key
|
|
||||||
Period, //!< Keyboard . and > key
|
|
||||||
Slash, //!< Keyboard / and ? key
|
|
||||||
F1, //!< Keyboard F1 key
|
|
||||||
F2, //!< Keyboard F2 key
|
|
||||||
F3, //!< Keyboard F3 key
|
|
||||||
F4, //!< Keyboard F4 key
|
|
||||||
F5, //!< Keyboard F5 key
|
|
||||||
F6, //!< Keyboard F6 key
|
|
||||||
F7, //!< Keyboard F7 key
|
|
||||||
F8, //!< Keyboard F8 key
|
|
||||||
F9, //!< Keyboard F9 key
|
|
||||||
F10, //!< Keyboard F10 key
|
|
||||||
F11, //!< Keyboard F11 key
|
|
||||||
F12, //!< Keyboard F12 key
|
|
||||||
F13, //!< Keyboard F13 key
|
|
||||||
F14, //!< Keyboard F14 key
|
|
||||||
F15, //!< Keyboard F15 key
|
|
||||||
F16, //!< Keyboard F16 key
|
|
||||||
F17, //!< Keyboard F17 key
|
|
||||||
F18, //!< Keyboard F18 key
|
|
||||||
F19, //!< Keyboard F19 key
|
|
||||||
F20, //!< Keyboard F20 key
|
|
||||||
F21, //!< Keyboard F21 key
|
|
||||||
F22, //!< Keyboard F22 key
|
|
||||||
F23, //!< Keyboard F23 key
|
|
||||||
F24, //!< Keyboard F24 key
|
|
||||||
CapsLock, //!< Keyboard Caps %Lock key
|
|
||||||
PrintScreen, //!< Keyboard Print Screen key
|
|
||||||
ScrollLock, //!< Keyboard Scroll %Lock key
|
|
||||||
Pause, //!< Keyboard Pause key
|
|
||||||
Insert, //!< Keyboard Insert key
|
|
||||||
Home, //!< Keyboard Home key
|
|
||||||
PageUp, //!< Keyboard Page Up key
|
|
||||||
Delete, //!< Keyboard Delete Forward key
|
|
||||||
End, //!< Keyboard End key
|
|
||||||
PageDown, //!< Keyboard Page Down key
|
|
||||||
Right, //!< Keyboard Right Arrow key
|
|
||||||
Left, //!< Keyboard Left Arrow key
|
|
||||||
Down, //!< Keyboard Down Arrow key
|
|
||||||
Up, //!< Keyboard Up Arrow key
|
|
||||||
NumLock, //!< Keypad Num %Lock and Clear key
|
|
||||||
NumpadDivide, //!< Keypad / key
|
|
||||||
NumpadMultiply, //!< Keypad * key
|
|
||||||
NumpadMinus, //!< Keypad - key
|
|
||||||
NumpadPlus, //!< Keypad + key
|
|
||||||
NumpadEqual, //!< keypad = key
|
|
||||||
NumpadEnter, //!< Keypad Enter/Return key
|
|
||||||
NumpadDecimal, //!< Keypad . and Delete key
|
|
||||||
Numpad1, //!< Keypad 1 and End key
|
|
||||||
Numpad2, //!< Keypad 2 and Down Arrow key
|
|
||||||
Numpad3, //!< Keypad 3 and Page Down key
|
|
||||||
Numpad4, //!< Keypad 4 and Left Arrow key
|
|
||||||
Numpad5, //!< Keypad 5 key
|
|
||||||
Numpad6, //!< Keypad 6 and Right Arrow key
|
|
||||||
Numpad7, //!< Keypad 7 and Home key
|
|
||||||
Numpad8, //!< Keypad 8 and Up Arrow key
|
|
||||||
Numpad9, //!< Keypad 9 and Page Up key
|
|
||||||
Numpad0, //!< 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: \|.
|
|
||||||
NonUsBackslash, //!< Keyboard Non-US \ and | key
|
|
||||||
Application, //!< Keyboard Application key
|
|
||||||
Execute, //!< Keyboard Execute key
|
|
||||||
ModeChange, //!< Keyboard Mode Change key
|
|
||||||
Help, //!< Keyboard Help key
|
|
||||||
Menu, //!< Keyboard Menu key
|
|
||||||
Select, //!< Keyboard Select key
|
|
||||||
Redo, //!< Keyboard Redo key
|
|
||||||
Undo, //!< Keyboard Undo key
|
|
||||||
Cut, //!< Keyboard Cut key
|
|
||||||
Copy, //!< Keyboard Copy key
|
|
||||||
Paste, //!< Keyboard Paste key
|
|
||||||
VolumeMute, //!< Keyboard Volume Mute key
|
|
||||||
VolumeUp, //!< Keyboard Volume Up key
|
|
||||||
VolumeDown, //!< Keyboard Volume Down key
|
|
||||||
MediaPlayPause, //!< Keyboard Media Play Pause key
|
|
||||||
MediaStop, //!< Keyboard Media Stop key
|
|
||||||
MediaNextTrack, //!< Keyboard Media Next Track key
|
|
||||||
MediaPreviousTrack, //!< Keyboard Media Previous Track key
|
|
||||||
LControl, //!< Keyboard Left Control key
|
|
||||||
LShift, //!< Keyboard Left Shift key
|
|
||||||
LAlt, //!< Keyboard Left Alt key
|
|
||||||
LSystem, //!< Keyboard Left System key
|
|
||||||
RControl, //!< Keyboard Right Control key
|
|
||||||
RShift, //!< Keyboard Right Shift key
|
|
||||||
RAlt, //!< Keyboard Right Alt key
|
|
||||||
RSystem, //!< Keyboard Right System key
|
|
||||||
Back, //!< Keyboard Back key
|
|
||||||
Forward, //!< Keyboard Forward key
|
|
||||||
Refresh, //!< Keyboard Refresh key
|
|
||||||
Stop, //!< Keyboard Stop key
|
|
||||||
Search, //!< Keyboard Search key
|
|
||||||
Favorites, //!< Keyboard Favorites key
|
|
||||||
HomePage, //!< Keyboard Home Page key
|
|
||||||
LaunchApplication1, //!< Keyboard Launch Application 1 key
|
|
||||||
LaunchApplication2, //!< Keyboard Launch Application 2 key
|
|
||||||
LaunchMail, //!< Keyboard Launch Mail key
|
|
||||||
LaunchMediaSelect, //!< Keyboard Launch Media Select key
|
|
||||||
|
|
||||||
ScancodeCount //!< Keep last -- the total number of scancodes
|
|
||||||
};
|
|
||||||
|
|
||||||
#if defined(__clang__)
|
|
||||||
#pragma clang diagnostic pop
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
using Scancode = Scan::Scancode;
|
using Scancode = Scan;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Check if a key is pressed
|
/// \brief Check if a key is pressed
|
||||||
|
@ -285,10 +285,10 @@ private:
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
IOHIDManagerRef m_manager{}; ///< Underlying HID Manager
|
IOHIDManagerRef m_manager{}; ///< Underlying HID Manager
|
||||||
IOHIDElements m_keys[Keyboard::Scan::ScancodeCount]; ///< All the keys on any connected keyboard
|
IOHIDElements m_keys[static_cast<std::size_t>(Keyboard::Scan::ScancodeCount)]; ///< All the keys on any connected keyboard
|
||||||
Keyboard::Scancode m_keyToScancodeMapping[Keyboard::KeyCount]; ///< Mapping from Key to Scancode
|
Keyboard::Scancode m_keyToScancodeMapping[Keyboard::KeyCount]; ///< Mapping from Key to Scancode
|
||||||
Keyboard::Key m_scancodeToKeyMapping[Keyboard::Scan::ScancodeCount]; ///< Mapping from Scancode to Key
|
Keyboard::Key m_scancodeToKeyMapping[static_cast<std::size_t>(Keyboard::Scan::ScancodeCount)]; ///< Mapping from Scancode to Key
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// m_keys' index corresponds to sf::Keyboard::Scancode enum.
|
/// m_keys' index corresponds to sf::Keyboard::Scancode enum.
|
||||||
|
@ -561,7 +561,7 @@ bool HIDInputManager::isKeyPressed(Keyboard::Key key)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool HIDInputManager::isKeyPressed(Keyboard::Scancode code)
|
bool HIDInputManager::isKeyPressed(Keyboard::Scancode code)
|
||||||
{
|
{
|
||||||
return (code != Keyboard::Scan::Unknown) && isPressed(m_keys[code]);
|
return (code != Keyboard::Scan::Unknown) && isPressed(m_keys[static_cast<std::size_t>(code)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -571,7 +571,7 @@ Keyboard::Key HIDInputManager::localize(Keyboard::Scancode code)
|
|||||||
if (code == Keyboard::Scan::Unknown)
|
if (code == Keyboard::Scan::Unknown)
|
||||||
return Keyboard::Unknown;
|
return Keyboard::Unknown;
|
||||||
|
|
||||||
return m_scancodeToKeyMapping[code];
|
return m_scancodeToKeyMapping[static_cast<std::size_t>(code)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -794,7 +794,7 @@ void HIDInputManager::loadKey(IOHIDElementRef key)
|
|||||||
if (code != Keyboard::Scan::Unknown)
|
if (code != Keyboard::Scan::Unknown)
|
||||||
{
|
{
|
||||||
CFRetain(key);
|
CFRetain(key);
|
||||||
m_keys[code].push_back(key);
|
m_keys[static_cast<std::size_t>(code)].push_back(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -823,7 +823,7 @@ void HIDInputManager::buildMappings()
|
|||||||
|
|
||||||
// For each scancode having a IOHIDElement, we translate the corresponding
|
// For each scancode having a IOHIDElement, we translate the corresponding
|
||||||
// virtual code to a localized Key.
|
// virtual code to a localized Key.
|
||||||
for (int i = 0; i < Keyboard::Scan::ScancodeCount; ++i)
|
for (int i = 0; i < static_cast<int>(Keyboard::Scan::ScancodeCount); ++i)
|
||||||
{
|
{
|
||||||
Keyboard::Scancode scan = static_cast<Keyboard::Scancode>(i);
|
Keyboard::Scancode scan = static_cast<Keyboard::Scancode>(i);
|
||||||
std::uint8_t virtualCode = scanToVirtualCode(scan);
|
std::uint8_t virtualCode = scanToVirtualCode(scan);
|
||||||
@ -898,7 +898,7 @@ void HIDInputManager::buildMappings()
|
|||||||
// Register the bi-mapping
|
// Register the bi-mapping
|
||||||
if (m_keyToScancodeMapping[code] == Keyboard::Scan::Unknown)
|
if (m_keyToScancodeMapping[code] == Keyboard::Scan::Unknown)
|
||||||
m_keyToScancodeMapping[code] = scan;
|
m_keyToScancodeMapping[code] = scan;
|
||||||
m_scancodeToKeyMapping[scan] = code;
|
m_scancodeToKeyMapping[static_cast<std::size_t>(scan)] = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
CFRelease(tis);
|
CFRelease(tis);
|
||||||
|
@ -44,10 +44,10 @@
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
const KeyCode nullKeyCode = 0;
|
const KeyCode nullKeyCode = 0;
|
||||||
const int maxKeyCode = 256;
|
const int maxKeyCode = 256;
|
||||||
KeyCode scancodeToKeycode[sf::Keyboard::Scan::ScancodeCount]; ///< Mapping of SFML scancode to X11 KeyCode
|
KeyCode scancodeToKeycode[static_cast<std::size_t>(sf::Keyboard::Scan::ScancodeCount)]; ///< Mapping of SFML scancode to X11 KeyCode
|
||||||
sf::Keyboard::Scancode keycodeToScancode[maxKeyCode]; ///< Mapping of X11 KeyCode to SFML scancode
|
sf::Keyboard::Scancode keycodeToScancode[maxKeyCode]; ///< Mapping of X11 KeyCode to SFML scancode
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool isValidKeycode(KeyCode keycode)
|
bool isValidKeycode(KeyCode keycode)
|
||||||
@ -491,7 +491,7 @@ void ensureMapping()
|
|||||||
scancode = mappedScancode->second;
|
scancode = mappedScancode->second;
|
||||||
|
|
||||||
if (scancode != sf::Keyboard::Scan::Unknown)
|
if (scancode != sf::Keyboard::Scan::Unknown)
|
||||||
scancodeToKeycode[scancode] = static_cast<KeyCode>(keycode);
|
scancodeToKeycode[static_cast<std::size_t>(scancode)] = static_cast<KeyCode>(keycode);
|
||||||
|
|
||||||
keycodeToScancode[keycode] = scancode;
|
keycodeToScancode[keycode] = scancode;
|
||||||
}
|
}
|
||||||
@ -506,8 +506,9 @@ void ensureMapping()
|
|||||||
{
|
{
|
||||||
scancode = translateKeyCode(display, static_cast<KeyCode>(keycode));
|
scancode = translateKeyCode(display, static_cast<KeyCode>(keycode));
|
||||||
|
|
||||||
if (scancode != sf::Keyboard::Scan::Unknown && scancodeToKeycode[scancode] == nullKeyCode)
|
if (scancode != sf::Keyboard::Scan::Unknown &&
|
||||||
scancodeToKeycode[scancode] = static_cast<KeyCode>(keycode);
|
scancodeToKeycode[static_cast<std::size_t>(scancode)] == nullKeyCode)
|
||||||
|
scancodeToKeycode[static_cast<std::size_t>(scancode)] = static_cast<KeyCode>(keycode);
|
||||||
|
|
||||||
keycodeToScancode[keycode] = scancode;
|
keycodeToScancode[keycode] = scancode;
|
||||||
}
|
}
|
||||||
@ -525,7 +526,7 @@ KeyCode scancodeToKeyCode(sf::Keyboard::Scancode code)
|
|||||||
ensureMapping();
|
ensureMapping();
|
||||||
|
|
||||||
if (code != sf::Keyboard::Scan::Unknown)
|
if (code != sf::Keyboard::Scan::Unknown)
|
||||||
return scancodeToKeycode[code];
|
return scancodeToKeycode[static_cast<std::size_t>(code)];
|
||||||
|
|
||||||
return nullKeyCode;
|
return nullKeyCode;
|
||||||
}
|
}
|
||||||
@ -560,7 +561,7 @@ KeyCode keyToKeyCode(sf::Keyboard::Key key)
|
|||||||
|
|
||||||
// Fallback for when XKeysymToKeycode cannot tell the KeyCode for XK_Alt_R
|
// Fallback for when XKeysymToKeycode cannot tell the KeyCode for XK_Alt_R
|
||||||
if (key == sf::Keyboard::RAlt)
|
if (key == sf::Keyboard::RAlt)
|
||||||
return scancodeToKeycode[sf::Keyboard::Scan::RAlt];
|
return scancodeToKeycode[static_cast<std::size_t>(sf::Keyboard::Scan::RAlt)];
|
||||||
|
|
||||||
return nullKeyCode;
|
return nullKeyCode;
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,8 @@
|
|||||||
namespace sf::priv
|
namespace sf::priv
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Keyboard::Scancode InputImpl::m_keyToScancodeMapping[Keyboard::KeyCount]; ///< Mapping from Key to Scancode
|
Keyboard::Scancode InputImpl::m_keyToScancodeMapping[Keyboard::KeyCount]; ///< Mapping from Key to Scancode
|
||||||
Keyboard::Key InputImpl::m_scancodeToKeyMapping[Keyboard::Scan::ScancodeCount]; ///< Mapping from Scancode to Key
|
Keyboard::Key InputImpl::m_scancodeToKeyMapping[static_cast<std::size_t>(Keyboard::Scan::ScancodeCount)]; ///< Mapping from Scancode to Key
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Keyboard::Key virtualKeyToSfKey(UINT virtualKey)
|
Keyboard::Key virtualKeyToSfKey(UINT virtualKey)
|
||||||
@ -541,14 +541,14 @@ void InputImpl::ensureMappings()
|
|||||||
key = Keyboard::Unknown;
|
key = Keyboard::Unknown;
|
||||||
|
|
||||||
// Phase 2: Translate scancode to virtual code to key names
|
// Phase 2: Translate scancode to virtual code to key names
|
||||||
for (int i = 0; i < Keyboard::Scan::ScancodeCount; ++i)
|
for (int i = 0; i < static_cast<int>(Keyboard::Scan::ScancodeCount); ++i)
|
||||||
{
|
{
|
||||||
Keyboard::Scancode scan = static_cast<Keyboard::Scancode>(i);
|
Keyboard::Scancode scan = static_cast<Keyboard::Scancode>(i);
|
||||||
UINT virtualKey = sfScanToVirtualKey(scan);
|
UINT virtualKey = sfScanToVirtualKey(scan);
|
||||||
Keyboard::Key key = virtualKeyToSfKey(virtualKey);
|
Keyboard::Key key = virtualKeyToSfKey(virtualKey);
|
||||||
if (key != Keyboard::Unknown && m_keyToScancodeMapping[key] == Keyboard::Scan::Unknown)
|
if (key != Keyboard::Unknown && m_keyToScancodeMapping[key] == Keyboard::Scan::Unknown)
|
||||||
m_keyToScancodeMapping[key] = scan;
|
m_keyToScancodeMapping[key] = scan;
|
||||||
m_scancodeToKeyMapping[scan] = key;
|
m_scancodeToKeyMapping[static_cast<std::size_t>(scan)] = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
isMappingInitialized = true;
|
isMappingInitialized = true;
|
||||||
@ -576,7 +576,7 @@ Keyboard::Key InputImpl::localize(Keyboard::Scancode code)
|
|||||||
|
|
||||||
ensureMappings();
|
ensureMappings();
|
||||||
|
|
||||||
return m_scancodeToKeyMapping[code];
|
return m_scancodeToKeyMapping[static_cast<std::size_t>(code)];
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
@ -30,6 +30,8 @@
|
|||||||
#include <SFML/Window/Keyboard.hpp>
|
#include <SFML/Window/Keyboard.hpp>
|
||||||
#include <SFML/Window/Mouse.hpp>
|
#include <SFML/Window/Mouse.hpp>
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
|
|
||||||
namespace sf::priv
|
namespace sf::priv
|
||||||
{
|
{
|
||||||
@ -184,8 +186,8 @@ private:
|
|||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// NOLINTBEGIN(readability-identifier-naming)
|
// NOLINTBEGIN(readability-identifier-naming)
|
||||||
static Keyboard::Scancode m_keyToScancodeMapping[Keyboard::KeyCount]; ///< Mapping from Key to Scancode
|
static Keyboard::Scancode m_keyToScancodeMapping[Keyboard::KeyCount]; ///< Mapping from Key to Scancode
|
||||||
static Keyboard::Key m_scancodeToKeyMapping[Keyboard::Scan::ScancodeCount]; ///< Mapping from Scancode to Key
|
static Keyboard::Key m_scancodeToKeyMapping[static_cast<std::size_t>(Keyboard::Scan::ScancodeCount)]; ///< Mapping from Scancode to Key
|
||||||
// NOLINTEND(readability-identifier-naming)
|
// NOLINTEND(readability-identifier-naming)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user