issue #18 - Sticky modifier/meta keys

- improved on Mac.
This commit is contained in:
jerry 2014-07-02 13:25:49 +00:00
parent 547d99f7af
commit 995730a646
3 changed files with 44 additions and 1 deletions

View File

@ -458,6 +458,47 @@ COSXKeyState::pollPressedKeys(KeyButtonSet& pressedKeys) const
} }
} }
void
COSXKeyState::fixStickyKeys()
{
KeyModifierMask synergyMask = getActiveModifiers();
KeyModifierMask hardwareMask = pollActiveModifiers();
if (synergyMask != hardwareMask) {
// modifier key stuck
// compute changed modifiers
KeyModifierMask changed = (hardwareMask ^ synergyMask);
if (changed) {
KeyButton kb;
CString keyFixed;
// synthesize changed modifier keys
if ((changed & KeyModifierShift) != 0) {
kb = mapVirtualKeyToKeyButton(s_shiftVK);
fakeKeyUp(kb);
keyFixed.append("shift ");
}
if ((changed & KeyModifierControl) != 0) {
kb = mapVirtualKeyToKeyButton(s_controlVK);
fakeKeyUp(kb);
keyFixed.append("ctrl ");
}
if ((changed & KeyModifierAlt) != 0) {
kb = mapVirtualKeyToKeyButton(s_altVK);
fakeKeyUp(kb);
keyFixed.append("alt ");
}
if ((changed & KeyModifierSuper) != 0) {
kb = mapVirtualKeyToKeyButton(s_superVK);
fakeKeyUp(kb);
keyFixed.append("cmd ");
}
LOG((CLOG_DEBUG "fixed stuck modifier key: %s", keyFixed.c_str()));
}
}
}
void void
COSXKeyState::getKeyMap(CKeyMap& keyMap) COSXKeyState::getKeyMap(CKeyMap& keyMap)
{ {

View File

@ -99,7 +99,7 @@ public:
pollActiveModifiers() const; pollActiveModifiers() const;
virtual SInt32 pollActiveGroup() const; virtual SInt32 pollActiveGroup() const;
virtual void pollPressedKeys(KeyButtonSet& pressedKeys) const; virtual void pollPressedKeys(KeyButtonSet& pressedKeys) const;
void fixStickyKeys();
protected: protected:
// CKeyState overrides // CKeyState overrides
virtual void getKeyMap(CKeyMap& keyMap); virtual void getKeyMap(CKeyMap& keyMap);

View File

@ -527,6 +527,8 @@ COSXScreen::postMouseEvent(CGPoint& pos) const
void void
COSXScreen::fakeMouseButton(ButtonID id, bool press) COSXScreen::fakeMouseButton(ButtonID id, bool press)
{ {
m_keyState->fixStickyKeys();
NXEventHandle handle = NXOpenEventStatus(); NXEventHandle handle = NXOpenEventStatus();
double clickTime = NXClickTime(handle); double clickTime = NXClickTime(handle);