mirror of
https://github.com/SFML/SFML.git
synced 2024-12-01 07:41:05 +08:00
Use lazy loading for keyboard scancodes on macos
This commit is contained in:
parent
20b048fb08
commit
6bcc3414fc
@ -287,6 +287,7 @@ private:
|
|||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
IOHIDManagerRef m_manager{}; ///< Underlying HID Manager
|
IOHIDManagerRef m_manager{}; ///< Underlying HID Manager
|
||||||
|
bool m_keysInitialized{}; ///< Has initializeKeyboard been called at least once?
|
||||||
EnumArray<Keyboard::Scancode, IOHIDElements, Keyboard::ScancodeCount> m_keys; ///< All the keys on any connected keyboard
|
EnumArray<Keyboard::Scancode, IOHIDElements, Keyboard::ScancodeCount> m_keys; ///< All the keys on any connected keyboard
|
||||||
EnumArray<Keyboard::Key, Keyboard::Scancode, Keyboard::KeyCount> m_keyToScancodeMapping{}; ///< Mapping from Key to Scancode
|
EnumArray<Keyboard::Key, Keyboard::Scancode, Keyboard::KeyCount> m_keyToScancodeMapping{}; ///< Mapping from Key to Scancode
|
||||||
EnumArray<Keyboard::Scancode, Keyboard::Key, Keyboard::ScancodeCount> m_scancodeToKeyMapping{}; ///< Mapping from Scancode to Key
|
EnumArray<Keyboard::Scancode, Keyboard::Key, Keyboard::ScancodeCount> m_scancodeToKeyMapping{}; ///< Mapping from Scancode to Key
|
||||||
|
@ -562,6 +562,13 @@ bool HIDInputManager::isKeyPressed(Keyboard::Key key)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool HIDInputManager::isKeyPressed(Keyboard::Scancode code)
|
bool HIDInputManager::isKeyPressed(Keyboard::Scancode code)
|
||||||
{
|
{
|
||||||
|
// Lazy load m_keys to prevent unnecessary macOS input monitoring permission requests
|
||||||
|
if (!m_keysInitialized)
|
||||||
|
{
|
||||||
|
initializeKeyboard();
|
||||||
|
m_keysInitialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
return (code != Keyboard::Scan::Unknown) && isPressed(m_keys[code]);
|
return (code != Keyboard::Scan::Unknown) && isPressed(m_keys[code]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -716,7 +723,6 @@ HIDInputManager::HIDInputManager()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Build up our knowledge of the hardware
|
// Build up our knowledge of the hardware
|
||||||
initializeKeyboard();
|
|
||||||
buildMappings();
|
buildMappings();
|
||||||
|
|
||||||
// Register for notification on keyboard layout changes
|
// Register for notification on keyboard layout changes
|
||||||
@ -924,6 +930,8 @@ void HIDInputManager::freeUp()
|
|||||||
|
|
||||||
m_manager = nil;
|
m_manager = nil;
|
||||||
|
|
||||||
|
if (m_keysInitialized)
|
||||||
|
{
|
||||||
for (auto& key : m_keys)
|
for (auto& key : m_keys)
|
||||||
{
|
{
|
||||||
for (IOHIDElementRef iohidElementRef : key)
|
for (IOHIDElementRef iohidElementRef : key)
|
||||||
@ -931,6 +939,8 @@ void HIDInputManager::freeUp()
|
|||||||
|
|
||||||
key.clear();
|
key.clear();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
m_keysInitialized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user