mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 14:21:04 +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
|
||||
////////////////////////////////////////////////////////////
|
||||
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::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
|
||||
|
@ -562,6 +562,13 @@ bool HIDInputManager::isKeyPressed(Keyboard::Key key)
|
||||
////////////////////////////////////////////////////////////
|
||||
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]);
|
||||
}
|
||||
|
||||
@ -716,7 +723,6 @@ HIDInputManager::HIDInputManager()
|
||||
}
|
||||
|
||||
// Build up our knowledge of the hardware
|
||||
initializeKeyboard();
|
||||
buildMappings();
|
||||
|
||||
// Register for notification on keyboard layout changes
|
||||
@ -924,6 +930,8 @@ void HIDInputManager::freeUp()
|
||||
|
||||
m_manager = nil;
|
||||
|
||||
if (m_keysInitialized)
|
||||
{
|
||||
for (auto& key : m_keys)
|
||||
{
|
||||
for (IOHIDElementRef iohidElementRef : key)
|
||||
@ -932,6 +940,8 @@ void HIDInputManager::freeUp()
|
||||
key.clear();
|
||||
}
|
||||
}
|
||||
m_keysInitialized = false;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
Loading…
Reference in New Issue
Block a user