Skip to content

Commit

Permalink
Align and fix mappings and general logic
Browse files Browse the repository at this point in the history
- 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'
- Update documentation
  • Loading branch information
eXpl0it3r committed Aug 12, 2021
1 parent 157e401 commit 34082e5
Show file tree
Hide file tree
Showing 21 changed files with 1,401 additions and 928 deletions.
328 changes: 175 additions & 153 deletions include/SFML/Window/Keyboard.hpp

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/SFML/Window/Android/InputImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ class InputImpl
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);
Expand Down
4 changes: 2 additions & 2 deletions src/SFML/Window/Keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

////////////////////////////////////////////////////////////
Expand Down
39 changes: 18 additions & 21 deletions src/SFML/Window/OSX/HIDInputManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,25 @@ class HIDInputManager : NonCopyable
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:

////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -205,17 +213,6 @@ class HIDInputManager : NonCopyable
////////////////////////////////////////////////////////////
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
///
Expand All @@ -233,7 +230,7 @@ class HIDInputManager : NonCopyable
///
/// \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);
Expand All @@ -254,8 +251,8 @@ class HIDInputManager : NonCopyable
/// \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);
Expand All @@ -267,7 +264,7 @@ class HIDInputManager : NonCopyable
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.
///
////////////////////////////////////////////////////////////
Expand All @@ -279,9 +276,9 @@ class HIDInputManager : NonCopyable
// 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.
Expand Down
Loading

0 comments on commit 34082e5

Please sign in to comment.