diff --git a/OSXvnc-server/VNCServer.h b/OSXvnc-server/VNCServer.h index 001ec8d..b226561 100644 --- a/OSXvnc-server/VNCServer.h +++ b/OSXvnc-server/VNCServer.h @@ -33,6 +33,7 @@ // This flag will try to change the modifier key state to the required set for the unicode key that came in BOOL pressModsForKeys; CGEventSourceRef vncSourceRef; + CGEventSourceRef specialKeysVncSourceRef; CGEventTapLocation vncTapLocation; TISInputSourceRef unicodeInputSource; diff --git a/OSXvnc-server/VNCServer.m b/OSXvnc-server/VNCServer.m index 63227e7..2401c73 100644 --- a/OSXvnc-server/VNCServer.m +++ b/OSXvnc-server/VNCServer.m @@ -375,6 +375,7 @@ - (void) rfbRunning { // Doesn't combine with any other sources NSLog(@"Using Private Event Source"); vncSourceRef = CGEventSourceCreate(kCGEventSourceStatePrivate); + specialKeysVncSourceRef = CGEventSourceCreate(kCGEventSourceStateHIDSystemState); break; case 1: // Combines only with other User Session Events @@ -761,7 +762,13 @@ - (void) sendKeyEvent: (CGKeyCode) keyCode down: (BOOL) down modifiers: (CGEvent CFRelease(event); } else { - CGEventRef event = CGEventCreateKeyboardEvent(vncSourceRef, keyCode, down); + CGEventRef event; + int specialKeysStartingFrom = 96; + if (specialKeysVncSourceRef != NULL && keyCode >= specialKeysStartingFrom){ + event = CGEventCreateKeyboardEvent(specialKeysVncSourceRef, keyCode, down); + }else { + event = CGEventCreateKeyboardEvent(vncSourceRef, keyCode, down); + } // The value of this function escapes me (since you still need to specify the keyCode for it to work // CGEventKeyboardSetUnicodeString (event, 1, (const UniChar *) &keySym);