Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scancode #1235

Merged
merged 27 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9453452
Add new API for scancodes
mantognini Mar 26, 2017
edcc792
Add support of scancodes for macOS
mantognini Mar 28, 2017
81ccb8e
Handle layout changes on macOS
mantognini May 26, 2017
1d4cf02
Use Scan prefix instead of 's'
eXpl0it3r Sep 8, 2017
89a0aef
Add new API for scancodes
mantognini Mar 26, 2017
c895696
Initial Windows implementation
JonnyPtn Sep 28, 2017
8626b04
Store pointer to Display in X11InputManager
eliasdaler Mar 29, 2018
e9a1880
Refactor X11InputManager and align mappings
eliasdaler Mar 29, 2018
cf7880b
Align key mappings & refactorings
eliasdaler Apr 2, 2018
8a260d0
Align and fix mappings and general logic
eXpl0it3r Apr 15, 2020
e9946ee
Make right Alt key work on X11
kimci86 Feb 15, 2022
33a5d1d
Improve scancodeToKeycode mapping
kimci86 Feb 15, 2022
afd9705
Fix description for dead keys
kimci86 Feb 15, 2022
722210f
Make getKeyFromEvent more robust for Decimal (Numpad)
kimci86 Feb 15, 2022
17bd9f7
Use a nested struct instead of a prefix
eXpl0it3r Nov 30, 2021
20787cc
Scancode renaming leftover
kimci86 Apr 17, 2022
69f08d4
Silence clang warnings about Scancode enumeration
kimci86 Apr 17, 2022
ace865b
Avoid overwriting key to scancode mapping
kimci86 Apr 17, 2022
9244b79
Fix missing description for NumpadMinus
kimci86 Apr 20, 2022
7bdc588
Improve description for NumpadDivide
kimci86 Apr 20, 2022
e97b2ef
Add initial dummy scancode implementation on Linux (DRM)
kimci86 Jun 23, 2022
bdfd1c6
Add mapping notification support for X11
eXpl0it3r Jun 23, 2022
6d5c6f6
Revamp the macOS implementation of scancodes
kimci86 Sep 21, 2022
64b323f
Generate key events for caps lock when the modifier state changes
kimci86 Dec 17, 2022
4c39416
Rename Key::Tilde to Key::Grave
kimci86 Dec 20, 2022
7216429
Fix virtual code translation to text for dead keys on macOS
kimci86 Dec 20, 2022
84e734c
Change formatting and implement suggestions
eXpl0it3r Dec 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions include/SFML/Window/Event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ class Event
////////////////////////////////////////////////////////////
struct KeyEvent
{
Keyboard::Key code; //!< Code of the key that has been pressed
bool alt; //!< Is the Alt key pressed?
bool control; //!< Is the Control key pressed?
bool shift; //!< Is the Shift key pressed?
bool system; //!< Is the System key pressed?
Keyboard::Key code; //!< Code of the key that has been pressed
Keyboard::Scancode scancode; //!< Physical code of the key that has been pressed
bool alt; //!< Is the Alt key pressed?
bool control; //!< Is the Control key pressed?
bool shift; //!< Is the Shift key pressed?
bool system; //!< Is the System key pressed?
};

////////////////////////////////////////////////////////////
Expand Down
283 changes: 271 additions & 12 deletions include/SFML/Window/Keyboard.hpp

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions src/SFML/Window/Android/InputImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::Scan::Unknown;
}

String InputImpl::getDescription(Keyboard::Scancode /* code */)
{
// Not applicable
return "";
}

