pqrs-org / Karabiner-archived

Karabiner (KeyRemap4MacBook) is a powerful utility for keyboard customization.
https://pqrs.org/osx/karabiner/
The Unlicense
3.82k stars 311 forks source link

Request - Ability to trigger keypresses from command line interface #343

Closed jgillman closed 9 years ago

jgillman commented 9 years ago

I don't think this is currently possible, but it would be really handy to be able to trigger key presses from the command line interface.

In my particular use case I use the app Alfred along with their companion app Alfred Remote. They have iTunes controls built into the app which is nice, but what I REALLY want to do it be able to emulate media key presses. Right now if I'm using another app to play music (e.g. Spotify or Rdio) their iTunes integration doesn't work.

Is this a realistic idea? I'm curious if anyone else would find this useful or if I'm just totally off base and there's a simpler solution.

Example

Just as an example, I would imagine the interface would be something like:

$ karabiner trigger "MUSIC_PLAY"
# or, following the convention of private.xml
$ karabiner trigger "ConsumerKeyCode::MUSIC_PLAY"

Or maybe more explicit:

$ karabiner keyDown 0x3
$ karabiner keyUp 0x3
# or, as a convenience method that combines the two
$ karabiner keyPress 0x3
tekezo commented 9 years ago

I've added extra command line tool post-hid-event at v10.6.8. Please upgrade to the latest beta version.

How to upgrade to the latest beta version: https://pqrs.org/osx/karabiner/document.html#check-for-updates

Usage:

$ /Applications/Karabiner.app/Contents/Library/utilities/bin/post-hid-event NX_KEYTYPE_NEXT
$ /Applications/Karabiner.app/Contents/Library/utilities/bin/post-hid-event NX_KEYTYPE_PREVIOUS

Show list of keycodes

$ /Applications/Karabiner.app/Contents/Library/utilities/bin/post-hid-event 

Note: If you want to send normal key event from command line, use JXA. https://github.com/dtinth/JXA-Cookbook/wiki/System-Events

jgillman commented 9 years ago

I just updated to the latest beta (v10.6.11) via the "Check for update including beta version" button, but I don't see the post-hid-event in /Applications/Karabiner.app/Contents/Library/utilities/bin/. I do see your commit that should add the utility but for some reason it's not there.

I can try completely uninstalling and reinstalling Karabiner.

screen shot 2015-02-16 at 9 37 18 am

tekezo commented 9 years ago

Excuse me. post-hid-event was not included in recent beta versions.

I've fixed this issue at v10.6.12. Please upgrade again.

jgillman commented 9 years ago

:beers: Awesome! Works like a charm. Thank you so much for the quick turn around!