Skip to content

Instantly share code, notes, and snippets.

@hweetty
Last active August 29, 2015 14:13
Show Gist options
  • Select an option

  • Save hweetty/dd6418bdc76fb6655dcf to your computer and use it in GitHub Desktop.

Select an option

Save hweetty/dd6418bdc76fb6655dcf to your computer and use it in GitHub Desktop.
Show OS X emoji keyboard (simulates cmd+ctr+space)
// Make sure a textfield is focused before calling for optimal results
- (void)showEmojiKeyboard {
// http://stackoverflow.com/questions/10734349/simulate-keypress-for-system-wide-hotkeys
CGEventSourceRef src = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
CGEventRef spcd = CGEventCreateKeyboardEvent(src, 0x31, true);
CGEventRef spcu = CGEventCreateKeyboardEvent(src, 0x31, false);
CGEventSetFlags(spcd, kCGEventFlagMaskCommand | kCGEventFlagMaskControl);
CGEventSetFlags(spcu, kCGEventFlagMaskCommand | kCGEventFlagMaskControl);
CGEventTapLocation loc = kCGHIDEventTap; // kCGSessionEventTap also works
CGEventPost(loc, spcd);
CGEventPost(loc, spcu);
CFRelease(spcd);
CFRelease(spcu);
CFRelease(src);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment