mirror of
https://github.com/SFML/SFML.git
synced 2025-01-18 23:35:11 +08:00
Add CapsLock, NumLock and ScrollLock support for Events
This commit is contained in:
parent
b56604c940
commit
9cae9491f0
@ -100,6 +100,9 @@ public:
|
||||
bool control{}; //!< Is the Control key pressed?
|
||||
bool shift{}; //!< Is the Shift key pressed?
|
||||
bool system{}; //!< Is the System key pressed?
|
||||
bool capsLock{}; //!< Is the CapsLock key toggled?
|
||||
bool numLock{}; //!< Is the NumLock key toggled? (Not supported on macOS)
|
||||
bool scrollLock{}; //!< Is the ScrollLock key toggled?
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -114,6 +117,9 @@ public:
|
||||
bool control{}; //!< Is the Control key pressed?
|
||||
bool shift{}; //!< Is the Shift key pressed?
|
||||
bool system{}; //!< Is the System key pressed?
|
||||
bool capsLock{}; //!< Is the CapsLock key toggled?
|
||||
bool numLock{}; //!< Is the NumLock key toggled? (Not supported on macOS)
|
||||
bool scrollLock{}; //!< Is the ScrollLock key toggled?
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -419,6 +419,10 @@ int WindowImplAndroid::processKeyEvent(AInputEvent* inputEvent, ActivityStates&
|
||||
keyEvent.code = androidKeyToSF(key);
|
||||
keyEvent.alt = metakey & AMETA_ALT_ON;
|
||||
keyEvent.shift = metakey & AMETA_SHIFT_ON;
|
||||
keyEvent.system = metakey & AMETA_SYM_ON;
|
||||
keyEvent.capsLock = metakey & AMETA_CAPS_LOCK_ON;
|
||||
keyEvent.numLock = metakey & AMETA_NUM_LOCK_ON;
|
||||
keyEvent.scrollLock = metakey & AMETA_SCROLL_LOCK_ON;
|
||||
forwardEvent(keyEvent);
|
||||
};
|
||||
|
||||
|
@ -91,6 +91,18 @@ bool systemDown()
|
||||
{
|
||||
return keyMap[sf::Keyboard::Key::LSystem] || keyMap[sf::Keyboard::Key::RSystem];
|
||||
}
|
||||
bool capsLockDown()
|
||||
{
|
||||
return false; // TODO: To be implemented, potentially with scancode support
|
||||
}
|
||||
bool numLockDown()
|
||||
{
|
||||
return false; // TODO: To be implemented, potentially with scancode support
|
||||
}
|
||||
bool scrollLockDown()
|
||||
{
|
||||
return false; // TODO: To be implemented, potentially with scancode support
|
||||
}
|
||||
|
||||
void uninitFileDescriptors()
|
||||
{
|
||||
@ -414,6 +426,9 @@ std::optional<sf::Event> eventProcess()
|
||||
keyEvent.control = controlDown();
|
||||
keyEvent.shift = shiftDown();
|
||||
keyEvent.system = systemDown();
|
||||
keyEvent.capsLock = capsLockDown();
|
||||
keyEvent.numLock = numLockDown();
|
||||
keyEvent.scrollLock = scrollLockDown();
|
||||
return keyEvent;
|
||||
};
|
||||
|
||||
|
@ -1809,6 +1809,9 @@ bool WindowImplX11::processEvent(XEvent& windowEvent)
|
||||
event.control = windowEvent.xkey.state & ControlMask;
|
||||
event.shift = windowEvent.xkey.state & ShiftMask;
|
||||
event.system = windowEvent.xkey.state & Mod4Mask;
|
||||
event.capsLock = windowEvent.xkey.state & LockMask;
|
||||
event.numLock = windowEvent.xkey.state & Mod2Mask;
|
||||
event.scrollLock = windowEvent.xkey.state & Mod3Mask;
|
||||
|
||||
const bool filtered = XFilterEvent(&windowEvent, None);
|
||||
|
||||
@ -1890,6 +1893,9 @@ bool WindowImplX11::processEvent(XEvent& windowEvent)
|
||||
event.control = windowEvent.xkey.state & ControlMask;
|
||||
event.shift = windowEvent.xkey.state & ShiftMask;
|
||||
event.system = windowEvent.xkey.state & Mod4Mask;
|
||||
event.capsLock = windowEvent.xkey.state & LockMask;
|
||||
event.numLock = windowEvent.xkey.state & Mod2Mask;
|
||||
event.scrollLock = windowEvent.xkey.state & Mod3Mask;
|
||||
pushEvent(event);
|
||||
|
||||
break;
|
||||
|
@ -883,10 +883,13 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
|
||||
if (m_keyRepeatEnabled || ((HIWORD(lParam) & KF_REPEAT) == 0))
|
||||
{
|
||||
Event::KeyPressed event;
|
||||
event.alt = HIWORD(GetKeyState(VK_MENU)) != 0;
|
||||
event.control = HIWORD(GetKeyState(VK_CONTROL)) != 0;
|
||||
event.shift = HIWORD(GetKeyState(VK_SHIFT)) != 0;
|
||||
event.system = HIWORD(GetKeyState(VK_LWIN)) || HIWORD(GetKeyState(VK_RWIN));
|
||||
event.alt = GetKeyState(VK_MENU) & 0x8000;
|
||||
event.control = GetKeyState(VK_CONTROL) & 0x8000;
|
||||
event.shift = GetKeyState(VK_SHIFT) & 0x8000;
|
||||
event.system = GetKeyState(VK_LWIN) & 0x8000 || GetKeyState(VK_RWIN) & 0x8000;
|
||||
event.capsLock = GetKeyState(VK_CAPITAL) & 0x0001;
|
||||
event.numLock = GetKeyState(VK_NUMLOCK) & 0x0001;
|
||||
event.scrollLock = GetKeyState(VK_SCROLL) & 0x0001;
|
||||
event.code = virtualKeyCodeToSF(wParam, lParam);
|
||||
event.scancode = toScancode(wParam, lParam);
|
||||
pushEvent(event);
|
||||
@ -899,10 +902,13 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
|
||||
case WM_SYSKEYUP:
|
||||
{
|
||||
Event::KeyReleased event;
|
||||
event.alt = HIWORD(GetKeyState(VK_MENU)) != 0;
|
||||
event.control = HIWORD(GetKeyState(VK_CONTROL)) != 0;
|
||||
event.shift = HIWORD(GetKeyState(VK_SHIFT)) != 0;
|
||||
event.system = HIWORD(GetKeyState(VK_LWIN)) || HIWORD(GetKeyState(VK_RWIN));
|
||||
event.alt = GetKeyState(VK_MENU) & 0x8000;
|
||||
event.control = GetKeyState(VK_CONTROL) & 0x8000;
|
||||
event.shift = GetKeyState(VK_SHIFT) & 0x8000;
|
||||
event.system = GetKeyState(VK_LWIN) & 0x8000 || GetKeyState(VK_RWIN) & 0x8000;
|
||||
event.capsLock = GetKeyState(VK_CAPITAL) & 0x0001;
|
||||
event.numLock = GetKeyState(VK_NUMLOCK) & 0x0001;
|
||||
event.scrollLock = GetKeyState(VK_SCROLL) & 0x0001;
|
||||
event.code = virtualKeyCodeToSF(wParam, lParam);
|
||||
event.scancode = toScancode(wParam, lParam);
|
||||
pushEvent(event);
|
||||
|
@ -63,6 +63,7 @@ struct ModifiersState
|
||||
BOOL leftControlWasDown{};
|
||||
BOOL rightControlWasDown{};
|
||||
BOOL capsLockWasOn{};
|
||||
BOOL numLockWasOn{};
|
||||
};
|
||||
|
||||
|
||||
@ -151,7 +152,8 @@ void initialiseKeyboardHelper()
|
||||
state.rightAlternateWasDown = isKeyMaskActive(modifiers, NSRightAlternateKeyMask);
|
||||
state.leftControlWasDown = isKeyMaskActive(modifiers, NSLeftControlKeyMask);
|
||||
state.rightControlWasDown = isKeyMaskActive(modifiers, NSRightControlKeyMask);
|
||||
state.capsLockWasOn = isKeyMaskActive(modifiers, NSEventModifierFlagCapsLock);
|
||||
state.capsLockWasOn = isKeyMaskActive(modifiers, NSAlphaShiftKeyMask);
|
||||
state.numLockWasOn = isKeyMaskActive(modifiers, NSNumericPadKeyMask);
|
||||
|
||||
isStateInitialized = YES;
|
||||
}
|
||||
@ -167,6 +169,9 @@ sf::Event::KeyPressed keyPressedEventWithModifiers(NSUInteger modifiers, sf::Key
|
||||
event.control = modifiers & NSControlKeyMask;
|
||||
event.shift = modifiers & NSShiftKeyMask;
|
||||
event.system = modifiers & NSCommandKeyMask;
|
||||
event.capsLock = modifiers & NSAlphaShiftKeyMask;
|
||||
event.numLock = modifiers & NSNumericPadKeyMask;
|
||||
event.scrollLock = false; // Doesn't exist on macOS
|
||||
return event;
|
||||
}
|
||||
|
||||
@ -181,6 +186,9 @@ sf::Event::KeyReleased keyReleasedEventWithModifiers(NSUInteger modifiers, sf::K
|
||||
event.control = modifiers & NSControlKeyMask;
|
||||
event.shift = modifiers & NSShiftKeyMask;
|
||||
event.system = modifiers & NSCommandKeyMask;
|
||||
event.capsLock = modifiers & NSAlphaShiftKeyMask;
|
||||
event.numLock = modifiers & NSNumericPadKeyMask;
|
||||
event.scrollLock = false; // Doesn't exist on macOS
|
||||
return event;
|
||||
}
|
||||
|
||||
@ -243,4 +251,12 @@ void handleModifiersChanged(NSUInteger modifiers, sf::priv::WindowImplCocoa& req
|
||||
sf::Keyboard::Key::Unknown,
|
||||
sf::Keyboard::Scan::CapsLock,
|
||||
requester);
|
||||
|
||||
// Handle num lock
|
||||
processOneModifier(modifiers,
|
||||
NSEventModifierFlagNumericPad,
|
||||
state.numLockWasOn,
|
||||
sf::Keyboard::Key::Unknown,
|
||||
sf::Keyboard::Scan::NumLock,
|
||||
requester);
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ TEST_CASE("[Window] sf::Event")
|
||||
const auto& textEntered = *event.getIf<sf::Event::TextEntered>();
|
||||
CHECK(textEntered.unicode == 123456);
|
||||
|
||||
event = sf::Event::KeyPressed{sf::Keyboard::Key::C, sf::Keyboard::Scan::C, true, true, true, true};
|
||||
event = sf::Event::KeyPressed{sf::Keyboard::Key::C, sf::Keyboard::Scan::C, true, true, true, true, true, true, true};
|
||||
CHECK(event.is<sf::Event::KeyPressed>());
|
||||
CHECK(event.getIf<sf::Event::KeyPressed>());
|
||||
const auto& keyPressed = *event.getIf<sf::Event::KeyPressed>();
|
||||
@ -91,8 +91,11 @@ TEST_CASE("[Window] sf::Event")
|
||||
CHECK(keyPressed.control);
|
||||
CHECK(keyPressed.shift);
|
||||
CHECK(keyPressed.system);
|
||||
CHECK(keyPressed.capsLock);
|
||||
CHECK(keyPressed.numLock);
|
||||
CHECK(keyPressed.scrollLock);
|
||||
|
||||
event = sf::Event::KeyReleased{sf::Keyboard::Key::D, sf::Keyboard::Scan::D, true, true, true, true};
|
||||
event = sf::Event::KeyReleased{sf::Keyboard::Key::D, sf::Keyboard::Scan::D, true, true, true, true, true, true, true};
|
||||
CHECK(event.is<sf::Event::KeyReleased>());
|
||||
CHECK(event.getIf<sf::Event::KeyReleased>());
|
||||
const auto& keyReleased = *event.getIf<sf::Event::KeyReleased>();
|
||||
@ -102,6 +105,9 @@ TEST_CASE("[Window] sf::Event")
|
||||
CHECK(keyReleased.control);
|
||||
CHECK(keyReleased.shift);
|
||||
CHECK(keyReleased.system);
|
||||
CHECK(keyReleased.capsLock);
|
||||
CHECK(keyReleased.numLock);
|
||||
CHECK(keyReleased.scrollLock);
|
||||
|
||||
event = sf::Event::MouseWheelScrolled{sf::Mouse::Wheel::Horizontal, 3.14f, {4, 5}};
|
||||
CHECK(event.is<sf::Event::MouseWheelScrolled>());
|
||||
|
Loading…
Reference in New Issue
Block a user