////////////////////////////////////////////////////////////
void InputImpl::setVirtualKeyboardVisible(bool visible)
{
Expand Down
30 changes: 24 additions & 6 deletions src/SFML/Window/Android/InputImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,37 @@ class InputImpl
public:

////////////////////////////////////////////////////////////
/// \brief Check if a key is pressed
/// \copydoc sf::Keyboard::isKeyPressed(Key)
///
/// \param key Key to check
////////////////////////////////////////////////////////////
static bool isKeyPressed(Keyboard::Key key);

////////////////////////////////////////////////////////////
/// \copydoc sf::Keyboard::isKeyPressed(Scancode)
///
/// \return True if the key is pressed, false otherwise
////////////////////////////////////////////////////////////
static bool isKeyPressed(Keyboard::Scancode code);

////////////////////////////////////////////////////////////
/// \copydoc sf::Keyboard::localize
///
////////////////////////////////////////////////////////////
static bool isKeyPressed(Keyboard::Key key);
static Keyboard::Key localize(Keyboard::Scancode code);

////////////////////////////////////////////////////////////
/// \brief Show or hide the virtual keyboard
/// \copydoc sf::Keyboard::delocalize
///
/// \param visible True to show, false to hide
////////////////////////////////////////////////////////////
static Keyboard::Scancode delocalize(Keyboard::Key key);

////////////////////////////////////////////////////////////
/// \copydoc sf::Keyboard::getDescription
///
////////////////////////////////////////////////////////////
static String getDescription(Keyboard::Scancode code);

////////////////////////////////////////////////////////////
/// \copydoc sf::Keyboard::setVirtualKeyboardVisible
///
////////////////////////////////////////////////////////////
static void setVirtualKeyboardVisible(bool visible);
Expand Down
2 changes: 1 addition & 1 deletion src/SFML/Window/Android/WindowImplAndroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ Keyboard::Key WindowImplAndroid::androidKeyToSF(int32_t key)
case AKEYCODE_ENTER: return Keyboard::Enter;
case AKEYCODE_DEL: return Keyboard::Backspace;
case AKEYCODE_FORWARD_DEL: return Keyboard::Delete;
case AKEYCODE_GRAVE: return Keyboard::Tilde;
case AKEYCODE_GRAVE: return Keyboard::Grave;
case AKEYCODE_MINUS: return Keyboard::Subtract;
case AKEYCODE_EQUALS: return Keyboard::Equal;
case AKEYCODE_LEFT_BRACKET: return Keyboard::LBracket;
Expand Down
6 changes: 6 additions & 0 deletions src/SFML/Window/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD OR SFML_OS_OPENBSD OR SFML_OS_NETBSD)
${SRCROOT}/Unix/ClipboardImpl.cpp
${SRCROOT}/Unix/InputImpl.cpp
${SRCROOT}/Unix/InputImpl.hpp
${SRCROOT}/Unix/KeyboardImpl.hpp
${SRCROOT}/Unix/KeyboardImpl.cpp
${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
Expand Down
38 changes: 37 additions & 1 deletion src/SFML/Window/DRM/InputImplUDev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ namespace
case KEY_L: return sf::Keyboard::L;
case KEY_SEMICOLON: return sf::Keyboard::Semicolon;
case KEY_APOSTROPHE: return sf::Keyboard::Quote;
case KEY_GRAVE: return sf::Keyboard::Tilde;
case KEY_GRAVE: return sf::Keyboard::Grave;
case KEY_LEFTSHIFT: return sf::Keyboard::LShift;
case KEY_BACKSLASH: return sf::Keyboard::Backslash;
case KEY_Z: return sf::Keyboard::Z;
Expand Down Expand Up @@ -407,6 +407,7 @@ namespace
//
event.type = inputEvent.value ? sf::Event::KeyPressed : sf::Event::KeyReleased;
event.key.code = kb;
event.key.scancode = sf::Keyboard::Scan::Unknown; // TODO: not implemented
event.key.alt = altDown();
event.key.control = controlDown();
event.key.shift = shiftDown();
Expand Down Expand Up @@ -567,6 +568,41 @@ bool InputImpl::isKeyPressed(Keyboard::Key key)
return keyMap[static_cast<std::size_t>(key)];
}

