Align key mappings & refactorings

- Changed getDescription output: Alt -> Meta, System -> Super
- Correct initialization of mapping arrays
- Added "ReverseSolidus" support
- Swap ScanEnter and ScanReturn
  (ScanEnter = Numpad Enter, ScanReturn = Keyboard Enter)
- Better descriptions for some keys
  (e.g. "Shift (Left)" -> "Left Shift")
This commit is contained in:
Elias Daler 2018-04-03 00:11:31 +03:00 committed by Lukas Dürrenberger
parent 95f19ff478
commit 5bf4982239
9 changed files with 1937 additions and 1837 deletions

View File

@ -120,8 +120,10 @@ elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD OR SFML_OS_OPENBSD OR SFML_OS_NETBSD)
${SRCROOT}/Unix/InputImpl.hpp
${SRCROOT}/Unix/KeyboardImpl.hpp
${SRCROOT}/Unix/KeyboardImpl.cpp
${SRCROOT}/Unix/KeySymToSFKeyMapping.hpp
${SRCROOT}/Unix/KeySymToKeyMapping.hpp
${SRCROOT}/Unix/KeySymToKeyMapping.cpp
${SRCROOT}/Unix/KeySymToUnicodeMapping.hpp
${SRCROOT}/Unix/KeySymToUnicodeMapping.cpp
${SRCROOT}/Unix/SensorImpl.cpp
${SRCROOT}/Unix/SensorImpl.hpp
${SRCROOT}/Unix/Display.cpp

View File

