diff --git a/lib/platform/CMSWindowsKeyState.cpp b/lib/platform/CMSWindowsKeyState.cpp index 788e9d5a..e675a4b8 100644 --- a/lib/platform/CMSWindowsKeyState.cpp +++ b/lib/platform/CMSWindowsKeyState.cpp @@ -925,12 +925,7 @@ CMSWindowsKeyState::getKeyMap(CKeyMap& keyMap) // deal with certain virtual keys specially switch (vk) { case VK_SHIFT: - if (MapVirtualKey(VK_RSHIFT, 0) == i) { - vk = VK_RSHIFT; - } - else { - vk = VK_LSHIFT; - } + vk = VK_LSHIFT; break; case VK_CONTROL: diff --git a/lib/platform/COSXKeyState.cpp b/lib/platform/COSXKeyState.cpp index 13b5f149..4ac5cb18 100644 --- a/lib/platform/COSXKeyState.cpp +++ b/lib/platform/COSXKeyState.cpp @@ -119,6 +119,12 @@ static const CKeyEntry s_controlKeys[] = { COSXKeyState::COSXKeyState() : m_deadKeyState(0) { + // initialize modifier key values + shiftPressed = false; + controlPressed = false; + altPressed = false; + superPressed = false; + capsPressed = false; // build virtual key map for (size_t i = 0; i < sizeof(s_controlKeys) / @@ -379,6 +385,27 @@ COSXKeyState::fakeKey(const Keystroke& keystroke) LOG((CLOG_CRIT "unable to create keyboard event for keystroke")); } + UInt32 vk = mapKeyButtonToVirtualKey(keystroke.m_data.m_button.m_button); + UInt32 modifierDown = keystroke.m_data.m_button.m_press; + + // check the key for specials and store the value (persistent until changed) + if (vk == s_shiftVK) shiftPressed=modifierDown; + if (vk == s_controlVK) controlPressed=modifierDown; + if (vk == s_altVK) altPressed=modifierDown; + if (vk == s_superVK) superPressed=modifierDown; + if (vk == s_capsLockVK) capsPressed=modifierDown; + + //Set the event flags for special keys - see following link: + //http://stackoverflow.com/questions/2008126/cgeventpost-possible-bug-when-simulating-keyboard-events + CGEventFlags modifiers = 0; + if (shiftPressed) modifiers |= kCGEventFlagMaskShift; + if (controlPressed) modifiers |= kCGEventFlagMaskControl; + if (altPressed) modifiers |= kCGEventFlagMaskAlternate; + if (superPressed) modifiers |= kCGEventFlagMaskCommand; + if (capsPressed) modifiers |= kCGEventFlagMaskAlphaShift; + + CGEventSetFlags(ref, modifiers); + CGEventPost(kCGHIDEventTap, ref); // add a delay if client data isn't zero diff --git a/lib/platform/COSXKeyState.h b/lib/platform/COSXKeyState.h index d1f4db8a..3066131f 100644 --- a/lib/platform/COSXKeyState.h +++ b/lib/platform/COSXKeyState.h @@ -201,6 +201,13 @@ private: mutable UInt32 m_deadKeyState; GroupList m_groups; GroupMap m_groupMap; + + // Hold the current state of modifier keys + bool shiftPressed; + bool controlPressed; + bool altPressed; + bool superPressed; + bool capsPressed; }; #endif diff --git a/lib/platform/CXWindowsScreen.cpp b/lib/platform/CXWindowsScreen.cpp index 18ac37d5..eda9927a 100644 --- a/lib/platform/CXWindowsScreen.cpp +++ b/lib/platform/CXWindowsScreen.cpp @@ -107,10 +107,11 @@ CXWindowsScreen::CXWindowsScreen(const char* displayName, bool isPrimary, int mo s_screen = this; // initializes Xlib support for concurrent threads. - if (XInitThreads() == 0) - { - throw XArch("XInitThreads() returned zero"); - } + // ...which breaks badly on RHEL for some reason, upstream #194 + //if (XInitThreads() == 0) + //{ + // throw XArch("XInitThreads() returned zero"); + //} // set the X I/O error handler so we catch the display disconnecting