////////////////////////////////////////////////////////////
bool InputImpl::isKeyPressed(Keyboard::Scancode /* code */)
{
// TODO: not implemented
err() << "sf::Keyboard::isKeyPressed(Keyboard::Scancode) is not implemented for DRM." << std::endl;
return false;
}


////////////////////////////////////////////////////////////
Keyboard::Key InputImpl::localize(Keyboard::Scancode /* code */)
{
// TODO: not implemented
err() << "sf::Keyboard::localize is not implemented for DRM." << std::endl;
return Keyboard::Unknown;
}


////////////////////////////////////////////////////////////
Keyboard::Scancode InputImpl::delocalize(Keyboard::Key /* key */)
{
// TODO: not implemented
err() << "sf::Keyboard::delocalize is not implemented for DRM." << std::endl;
return Keyboard::Scan::Unknown;
}


////////////////////////////////////////////////////////////
String InputImpl::getDescription(Keyboard::Scancode /* code */)
{
// TODO: not implemented
err() << "sf::Keyboard::getDescription is not implemented for DRM." << std::endl;
return "";
}


////////////////////////////////////////////////////////////
void InputImpl::setVirtualKeyboardVisible(bool /*visible*/)
Expand Down
30 changes: 24 additions & 6 deletions src/SFML/Window/DRM/InputImplUDev.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,37 @@ class InputImpl
public:

////////////////////////////////////////////////////////////
/// \brief Check if a key is pressed
/// \copydoc sf::Keyboard::isKeyPressed(Key)
///
/// \param key Key to check
////////////////////////////////////////////////////////////
static bool isKeyPressed(Keyboard::Key key);

////////////////////////////////////////////////////////////
/// \copydoc sf::Keyboard::isKeyPressed(Scancode)
///
/// \return True if the key is pressed, false otherwise
////////////////////////////////////////////////////////////
static bool isKeyPressed(Keyboard::Scancode code);

////////////////////////////////////////////////////////////
/// \copydoc sf::Keyboard::localize
///
////////////////////////////////////////////////////////////
static bool isKeyPressed(Keyboard::Key key);
static Keyboard::Key localize(Keyboard::Scancode code);

////////////////////////////////////////////////////////////
/// \brief Show or hide the virtual keyboard
/// \copydoc sf::Keyboard::delocalize
///
/// \param visible True to show, false to hide
////////////////////////////////////////////////////////////
static Keyboard::Scancode delocalize(Keyboard::Key key);

////////////////////////////////////////////////////////////
/// \copydoc sf::Keyboard::getDescription
///
////////////////////////////////////////////////////////////
static String getDescription(Keyboard::Scancode code);

////////////////////////////////////////////////////////////
/// \copydoc sf::Keyboard::setVirtualKeyboardVisible
///
////////////////////////////////////////////////////////////
static void setVirtualKeyboardVisible(bool visible);
Expand Down
24 changes: 24 additions & 0 deletions src/SFML/Window/Keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
////////////////////////////////////////////////////////////
#include <SFML/Window/Keyboard.hpp>
#include <SFML/Window/InputImpl.hpp>
#include <SFML/System/String.hpp>


namespace sf
Expand All @@ -37,6 +38,29 @@ bool Keyboard::isKeyPressed(Key key)
return priv::InputImpl::isKeyPressed(key);
}

////////////////////////////////////////////////////////////
bool Keyboard::isKeyPressed(Scancode code)
{
return priv::InputImpl::isKeyPressed(code);
}

////////////////////////////////////////////////////////////
Keyboard::Key Keyboard::localize(Scancode code)
{
return priv::InputImpl::localize(code);
}

////////////////////////////////////////////////////////////
Keyboard::Scancode Keyboard::delocalize(Key key)
{
return priv::InputImpl::delocalize(key);
}

////////////////////////////////////////////////////////////
String Keyboard::getDescription(Scancode code)
{
return priv::InputImpl::getDescription(code);
}

////////////////////////////////////////////////////////////
void Keyboard::setVirtualKeyboardVisible(bool visible)
Expand Down