Distinguishing between L_COMMAND and R_COMMAND in hotkeys

203 views
Skip to first unread message

da...@thedavid.co.uk

unread,
May 17, 2015, 7:20:36 AM5/17/15
to hamme...@googlegroups.com
I have a hyper modifier key defined (as cmd+opt+ctrl+shift) and mapped to 'esc', as in this article:
http://larryhynes.net/2015/02/switching-from-slate-to-hammerspoon.html

I'd like to be able to use other modifier keys with hyper, (e.g. hyper+cmd+j) which is tricky since cmd is already part of the hyper key combination. 

One way of doing this would be to use right cmd in the hyper key combination (r_cmd+opt+ctrl+shift), and then check whether left cmd was also held down.

The problem is that the hotkey module (and the carbon APIs it is based on) don't seem to distinguish between left and right cmd. Is there a way of doing so?

Chris Jones

unread,
May 20, 2015, 1:09:34 PM5/20/15
to da...@thedavid.co.uk, hamme...@googlegroups.com
Hi

On 17 May 2015 at 04:20, <da...@thedavid.co.uk> wrote:
The problem is that the hotkey module (and the carbon APIs it is based on) don't seem to distinguish between left and right cmd.

You are correct, the Carbon API does not expose which precise key was pressed, unfortunately.
 
Is there a way of doing so?

Yes, in a manner of speaking. There's no quick and easy way to do it, but it's useful enough to me that I did come up with a way to do it.

https://gist.github.com/7a83ee1a9be3b48bc2ac is my private.xml for Karabiner - what I did was define Hyper to use the right hand cmd/ctrl/alt/shift keys, then individually bind the hyper+modifier+key combinations that I want, to URLs, which Karabiner can directly trigger. If you switch up to the current pre-release version of Karabiner, it can dispatch the URLs in the background so Hammerspoon doesn't get focussed.
Then, my Hammerspoon config is: https://github.com/cmsj/hammerspoon-config/blob/master/init.lua so you can see how binding the URL events is pretty much the same as binding keyboard hotkeys.

Simple ;)

Cheers,

Chris
--
Cheers,

Chris
Reply all
Reply to author
Forward
0 new messages