@ -26,13 +26,12 @@
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window/Window.hpp> // important to be included first (conflict with None)
#include <SFML/Window/Unix/Display.hpp>
#include <SFML/Window/Unix/InputImpl.hpp>
#include <SFML/Window/Unix/Display.hpp>
#include <SFML/Window/Unix/KeyboardImpl.hpp>
#include <X11/Xlib.h>
#include <X11/keysym.h>
namespace sf
{
namespace priv

View File

@ -0,0 +1,261 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2018 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.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window/Unix/KeySymToKeyMapping.hpp>
#include <X11/keysym.h>
namespace sf
{
namespace priv
{
////////////////////////////////////////////////////////////
Keyboard::Key keySymToKey(KeySym symbol)
{
switch (symbol)
{
case XK_Shift_L: return Keyboard::LShift;
case XK_Shift_R: return Keyboard::RShift;
case XK_Control_L: return Keyboard::LControl;
case XK_Control_R: return Keyboard::RControl;
case XK_Alt_L: return Keyboard::LAlt;
case XK_Alt_R: return Keyboard::RAlt;
case XK_Super_L: return Keyboard::LSystem;
case XK_Super_R: return Keyboard::RSystem;
case XK_Menu: return Keyboard::Menu;
case XK_Escape: return Keyboard::Escape;
case XK_semicolon: return Keyboard::SemiColon;
case XK_slash: return Keyboard::Slash;
case XK_equal: return Keyboard::Equal;
case XK_minus: return Keyboard::Dash;
case XK_bracketleft: return Keyboard::LBracket;
case XK_bracketright: return Keyboard::RBracket;
case XK_comma: return Keyboard::Comma;
case XK_period: return Keyboard::Period;
case XK_apostrophe: return Keyboard::Quote;
case XK_backslash: return Keyboard::BackSlash;
case XK_grave: return Keyboard::Tilde;
case XK_space: return Keyboard::Space;
case XK_Return: return Keyboard::Return;
case XK_KP_Enter: return Keyboard::Return;
case XK_BackSpace: return Keyboard::BackSpace;
case XK_Tab: return Keyboard::Tab;
case XK_Prior: return Keyboard::PageUp;
case XK_Next: return Keyboard::PageDown;
case XK_End: return Keyboard::End;
case XK_Home: return Keyboard::Home;
case XK_Insert: return Keyboard::Insert;
case XK_Delete: return Keyboard::Delete;
case XK_KP_Add: return Keyboard::Add;
case XK_KP_Subtract: return Keyboard::Subtract;
case XK_KP_Multiply: return Keyboard::Multiply;
case XK_KP_Divide: return Keyboard::Divide;
case XK_Pause: return Keyboard::Pause;
case XK_F1: return Keyboard::F1;
case XK_F2: return Keyboard::F2;
case XK_F3: return Keyboard::F3;
case XK_F4: return Keyboard::F4;
case XK_F5: return Keyboard::F5;
case XK_F6: return Keyboard::F6;
case XK_F7: return Keyboard::F7;
case XK_F8: return Keyboard::F8;
case XK_F9: return Keyboard::F9;
case XK_F10: return Keyboard::F10;
case XK_F11: return Keyboard::F11;
case XK_F12: return Keyboard::F12;
case XK_F13: return Keyboard::F13;
case XK_F14: return Keyboard::F14;
case XK_F15: return Keyboard::F15;
case XK_Left: return Keyboard::Left;
case XK_Right: return Keyboard::Right;
case XK_Up: return Keyboard::Up;
case XK_Down: return Keyboard::Down;
case XK_KP_Insert: return Keyboard::Numpad0;
case XK_KP_End: return Keyboard::Numpad1;
case XK_KP_Down: return Keyboard::Numpad2;
case XK_KP_Page_Down: return Keyboard::Numpad3;
case XK_KP_Left: return Keyboard::Numpad4;
case XK_KP_Begin: return Keyboard::Numpad5;
case XK_KP_Right: return Keyboard::Numpad6;
case XK_KP_Home: return Keyboard::Numpad7;
case XK_KP_Up: return Keyboard::Numpad8;
case XK_KP_Page_Up: return Keyboard::Numpad9;
case XK_a: return Keyboard::A;
case XK_b: return Keyboard::B;
case XK_c: return Keyboard::C;
case XK_d: return Keyboard::D;
case XK_e: return Keyboard::E;
case XK_f: return Keyboard::F;
case XK_g: return Keyboard::G;
case XK_h: return Keyboard::H;
case XK_i: return Keyboard::I;
case XK_j: return Keyboard::J;
case XK_k: return Keyboard::K;
case XK_l: return Keyboard::L;
case XK_m: return Keyboard::M;
case XK_n: return Keyboard::N;
case XK_o: return Keyboard::O;
case XK_p: return Keyboard::P;
case XK_q: return Keyboard::Q;
case XK_r: return Keyboard::R;
case XK_s: return Keyboard::S;
case XK_t: return Keyboard::T;
case XK_u: return Keyboard::U;
case XK_v: return Keyboard::V;
case XK_w: return Keyboard::W;
case XK_x: return Keyboard::X;
case XK_y: return Keyboard::Y;
case XK_z: return Keyboard::Z;
case XK_0: return Keyboard::Num0;
case XK_1: return Keyboard::Num1;
case XK_2: return Keyboard::Num2;
case XK_3: return Keyboard::Num3;
case XK_4: return Keyboard::Num4;
case XK_5: return Keyboard::Num5;
case XK_6: return Keyboard::Num6;
case XK_7: return Keyboard::Num7;
case XK_8: return Keyboard::Num8;
case XK_9: return Keyboard::Num9;
default: return Keyboard::Unknown;
}
}
////////////////////////////////////////////////////////////
KeySym keyToKeySym(Keyboard::Key key)
{
switch (key)
{
case Keyboard::LShift: return XK_Shift_L;
case Keyboard::RShift: return XK_Shift_R;
case Keyboard::LControl: return XK_Control_L;
case Keyboard::RControl: return XK_Control_R;
case Keyboard::LAlt: return XK_Alt_L;
case Keyboard::RAlt: return XK_Alt_R;
case Keyboard::LSystem: return XK_Super_L;
case Keyboard::RSystem: return XK_Super_R;
case Keyboard::Menu: return XK_Menu;
case Keyboard::Escape: return XK_Escape;
case Keyboard::SemiColon: return XK_semicolon;
case Keyboard::Slash: return XK_slash;
case Keyboard::Equal: return XK_equal;
case Keyboard::Dash: return XK_minus;
case Keyboard::LBracket: return XK_bracketleft;
case Keyboard::RBracket: return XK_bracketright;
case Keyboard::Comma: return XK_comma;
case Keyboard::Period: return XK_period;
case Keyboard::Quote: return XK_apostrophe;
case Keyboard::BackSlash: return XK_backslash;
case Keyboard::Tilde: return XK_grave;
case Keyboard::Space: return XK_space;
case Keyboard::Return: return XK_Return;
case Keyboard::BackSpace: return XK_BackSpace;
case Keyboard::Tab: return XK_Tab;
case Keyboard::PageUp: return XK_Prior;
case Keyboard::PageDown: return XK_Next;
case Keyboard::End: return XK_End;
case Keyboard::Home: return XK_Home;
case Keyboard::Insert: return XK_Insert;
case Keyboard::Delete: return XK_Delete;
case Keyboard::Add: return XK_KP_Add;
case Keyboard::Subtract: return XK_KP_Subtract;
case Keyboard::Multiply: return XK_KP_Multiply;
case Keyboard::Divide: return XK_KP_Divide;
case Keyboard::Pause: return XK_Pause;
case Keyboard::F1: return XK_F1;
case Keyboard::F2: return XK_F2;
case Keyboard::F3: return XK_F3;
case Keyboard::F4: return XK_F4;
case Keyboard::F5: return XK_F5;
case Keyboard::F6: return XK_F6;
case Keyboard::F7: return XK_F7;
case Keyboard::F8: return XK_F8;
case Keyboard::F9: return XK_F9;
case Keyboard::F10: return XK_F10;
case Keyboard::F11: return XK_F11;
case Keyboard::F12: return XK_F12;
case Keyboard::F13: return XK_F13;
case Keyboard::F14: return XK_F14;
case Keyboard::F15: return XK_F15;
case Keyboard::Left: return XK_Left;
case Keyboard::Right: return XK_Right;
case Keyboard::Up: return XK_Up;
case Keyboard::Down: return XK_Down;
case Keyboard::Numpad0: return XK_KP_Insert;
case Keyboard::Numpad1: return XK_KP_End;
case Keyboard::Numpad2: return XK_KP_Down;
case Keyboard::Numpad3: return XK_KP_Page_Down;
case Keyboard::Numpad4: return XK_KP_Left;
case Keyboard::Numpad5: return XK_KP_Begin;
case Keyboard::Numpad6: return XK_KP_Right;
case Keyboard::Numpad7: return XK_KP_Home;
case Keyboard::Numpad8: return XK_KP_Up;
case Keyboard::Numpad9: return XK_KP_Page_Up;
case Keyboard::A: return XK_a;
case Keyboard::B: return XK_b;
case Keyboard::C: return XK_c;
case Keyboard::D: return XK_d;
case Keyboard::E: return XK_e;
case Keyboard::F: return XK_f;
case Keyboard::G: return XK_g;
case Keyboard::H: return XK_h;
case Keyboard::I: return XK_i;
case Keyboard::J: return XK_j;
case Keyboard::K: return XK_k;
case Keyboard::L: return XK_l;
case Keyboard::M: return XK_m;
case Keyboard::N: return XK_n;
case Keyboard::O: return XK_o;
case Keyboard::P: return XK_p;
case Keyboard::Q: return XK_q;
case Keyboard::R: return XK_r;
case Keyboard::S: return XK_s;
case Keyboard::T: return XK_t;
case Keyboard::U: return XK_u;
case Keyboard::V: return XK_v;
case Keyboard::W: return XK_w;
case Keyboard::X: return XK_x;
case Keyboard::Y: return XK_y;
case Keyboard::Z: return XK_z;
case Keyboard::Num0: return XK_0;
case Keyboard::Num1: return XK_1;
case Keyboard::Num2: return XK_2;
case Keyboard::Num3: return XK_3;
case Keyboard::Num4: return XK_4;
case Keyboard::Num5: return XK_5;
case Keyboard::Num6: return XK_6;
case Keyboard::Num7: return XK_7;
case Keyboard::Num8: return XK_8;
case Keyboard::Num9: return XK_9;
default: return NoSymbol;
}
}
} // namespace priv
} // namespace sf

View File

@ -0,0 +1,63 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2018 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.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_KEYSYMTOKEYMAPPING_HPP
#define SFML_KEYSYMTOKEYMAPPING_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window/Keyboard.hpp> // sf::Keyboard::Key
#include <X11/X.h> // KeySym
namespace sf
{
namespace priv
{
////////////////////////////////////////////////////////////
/// \brief Convert X11 KeySym to sf::Keyboard::Key
///
/// \param symbol X11 KeySym
///
/// \return The corresponding sf::Keyboard::Key
///
////////////////////////////////////////////////////////////
Keyboard::Key keySymToKey(KeySym symbol);
////////////////////////////////////////////////////////////
/// \brief Convert sf::Keyboard::Key to X11 KeySym
///
/// \param key X11 sf::Keyboard::Key
///
/// \return The corresponding X11 KeySym
///
////////////////////////////////////////////////////////////
KeySym keyToKeySym(Keyboard::Key key);
} // namespace priv
} // namespace sf
#endif // SFML_KEYSYMTOKEYMAPPING_HPP

View File

@ -1,282 +0,0 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2017 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.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_KEYSYMTOSFKEYMAPPING_HPP
#define SFML_KEYSYMTOSFKEYMAPPING_HPP
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window/Keyboard.hpp>
#include <X11/Xlib.h>
#include <X11/keysym.h>
namespace sf
{
namespace priv
{
////////////////////////////////////////////////////////////
/// \brief Convert X11 KeySym to sf::Keyboard::Key
///
/// \param symbol X11 KeySym
///
/// \return The corresponding sf::Keyboard::Key
///
////////////////////////////////////////////////////////////
inline Keyboard::Key keySymToSFKey(KeySym symbol)
{
switch (symbol)
{
case XK_Shift_L: return Keyboard::LShift;
case XK_Shift_R: return Keyboard::RShift;
case XK_Control_L: return Keyboard::LControl;
case XK_Control_R: return Keyboard::RControl;
case XK_Alt_L: return Keyboard::LAlt;
case XK_Alt_R: return Keyboard::RAlt;
case XK_Super_L: return Keyboard::LSystem;
case XK_Super_R: return Keyboard::RSystem;
case XK_Menu: return Keyboard::Menu;
case XK_Escape: return Keyboard::Escape;
case XK_semicolon: return Keyboard::SemiColon;
case XK_slash: return Keyboard::Slash;
case XK_equal: return Keyboard::Equal;
case XK_minus: return Keyboard::Dash;
case XK_bracketleft: return Keyboard::LBracket;
case XK_bracketright: return Keyboard::RBracket;
case XK_comma: return Keyboard::Comma;
case XK_period: return Keyboard::Period;
case XK_apostrophe: return Keyboard::Quote;
case XK_backslash: return Keyboard::BackSlash;
case XK_grave: return Keyboard::Tilde;
case XK_space: return Keyboard::Space;
case XK_Return: return Keyboard::Return;
case XK_KP_Enter: return Keyboard::Return;
case XK_BackSpace: return Keyboard::BackSpace;
case XK_Tab: return Keyboard::Tab;
case XK_Prior: return Keyboard::PageUp;
case XK_Next: return Keyboard::PageDown;
case XK_End: return Keyboard::End;
case XK_Home: return Keyboard::Home;
case XK_Insert: return Keyboard::Insert;
case XK_Delete: return Keyboard::Delete;
case XK_KP_Add: return Keyboard::Add;
case XK_KP_Subtract: return Keyboard::Subtract;
case XK_KP_Multiply: return Keyboard::Multiply;
case XK_KP_Divide: return Keyboard::Divide;
case XK_Pause: return Keyboard::Pause;
case XK_F1: return Keyboard::F1;
case XK_F2: return Keyboard::F2;
case XK_F3: return Keyboard::F3;
case XK_F4: return Keyboard::F4;
case XK_F5: return Keyboard::F5;
case XK_F6: return Keyboard::F6;
case XK_F7: return Keyboard::F7;
case XK_F8: return Keyboard::F8;
case XK_F9: return Keyboard::F9;
case XK_F10: return Keyboard::F10;
case XK_F11: return Keyboard::F11;
case XK_F12: return Keyboard::F12;
case XK_F13: return Keyboard::F13;
case XK_F14: return Keyboard::F14;
case XK_F15: return Keyboard::F15;
case XK_Left: return Keyboard::Left;
case XK_Right: return Keyboard::Right;
case XK_Up: return Keyboard::Up;
case XK_Down: return Keyboard::Down;
case XK_KP_Insert: return Keyboard::Numpad0;
case XK_KP_End: return Keyboard::Numpad1;
case XK_KP_Down: return Keyboard::Numpad2;
case XK_KP_Page_Down: return Keyboard::Numpad3;
case XK_KP_Left: return Keyboard::Numpad4;
case XK_KP_Begin: return Keyboard::Numpad5;
case XK_KP_Right: return Keyboard::Numpad6;
case XK_KP_Home: return Keyboard::Numpad7;
case XK_KP_Up: return Keyboard::Numpad8;
case XK_KP_Page_Up: return Keyboard::Numpad9;
case XK_a: return Keyboard::A;
case XK_b: return Keyboard::B;
case XK_c: return Keyboard::C;
case XK_d: return Keyboard::D;
case XK_e: return Keyboard::E;
case XK_f: return Keyboard::F;
case XK_g: return Keyboard::G;
case XK_h: return Keyboard::H;
case XK_i: return Keyboard::I;
case XK_j: return Keyboard::J;
case XK_k: return Keyboard::K;
case XK_l: return Keyboard::L;
case XK_m: return Keyboard::M;
case XK_n: return Keyboard::N;
case XK_o: return Keyboard::O;
case XK_p: return Keyboard::P;
case XK_q: return Keyboard::Q;
case XK_r: return Keyboard::R;
case XK_s: return Keyboard::S;
case XK_t: return Keyboard::T;
case XK_u: return Keyboard::U;
case XK_v: return Keyboard::V;
case XK_w: return Keyboard::W;
case XK_x: return Keyboard::X;
case XK_y: return Keyboard::Y;
case XK_z: return Keyboard::Z;
case XK_0: return Keyboard::Num0;
case XK_1: return Keyboard::Num1;
case XK_2: return Keyboard::Num2;
case XK_3: return Keyboard::Num3;
case XK_4: return Keyboard::Num4;
case XK_5: return Keyboard::Num5;
case XK_6: return Keyboard::Num6;
case XK_7: return Keyboard::Num7;
case XK_8: return Keyboard::Num8;
case XK_9: return Keyboard::Num9;
}
return Keyboard::Unknown;
}
////////////////////////////////////////////////////////////
/// \brief Convert sf::Keyboard::Key to X11 KeySym
///
/// \param key X11 sf::Keyboard::Key
///
/// \return The corresponding X11 KeySym
///
////////////////////////////////////////////////////////////
inline KeySym SFKeyToKeySym(Keyboard::Key key)
{
// Get the corresponding X11 keysym
KeySym keysym = NoSymbol;
switch (key)
{
case Keyboard::LShift: keysym = XK_Shift_L; break;
case Keyboard::RShift: keysym = XK_Shift_R; break;
case Keyboard::LControl: keysym = XK_Control_L; break;
case Keyboard::RControl: keysym = XK_Control_R; break;
case Keyboard::LAlt: keysym = XK_Alt_L; break;
case Keyboard::RAlt: keysym = XK_Alt_R; break;
case Keyboard::LSystem: keysym = XK_Super_L; break;
case Keyboard::RSystem: keysym = XK_Super_R; break;
case Keyboard::Menu: keysym = XK_Menu; break;
case Keyboard::Escape: keysym = XK_Escape; break;
case Keyboard::SemiColon: keysym = XK_semicolon; break;
case Keyboard::Slash: keysym = XK_slash; break;
case Keyboard::Equal: keysym = XK_equal; break;
case Keyboard::Dash: keysym = XK_minus; break;
case Keyboard::LBracket: keysym = XK_bracketleft; break;
case Keyboard::RBracket: keysym = XK_bracketright; break;
case Keyboard::Comma: keysym = XK_comma; break;
case Keyboard::Period: keysym = XK_period; break;
case Keyboard::Quote: keysym = XK_apostrophe; break;
case Keyboard::BackSlash: keysym = XK_backslash; break;
case Keyboard::Tilde: keysym = XK_grave; break;
case Keyboard::Space: keysym = XK_space; break;
case Keyboard::Return: keysym = XK_Return; break;
case Keyboard::BackSpace: keysym = XK_BackSpace; break;
case Keyboard::Tab: keysym = XK_Tab; break;
case Keyboard::PageUp: keysym = XK_Prior; break;
case Keyboard::PageDown: keysym = XK_Next; break;
case Keyboard::End: keysym = XK_End; break;
case Keyboard::Home: keysym = XK_Home; break;
case Keyboard::Insert: keysym = XK_Insert; break;
case Keyboard::Delete: keysym = XK_Delete; break;
case Keyboard::Add: keysym = XK_KP_Add; break;
case Keyboard::Subtract: keysym = XK_KP_Subtract; break;
case Keyboard::Multiply: keysym = XK_KP_Multiply; break;
case Keyboard::Divide: keysym = XK_KP_Divide; break;
case Keyboard::Pause: keysym = XK_Pause; break;
case Keyboard::F1: keysym = XK_F1; break;
case Keyboard::F2: keysym = XK_F2; break;
case Keyboard::F3: keysym = XK_F3; break;
case Keyboard::F4: keysym = XK_F4; break;
case Keyboard::F5: keysym = XK_F5; break;
case Keyboard::F6: keysym = XK_F6; break;
case Keyboard::F7: keysym = XK_F7; break;
case Keyboard::F8: keysym = XK_F8; break;
case Keyboard::F9: keysym = XK_F9; break;
case Keyboard::F10: keysym = XK_F10; break;
case Keyboard::F11: keysym = XK_F11; break;
case Keyboard::F12: keysym = XK_F12; break;
case Keyboard::F13: keysym = XK_F13; break;
case Keyboard::F14: keysym = XK_F14; break;
case Keyboard::F15: keysym = XK_F15; break;
case Keyboard::Left: keysym = XK_Left; break;
case Keyboard::Right: keysym = XK_Right; break;
case Keyboard::Up: keysym = XK_Up; break;
case Keyboard::Down: keysym = XK_Down; break;
case Keyboard::Numpad0: keysym = XK_KP_Insert; break;
case Keyboard::Numpad1: keysym = XK_KP_End; break;
case Keyboard::Numpad2: keysym = XK_KP_Down; break;
case Keyboard::Numpad3: keysym = XK_KP_Page_Down; break;
case Keyboard::Numpad4: keysym = XK_KP_Left; break;
case Keyboard::Numpad5: keysym = XK_KP_Begin; break;
case Keyboard::Numpad6: keysym = XK_KP_Right; break;
case Keyboard::Numpad7: keysym = XK_KP_Home; break;
case Keyboard::Numpad8: keysym = XK_KP_Up; break;
case Keyboard::Numpad9: keysym = XK_KP_Page_Up; break;
case Keyboard::A: keysym = XK_a; break;
case Keyboard::B: keysym = XK_b; break;
case Keyboard::C: keysym = XK_c; break;
case Keyboard::D: keysym = XK_d; break;
case Keyboard::E: keysym = XK_e; break;
case Keyboard::F: keysym = XK_f; break;
case Keyboard::G: keysym = XK_g; break;
case Keyboard::H: keysym = XK_h; break;
case Keyboard::I: keysym = XK_i; break;
case Keyboard::J: keysym = XK_j; break;
case Keyboard::K: keysym = XK_k; break;
case Keyboard::L: keysym = XK_l; break;
case Keyboard::M: keysym = XK_m; break;
case Keyboard::N: keysym = XK_n; break;
case Keyboard::O: keysym = XK_o; break;
case Keyboard::P: keysym = XK_p; break;
case Keyboard::Q: keysym = XK_q; break;
case Keyboard::R: keysym = XK_r; break;
case Keyboard::S: keysym = XK_s; break;
case Keyboard::T: keysym = XK_t; break;
case Keyboard::U: keysym = XK_u; break;
case Keyboard::V: keysym = XK_v; break;
case Keyboard::W: keysym = XK_w; break;
case Keyboard::X: keysym = XK_x; break;
case Keyboard::Y: keysym = XK_y; break;
case Keyboard::Z: keysym = XK_z; break;
case Keyboard::Num0: keysym = XK_0; break;
case Keyboard::Num1: keysym = XK_1; break;
case Keyboard::Num2: keysym = XK_2; break;
case Keyboard::Num3: keysym = XK_3; break;
case Keyboard::Num4: keysym = XK_4; break;
case Keyboard::Num5: keysym = XK_5; break;
case Keyboard::Num6: keysym = XK_6; break;
case Keyboard::Num7: keysym = XK_7; break;
case Keyboard::Num8: keysym = XK_8; break;
case Keyboard::Num9: keysym = XK_9; break;
}
return keysym;
}
} // namespace priv
} // namespace sf
#endif // SFML_KEYSYMTOSFKEYMAPPING_HPP

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -26,29 +26,32 @@
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window/Unix/KeyboardImpl.hpp>
#include <SFML/System/Utf.hpp>
#include <SFML/Window/Unix/Display.hpp>
#include <SFML/Window/Unix/KeySymToSFKeyMapping.hpp>
#include <SFML/Window/Unix/KeySymToKeyMapping.hpp>
#include <SFML/Window/Unix/KeySymToUnicodeMapping.hpp>
#include <SFML/System/String.hpp>
#include <SFML/System/Utf.hpp>
#include <X11/keysym.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <cstring>
#include <X11/XKBlib.h>
#include <cstring> // strcmp
namespace {
namespace
{
const KeyCode NullKeyCode = 0;
KeyCode scancodeToKeycode[sf::Keyboard::ScanCodeCount] = { NullKeyCode }; ///< Mapping of SFML scancode to X11 KeyCode
sf::Keyboard::Scancode keycodeToScancode[256] = { sf::Keyboard::ScanUnknown}; ///< Mapping of X11 KeyCode to SFML scancode
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;
////////////////////////////////////////////////////////////
bool isValidKeycode(KeyCode keycode)
{
// Valid key code range is [8,255], according to the Xlib manual
return keycode >= 8 || keycode <= 255;
return (keycode >= 8) || (keycode <= 255);
}
////////////////////////////////////////////////////////////
sf::Keyboard::Scancode translateKeyCode(Display* display, KeyCode keycode)
{
@ -60,23 +63,24 @@ sf::Keyboard::Scancode translateKeyCode(Display* display, KeyCode keycode)
// since the returned key code should correspond to a physical
// location.
KeySym keySym = XkbKeycodeToKeysym(display, keycode, 0, 1);
switch (keySym)
{
case XK_KP_0: return sf::Keyboard::ScanNumpad0;
case XK_KP_1: return sf::Keyboard::ScanNumpad1;
case XK_KP_2: return sf::Keyboard::ScanNumpad2;
case XK_KP_3: return sf::Keyboard::ScanNumpad3;
case XK_KP_4: return sf::Keyboard::ScanNumpad4;
case XK_KP_5: return sf::Keyboard::ScanNumpad5;
case XK_KP_6: return sf::Keyboard::ScanNumpad6;
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:
case XK_KP_Decimal: return sf::Keyboard::ScanDecimal;
case XK_KP_Equal: return sf::Keyboard::ScanPadEquals;
case XK_KP_Enter: return sf::Keyboard::ScanReturn;
default: break;
case XK_KP_0: return sf::Keyboard::ScanNumpad0;
case XK_KP_1: return sf::Keyboard::ScanNumpad1;
case XK_KP_2: return sf::Keyboard::ScanNumpad2;
case XK_KP_3: return sf::Keyboard::ScanNumpad3;
case XK_KP_4: return sf::Keyboard::ScanNumpad4;
case XK_KP_5: return sf::Keyboard::ScanNumpad5;
case XK_KP_6: return sf::Keyboard::ScanNumpad6;
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;
default: break;
}
// Now try primary keysym for function keys (non-printable keys)
@ -85,147 +89,142 @@ sf::Keyboard::Scancode translateKeyCode(Display* display, KeyCode keycode)
switch (keySym)
{
case XK_Escape: return sf::Keyboard::ScanEscape;
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:
case XK_Alt_L: return sf::Keyboard::ScanLAlt;
case XK_Mode_switch: // Mapped to Alt_R on many keyboards
case XK_ISO_Level3_Shift: // AltGr on at least some machines
case XK_Meta_R:
case XK_Alt_R: return sf::Keyboard::ScanRAlt;
case XK_Super_L: return sf::Keyboard::ScanLSystem;
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_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_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;
case XK_F4: return sf::Keyboard::ScanF4;
case XK_F5: return sf::Keyboard::ScanF5;
case XK_F6: return sf::Keyboard::ScanF6;
case XK_F7: return sf::Keyboard::ScanF7;
case XK_F8: return sf::Keyboard::ScanF8;
case XK_F9: return sf::Keyboard::ScanF9;
case XK_F10: return sf::Keyboard::ScanF10;
case XK_F11: return sf::Keyboard::ScanF11;
case XK_F12: return sf::Keyboard::ScanF12;
case XK_F13: return sf::Keyboard::ScanF13;
case XK_F14: return sf::Keyboard::ScanF14;
case XK_F15: return sf::Keyboard::ScanF15;
// SFML doesn't currently have these scancodes
/* 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;
case XK_F25: return sf::Keyboard::ScanF25; */
case XK_Escape: return sf::Keyboard::ScanEscape;
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_Alt_R: return sf::Keyboard::ScanRAlt;
case XK_Super_L: return sf::Keyboard::ScanLSystem;
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_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_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;
case XK_F4: return sf::Keyboard::ScanF4;
case XK_F5: return sf::Keyboard::ScanF5;
case XK_F6: return sf::Keyboard::ScanF6;
case XK_F7: return sf::Keyboard::ScanF7;
case XK_F8: return sf::Keyboard::ScanF8;
case XK_F9: return sf::Keyboard::ScanF9;
case XK_F10: return sf::Keyboard::ScanF10;
case XK_F11: return sf::Keyboard::ScanF11;
case XK_F12: return sf::Keyboard::ScanF12;
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
// 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::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;
// These should have been detected in secondary keysym test above!
case XK_KP_Insert: return sf::Keyboard::ScanNumpad0;
case XK_KP_End: return sf::Keyboard::ScanNumpad1;
case XK_KP_Down: return sf::Keyboard::ScanNumpad2;
case XK_KP_Page_Down: return sf::Keyboard::ScanNumpad3;
case XK_KP_Left: return sf::Keyboard::ScanNumpad4;
case XK_KP_Right: return sf::Keyboard::ScanNumpad6;
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_Insert: return sf::Keyboard::ScanNumpad0;
case XK_KP_End: return sf::Keyboard::ScanNumpad1;
case XK_KP_Down: return sf::Keyboard::ScanNumpad2;
case XK_KP_Page_Down: return sf::Keyboard::ScanNumpad3;
case XK_KP_Left: return sf::Keyboard::ScanNumpad4;
case XK_KP_Right: return sf::Keyboard::ScanNumpad6;
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;
// 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_1: return sf::Keyboard::ScanNum1;
case XK_2: return sf::Keyboard::ScanNum2;
case XK_3: return sf::Keyboard::ScanNum3;
case XK_4: return sf::Keyboard::ScanNum4;
case XK_5: return sf::Keyboard::ScanNum5;
case XK_6: return sf::Keyboard::ScanNum6;
case XK_7: return sf::Keyboard::ScanNum7;
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_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_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::ScanWorld1; // At least in some layouts...
default: break;
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_1: return sf::Keyboard::ScanNum1;
case XK_2: return sf::Keyboard::ScanNum2;
case XK_3: return sf::Keyboard::ScanNum3;
case XK_4: return sf::Keyboard::ScanNum4;
case XK_5: return sf::Keyboard::ScanNum5;
case XK_6: return sf::Keyboard::ScanNum6;
case XK_7: return sf::Keyboard::ScanNum7;
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_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_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;
default: return sf::Keyboard::ScanUnknown;
}
// No matching translation was found
return sf::Keyboard::ScanUnknown;
}
////////////////////////////////////////////////////////////
void initMapping()
{
for (int i = 0; i < 256; ++i)
scancodeToKeycode[i] = NullKeyCode;
for (int i = 0; i < sf::Keyboard::ScanCodeCount; ++i)
keycodeToScancode[i] = sf::Keyboard::ScanUnknown;
Display* display = sf::priv::OpenDisplay();
// Find the X11 key code -> SFML key code mapping
@ -236,12 +235,13 @@ void initMapping()
XkbGetNames(display, XkbKeyNamesMask, desc);
sf::Keyboard::Scancode sc;
for (int keycode = desc->min_key_code; keycode <= desc->max_key_code; ++keycode)
{
std::memcpy(name, desc->names->keys[keycode].name, XkbKeyNameLength);
name[XkbKeyNameLength] = '\0';
if (strcmp(name, "TLDE") == 0) sc = sf::Keyboard::ScanGraveAccent;
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;
@ -254,7 +254,7 @@ void initMapping()
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, "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;
@ -289,7 +289,8 @@ void initMapping()
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 sc = sf::Keyboard::ScanUnknown;
else if (strcmp(name, "LSGT") == 0) sc = sf::Keyboard::ScanReverseSolidus;
else sc = sf::Keyboard::ScanUnknown;
if (isValidKeycode(keycode))
{
@ -318,8 +319,9 @@ void initMapping()
isMappingInitialized = true;
}
////////////////////////////////////////////////////////////
KeyCode SFScancodeToKeyCode(sf::Keyboard::Scancode code)
KeyCode scancodeToKeyCode(sf::Keyboard::Scancode code)
{
if (!isMappingInitialized)
initMapping();
@ -327,21 +329,25 @@ KeyCode SFScancodeToKeyCode(sf::Keyboard::Scancode code)
return scancodeToKeycode[code];
}
////////////////////////////////////////////////////////////
sf::Keyboard::Scancode keyCodeToSFScancode(KeyCode code)
sf::Keyboard::Scancode keyCodeToScancode(KeyCode code)
{
if (!isMappingInitialized)
initMapping();
if (isValidKeycode(code))
return keycodeToScancode[code];
return sf::Keyboard::ScanUnknown;
}
////////////////////////////////////////////////////////////
KeyCode SFKeyToKeyCode(sf::Keyboard::Key key)
KeyCode keyToKeyCode(sf::Keyboard::Key key)
{
KeySym keysym = sf::priv::SFKeyToKeySym(key);
KeySym keysym = sf::priv::keyToKeySym(key);
if (keysym != NoSymbol)
{
Display* display = sf::priv::OpenDisplay();
@ -349,21 +355,28 @@ KeyCode SFKeyToKeyCode(sf::Keyboard::Key key)
sf::priv::CloseDisplay(display);
return keycode;
}
return NullKeyCode;
}
////////////////////////////////////////////////////////////
KeySym SFScancodeToKeySym(sf::Keyboard::Scancode code)
KeySym scancodeToKeySym(sf::Keyboard::Scancode code)
{
Display* display = sf::priv::OpenDisplay();
KeySym keysym = NoSymbol;
KeyCode keycode = SFScancodeToKeyCode(code);
KeyCode keycode = scancodeToKeyCode(code);
if (keycode != NullKeyCode) // ensure that this Scancode is mapped to keycode
keysym = XkbKeycodeToKeysym(display, keycode, 0, 0);
sf::priv::CloseDisplay(display);
return keysym;
}
////////////////////////////////////////////////////////////
bool isKeyPressedImpl(KeyCode keycode)
{
@ -380,6 +393,7 @@ bool isKeyPressedImpl(KeyCode keycode)
// Check our keycode
return (keys[keycode / 8] & (1 << (keycode % 8))) != 0;
}
return false;
}
@ -393,7 +407,7 @@ namespace priv
////////////////////////////////////////////////////////////
bool KeyboardImpl::isKeyPressed(Keyboard::Key key)
{
KeyCode keycode = SFKeyToKeyCode(key);
KeyCode keycode = keyToKeyCode(key);
return isKeyPressedImpl(keycode);
}
@ -401,7 +415,7 @@ bool KeyboardImpl::isKeyPressed(Keyboard::Key key)
////////////////////////////////////////////////////////////
bool KeyboardImpl::isKeyPressed(Keyboard::Scancode code)
{
KeyCode keycode = SFScancodeToKeyCode(code);
KeyCode keycode = scancodeToKeyCode(code);
return isKeyPressedImpl(keycode);
}
@ -409,18 +423,19 @@ bool KeyboardImpl::isKeyPressed(Keyboard::Scancode code)
////////////////////////////////////////////////////////////
Keyboard::Scancode KeyboardImpl::unlocalize(Keyboard::Key key)
{
KeyCode keycode = SFKeyToKeyCode(key);
return keyCodeToSFScancode(keycode);
KeyCode keycode = keyToKeyCode(key);
return keyCodeToScancode(keycode);
}
////////////////////////////////////////////////////////////
Keyboard::Key KeyboardImpl::localize(Keyboard::Scancode code)
{
KeySym keysym = SFScancodeToKeySym(code);
return keySymToSFKey(keysym);
KeySym keysym = scancodeToKeySym(code);
return keySymToKey(keysym);
}
////////////////////////////////////////////////////////////
String KeyboardImpl::getDescription(Keyboard::Scancode code)
{
@ -428,7 +443,8 @@ 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::ScanEnter ||
if (code == Keyboard::ScanEscape ||
code == Keyboard::ScanEnter ||
code == Keyboard::ScanReturn ||
code == Keyboard::ScanTab ||
code == Keyboard::ScanDelete ||
@ -440,7 +456,7 @@ String KeyboardImpl::getDescription(Keyboard::Scancode code)
if (checkInput)
{
KeySym keysym = SFScancodeToKeySym(code);
KeySym keysym = scancodeToKeySym(code);
Uint32 unicode = keysymToUnicode(keysym);
if (unicode != 0)
@ -471,6 +487,7 @@ String KeyboardImpl::getDescription(Keyboard::Scancode code)
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::ScanCapsLock: return "CapsLock";
case Keyboard::ScanPrintScreen: return "PrintScreen";
@ -495,7 +512,7 @@ String KeyboardImpl::getDescription(Keyboard::Scancode code)
case Keyboard::ScanMinus: return "Minux (Numpad)";
case Keyboard::ScanPlus: return "Plus (Numpad)";
case Keyboard::ScanPadEquals: return "Equals (Numpad)";
case Keyboard::ScanReturn: return "Return (Numpad)";
case Keyboard::ScanReturn: return "Enter (Numpad)";
case Keyboard::ScanDecimal: return "Decimal (Numpad)";
case Keyboard::ScanNumpad0: return "0 (Numpad)";
@ -525,17 +542,16 @@ String KeyboardImpl::getDescription(Keyboard::Scancode code)
case Keyboard::ScanVolumeUp: return "Volume Up";
case Keyboard::ScanVolumeDown: return "Volume Down";
case Keyboard::ScanLControl: return "Control (Left)";
case Keyboard::ScanLShift: return "Shift (Left)";
case Keyboard::ScanLAlt: return "Alt (Left)";
case Keyboard::ScanLSystem: return "Meta (Left)";
case Keyboard::ScanRControl: return "Control (Right)";
case Keyboard::ScanRShift: return "Shift (Right)";
case Keyboard::ScanRAlt: return "Alt (Right)";
case Keyboard::ScanRSystem: return "Meta (Right)";
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.
}
return "Unknown Scancode"; // no guess good enough possible.
}
@ -549,11 +565,12 @@ Keyboard::Key KeyboardImpl::getKeyFromEvent(XKeyEvent& event)
{
// Get the SFML keyboard code from the keysym of the key that has been pressed
KeySym keysym = XLookupKeysym(&event, i);
key = keySymToSFKey(keysym);
key = keySymToKey(keysym);
if (key != Keyboard::Unknown)
break;
}
return key;
}
@ -561,8 +578,9 @@ Keyboard::Key KeyboardImpl::getKeyFromEvent(XKeyEvent& event)
////////////////////////////////////////////////////////////
Keyboard::Scancode KeyboardImpl::getScancodeFromEvent(XKeyEvent& event)
{
return keyCodeToSFScancode(event.keycode);
return keyCodeToScancode(event.keycode);
}
} // namespace priv
} // namespace sf

View File

@ -28,21 +28,19 @@
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/String.hpp>
#include <SFML/Window/Keyboard.hpp>
#include <X11/Xlib.h> // XKeyEvent
#include <X11/X.h> // Keycode
#include <X11/XKBlib.h>
namespace sf {
namespace priv {
namespace sf
{
namespace priv
{
////////////////////////////////////////////////////////////
/// \brief sf::priv::InputImpl helper
///
/// This class manage as a singleton instance the keyboard state.
/// Its purpose is to help sf::priv::InputImpl class.
/// \brief sf::priv::KeyboardImpl helper
///
/// This class implements keyboard handling functions
/// to help sf::priv::InputImpl class.
////////////////////////////////////////////////////////////
class KeyboardImpl
{