{"action":"created","issue":{"url":"https://api.github.com/repos/synergy/synergy/issues/3305","labels_url":"https://api.github.com/repos/synergy/synergy/issues/3305/labels{/name}","comments_url":"https://api.github.com/repos/synergy/synergy/issues/3305/comments","events_url":"https://api.github.com/repos/synergy/synergy/issues/3305/events","html_url":"https://github.com/synergy/synergy/issues/3305","id":45613371,"number":3305,"title":"Patch for Volume Up, Down and Mute on OSX Clients","user":{"login":"nbolton","id":313427,"avatar_url":"https://avatars.githubusercontent.com/u/313427?v=3","gravatar_id":"","url":"https://api.github.com/users/nbolton","html_url":"https://github.com/nbolton","followers_url":"https://api.github.com/users/nbolton/followers","following_url":"https://api.github.com/users/nbolton/following{/other_user}","gists_url":"https://api.github.com/users/nbolton/gists{/gist_id}","starred_url":"https://api.github.com/users/nbolton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nbolton/subscriptions","organizations_url":"https://api.github.com/users/nbolton/orgs","repos_url":"https://api.github.com/users/nbolton/repos","events_url":"https://api.github.com/users/nbolton/events{/privacy}","received_events_url":"https://api.github.com/users/nbolton/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/synergy/synergy/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2014-10-13T06:54:35Z","updated_at":"2015-02-16T02:13:12Z","closed_at":null,"body":"**Imported issue:**\n\n* Author: Douglas Mayle\n* Date: 2012-09-19 02:29:36\n* Legacy ID: 3375\n\n**Steps to reproduce:**\r\n\r\nSynergy Mac Clients do not currently support Media keys for a couple of reasons:\r\n\r\n1. The Synergy keymap is built up from keyboard layouts, and keyboard layouts don't contains multimedia keys.\r\n2. CGEventCreateKeyboardEvent is unable to create a multimedia event, probably for the same reason as above.\r\n\r\nI handle the first problem by manually adding these keys to the s_controlKeys structure.  To handle the second problem, I wrote a separate application to listen in on and serialize these multimedia events.  I then wrote a patch to build a custom event from these serialized events in the case of volume up, down, and mute.  To my knowledge, this is the only way possible to simulate these keypresses (the other solution I've seen is to watch for these keypresses, and directly interact with the sound system, which introduces all sorts of edge cases not worth dealing with)\r\n\r\nI can't see how to attach a file, so I'm pasting the contents of the patch into the 'Additional comments' section.\r\n\r\nI believe I'm leaking CFDataRef's, though since I'm unsure as to the required lifetime with regards to posting the event, I've left it as an exercise for whomever accepts this patch.  I'm not a Mac application developer, and given the number of times I press Vol Up/Down/Mute before launching, I'm okay with the leaks on my system, as long as the volume keys work.\r\n\r\n**Versions and operating systems:**\r\n\r\nI have only tested this on OSX Mountain Lion as a client, talking to a Linux (Ubuntu) server. The Linux server is running 1.4.10, and my patch was against trunk.\r\n\r\n**Temporary workarounds:**\r\n\r\nNone\r\n\r\n**Additional comments:**\r\n\r\n    Index: src/lib/platform/COSXKeyState.cpp\r\n    ===================================================================\r\n    --- src/lib/platform/COSXKeyState.cpp\t(revision 1659)\r\n    +++ src/lib/platform/COSXKeyState.cpp\t(working copy)\r\n    @@ -36,6 +36,20 @@\r\n     static const UInt32 s_superVK    = kVK_Command;\r\n     static const UInt32 s_capsLockVK = kVK_CapsLock;\r\n     static const UInt32 s_numLockVK  = kVK_ANSI_KeypadClear; // 71\r\n    +\r\n    +const UInt8 VolUp_Press[] = { 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x40, 0x35, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x40, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x37, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x02, 0xC0, 0x38, 0x44, 0x34, 0x00, 0x00, 0x44, 0x92, 0x20, 0x00, 0x00, 0x02, 0xC0, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x3A, 0xB0, 0xAB, 0x9F, 0x70, 0x00, 0x00, 0x17, 0x86, 0x00, 0x01, 0x40, 0x3B, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x40, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x6A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x6B, 0x00, 0x00, 0x07, 0x80, 0x00, 0x01, 0x40, 0x53, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0F, 0x40, 0x54, 0x00, 0x00, 0x0B, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };\r\n    +\r\n    +const UInt8 VolUp_Release[] = { 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x40, 0x35, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x40, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x37, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x02, 0xC0, 0x38, 0x44, 0x34, 0x00, 0x00, 0x44, 0x92, 0x20, 0x00, 0x00, 0x02, 0xC0, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x3A, 0xA9, 0xFE, 0x64, 0xF0, 0x00, 0x00, 0x17, 0x86, 0x00, 0x01, 0x40, 0x3B, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x40, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x6A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x6B, 0x00, 0x00, 0x07, 0x80, 0x00, 0x01, 0x40, 0x53, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0F, 0x40, 0x54, 0x00, 0x00, 0x0A, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };\r\n    +\r\n    +const UInt8 VolDown_Press[] = { 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x40, 0x35, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x40, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x37, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x02, 0xC0, 0x38, 0x43, 0xFE, 0x00, 0x00, 0x44, 0x9E, 0x00, 0x00, 0x00, 0x02, 0xC0, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x3A, 0x8C, 0x11, 0x65, 0xC0, 0x00, 0x00, 0x18, 0xCE, 0x00, 0x01, 0x40, 0x3B, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x40, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x6A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x6B, 0x00, 0x00, 0x07, 0x80, 0x00, 0x01, 0x40, 0x53, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0F, 0x40, 0x54, 0x00, 0x01, 0x0A, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };\r\n    +\r\n    +const UInt8 VolDown_Release[] = { 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x40, 0x35, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x40, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x37, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x02, 0xC0, 0x38, 0x43, 0xFE, 0x00, 0x00, 0x44, 0x9E, 0x00, 0x00, 0x00, 0x02, 0xC0, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x3A, 0x91, 0xCD, 0xB8, 0x60, 0x00, 0x00, 0x18, 0xCE, 0x00, 0x01, 0x40, 0x3B, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x40, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x6A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x6B, 0x00, 0x00, 0x07, 0x80, 0x00, 0x01, 0x40, 0x53, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0F, 0x40, 0x54, 0x00, 0x01, 0x0B, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };\r\n    +\r\n    +const UInt8 Mute_Press[] = { 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x40, 0x35, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x40, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x37, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x02, 0xC0, 0x38, 0x43, 0x99, 0x80, 0x00, 0x44, 0x5A, 0x40, 0x00, 0x00, 0x02, 0xC0, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x3A, 0x25, 0x88, 0x1E, 0xD8, 0x00, 0x00, 0x18, 0xFC, 0x00, 0x01, 0x40, 0x3B, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x40, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x6A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x6B, 0x00, 0x00, 0x07, 0x80, 0x00, 0x01, 0x40, 0x53, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0F, 0x40, 0x54, 0x00, 0x07, 0x0A, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };\r\n    +\r\n    +const UInt8 Mute_Release[] = { 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x40, 0x35, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x40, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x37, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x02, 0xC0, 0x38, 0x43, 0x99, 0x80, 0x00, 0x44, 0x5A, 0x40, 0x00, 0x00, 0x02, 0xC0, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x3A, 0x2B, 0xBA, 0x93, 0xA8, 0x00, 0x00, 0x18, 0xFC, 0x00, 0x01, 0x40, 0x3B, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x40, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x6A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x6B, 0x00, 0x00, 0x07, 0x80, 0x00, 0x01, 0x40, 0x53, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0F, 0x40, 0x54, 0x00, 0x07, 0x0B, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };\r\n    +\r\n    +\r\n     #else\r\n     // Hardcoded virtual key table on 10.4 and below.\r\n     static const UInt32 s_shiftVK    = 56;\r\n    @@ -103,6 +117,11 @@\r\n     \t{ kKeyKP_Divide,\tkVK_ANSI_KeypadDivide },\r\n     \t{ kKeyKP_Subtract,\tkVK_ANSI_KeypadMinus },\r\n     \t{ kKeyKP_Enter,\t\tkVK_ANSI_KeypadEnter },\r\n    +\r\n    +        // Multimedia keys with virtual key codes\r\n    +\t{ kKeyAudioUp,\t\tkVK_VolumeUp },\r\n    +\t{ kKeyAudioDown,\tkVK_VolumeDown },\r\n    +\t{ kKeyAudioMute,\tkVK_Mute },\r\n     #else\r\n       // Hardcoded virtual key table on 10.4 and below.\r\n     \t// cursor keys.\r\n    @@ -490,9 +509,35 @@\r\n     \t\t\tLOG((CLOG_DEBUG1 \"  %%%%%%%%03x (%%%%%%%%08x) %%%%%%%%s\", keystroke.m_data.m_button.m_button, keystroke.m_data.m_button.m_client, keystroke.m_data.m_button.m_press ? \"down\" : \"up\"));\r\n     \r\n     \t\t// let system figure out character for us\r\n    -\t\tref = CGEventCreateKeyboardEvent(0, mapKeyButtonToVirtualKey(\r\n    -\t\t\t\t\t\t\t\t\tkeystroke.m_data.m_button.m_button),\r\n    -\t\t\t\t\t\t\t\tkeystroke.m_data.m_button.m_press);\r\n    +\t\tif (mapKeyButtonToVirtualKey(keystroke.m_data.m_button.m_button) == kVK_VolumeUp) {\r\n    +\t\t\tif (keystroke.m_data.m_button.m_press) {\r\n    +\t\t\t\tCFDataRef data_press = CFDataCreate(kCFAllocatorDefault, VolUp_Press, sizeof(VolUp_Press));\r\n    +\t\t\t\tref = CGEventCreateFromData(kCFAllocatorDefault, data_press);\r\n    +\t\t\t} else {\r\n    +\t\t\t\tCFDataRef data_release = CFDataCreate(kCFAllocatorDefault, VolUp_Release, sizeof(VolUp_Release));\r\n    +\t\t\t\tref = CGEventCreateFromData(kCFAllocatorDefault, data_release);\r\n    +\t\t\t}\r\n    +\t\t} else if (mapKeyButtonToVirtualKey(keystroke.m_data.m_button.m_button) == kVK_VolumeDown) {\r\n    +\t\t\tif (keystroke.m_data.m_button.m_press) {\r\n    +\t\t\t\tCFDataRef data_press = CFDataCreate(kCFAllocatorDefault, VolDown_Press, sizeof(VolDown_Press));\r\n    +\t\t\t\tref = CGEventCreateFromData(kCFAllocatorDefault, data_press);\r\n    +\t\t\t} else {\r\n    +\t\t\t\tCFDataRef data_release = CFDataCreate(kCFAllocatorDefault, VolDown_Release, sizeof(VolDown_Release));\r\n    +\t\t\t\tref = CGEventCreateFromData(kCFAllocatorDefault, data_release);\r\n    +\t\t\t}\r\n    +\t\t} else if (mapKeyButtonToVirtualKey(keystroke.m_data.m_button.m_button) == kVK_Mute) {\r\n    +\t\t\tif (keystroke.m_data.m_button.m_press) {\r\n    +\t\t\t\tCFDataRef data_press = CFDataCreate(kCFAllocatorDefault, Mute_Press, sizeof(Mute_Press));\r\n    +\t\t\t\tref = CGEventCreateFromData(kCFAllocatorDefault, data_press);\r\n    +\t\t\t} else {\r\n    +\t\t\t\tCFDataRef data_release = CFDataCreate(kCFAllocatorDefault, Mute_Release, sizeof(Mute_Release));\r\n    +\t\t\t\tref = CGEventCreateFromData(kCFAllocatorDefault, data_release);\r\n    +\t\t\t}\r\n    +\t\t} else {\r\n    +\t\t\tref = CGEventCreateKeyboardEvent(0, mapKeyButtonToVirtualKey(\r\n    +\t\t\t\t\t\t\t\t\t\tkeystroke.m_data.m_button.m_button),\r\n    +\t\t\t\t\t\t\t\t\tkeystroke.m_data.m_button.m_press);\r\n    +\t\t}\r\n     \t\tif (ref == NULL) {\r\n     \t\t\tLOG((CLOG_CRIT \"unable to create keyboard event for keystroke\"));\r\n     \t\t}"},"comment":{"url":"https://api.github.com/repos/synergy/synergy/issues/comments/74451483","html_url":"https://github.com/synergy/synergy/issues/3305#issuecomment-74451483","issue_url":"https://api.github.com/repos/synergy/synergy/issues/3305","id":74451483,"user":{"login":"ManjotS","id":644885,"avatar_url":"https://avatars.githubusercontent.com/u/644885?v=3","gravatar_id":"","url":"https://api.github.com/users/ManjotS","html_url":"https://github.com/ManjotS","followers_url":"https://api.github.com/users/ManjotS/followers","following_url":"https://api.github.com/users/ManjotS/following{/other_user}","gists_url":"https://api.github.com/users/ManjotS/gists{/gist_id}","starred_url":"https://api.github.com/users/ManjotS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ManjotS/subscriptions","organizations_url":"https://api.github.com/users/ManjotS/orgs","repos_url":"https://api.github.com/users/ManjotS/repos","events_url":"https://api.github.com/users/ManjotS/events{/privacy}","received_events_url":"https://api.github.com/users/ManjotS/received_events","type":"User","site_admin":false},"created_at":"2015-02-16T02:13:12Z","updated_at":"2015-02-16T02:13:12Z","body":"Please fix this"}}