skhd icon indicating copy to clipboard operation
skhd copied to clipboard

keywords (modifiers and literals)

Open koekeishiya opened this issue 6 years ago • 31 comments

modifiers (<mod>):

fn

cmd
lcmd
rcmd

shift
lshift
rshift

alt
lalt
ralt

ctrl
lctrl
rctrl

hyper (cmd + shift + alt + ctrl)

meh (shift + alt + ctrl)

key literals:

"return"     (kVK_Return)
"tab"        (kVK_Tab)
"space"      (kVK_Space)
"backspace"  (kVK_Delete)
"escape"     (kVK_Escape)

The following keys can not be used with the fn-modifier:

"delete"     (kVK_ForwardDelete)
"home"       (kVK_Home)
"end"        (kVK_End)
"pageup"     (kVK_PageUp)
"pagedown"   (kVK_PageDown)
"insert"     (kVK_Help)
"left"       (kVK_LeftArrow)
"right"      (kVK_RightArrow)
"up"         (kVK_UpArrow)
"down"       (kVK_DownArrow)
"f1"         (kVK_F1)
"f2"         (kVK_F2)
"f3"         (kVK_F3)
"f4"         (kVK_F4)
"f5"         (kVK_F5)
"f6"         (kVK_F6)
"f7"         (kVK_F7)
"f8"         (kVK_F8)
"f9"         (kVK_F9)
"f10"        (kVK_F10)
"f11"        (kVK_F11)
"f12"        (kVK_F12)
"f13"        (kVK_F13)
"f14"        (kVK_F14)
"f15"        (kVK_F15)
"f16"        (kVK_F16)
"f17"        (kVK_F17)
"f18"        (kVK_F18)
"f19"        (kVK_F19)
"f20"        (kVK_F20)
 
"sound_up"          (NX_KEYTYPE_SOUND_UP)
"sound_down"        (NX_KEYTYPE_SOUND_DOWN)
"mute"              (NX_KEYTYPE_MUTE)
"play"              (NX_KEYTYPE_PLAY)            
"previous"          (NX_KEYTYPE_PREVIOUS)        
"next"              (NX_KEYTYPE_NEXT)
"rewind"            (NX_KEYTYPE_REWIND)          
"fast"              (NX_KEYTYPE_FAST)            
"brightness_up"     (NX_KEYTYPE_BRIGHTNESS_UP)
"brightness_down"   (NX_KEYTYPE_BRIGHTNESS_DOWN)
"illumination_up"   (NX_KEYTYPE_ILLUMINATION_UP) 
"illumination_down" (NX_KEYTYPE_ILLUMINATION_DOWN)

keycodes: apple_keyboard

OR

Launch skhd in observer mode: skhd --observe or skhd -o. Press ctrl+c to quit.

koekeishiya avatar Aug 07 '17 18:08 koekeishiya

Consider looking at cliclick as well.

dzfranklin avatar Dec 11 '17 21:12 dzfranklin

Is there any support for keys like '=' or '`' ?

Njiallu avatar Mar 23 '18 14:03 Njiallu

No idea, I've never tried to map those.

You can always map the key using its keycode though. '=' is 0x1D on my keyboard. You can find this in the pictures above, ~~or by using https://github.com/koekeishiya/cev or a similar tool.~~ Integrated into skhd: Launch as: skhd --observe or skhd -o. Press ctrl+c to quit.

koekeishiya avatar Mar 23 '18 14:03 koekeishiya

@Njiallu: '`' (~) is 0x32 on my keyboard, and

cmd - 0x32: ...

works :)

jpo-joyent avatar Sep 26 '18 21:09 jpo-joyent

For me, rshift does not work but shift does. Any clues? I am having wrist pain from using fn all the time.

janwirth avatar Aug 13 '19 15:08 janwirth

@FranzSkuffka These all work for me. Note that the order you define your binds in matters: if you define shift - x before rshift - x, the latter one will never trigger.

# shift - x : terminal-notifier -message "shift - x"
lshift - x : terminal-notifier -message "lshift - x"
rshift - x : terminal-notifier -message "rshift - x"

If you have a specific question, you should file a separate issue and add your skhdrc file.

dominiklohmann avatar Aug 13 '19 15:08 dominiklohmann

I can't seem to bind period . and comma ,:

alt - 0x2b : yabai -m window --focus north
alt - 0x2f : yabai -m window --focus east

This actually corrupts alt+0-9

rafi avatar Oct 31 '19 09:10 rafi

I can't seem to bind period . and comma ,:

alt - 0x2b : yabai -m window --focus north
alt - 0x2f : yabai -m window --focus east

This actually corrupts alt+0-9

Try writing it in capital case, i.e. 0x2B instead of 0x2b.

ysida avatar Oct 07 '20 07:10 ysida

I try to play/pause media with the f8-key (not the "picture-key") but unfortunately it doesn't work with media key trigger below. Instead I get a "z" key output. f8 : skhd --key "play"

DanielVolz avatar Nov 30 '20 02:11 DanielVolz

Thanks for the documentation! Can you pin this issue so it's easier to find?

https://docs.github.com/en/github/managing-your-work-on-github/pinning-an-issue-to-your-repository

andy-zhou avatar Feb 06 '21 19:02 andy-zhou

For reference to someone having had my same issue, when assigning the fn key to Control in System Preferences -> Keyboard -> Modifier keys, pressing fn will issue a rctrl despite the location on the keyboard.

andryandrew avatar Oct 13 '21 21:10 andryandrew

Is there a way to define any key as a modifier? or even better give it dual action? Eg if capslock is held treat it as the shift key or if f is held treat hjkl as arrow keys. I've been using https://github.com/rexroni/sdiol on Linux for a while and it's been an amazing experience and would love to have the same experience on MacOS.

update: nvm I think what I'm looking for on mac is https://karabiner-elements.pqrs.org/

here is an example of what you can do with it:

-- the f key will expose an alternate layer of the keymap when held
f_keymap = {
    -- when f is held, convert h/j/k/l to arrow keys
    KEY_H = KEY_LEFT,
    KEY_J = KEY_DOWN,
    KEY_K = KEY_UP,
    KEY_L = KEY_RIGHT,
    -- also convert u and i to left and right parentheses
    KEY_U = shift(KEY_9),
    KEY_I = shift(KEY_0),
}

root_keymap = {
    -- caps lock is way too useless of a key for your home row
    KEY_CAPSLOCK = KEY_LEFTCTRL,
    -- assign f to have different behavior on tap vs hold
    KEY_F = dual_key(KEY_F, f_keymap),
}

-- use a case-insensitive regex to identify the keyboard device(s) to grab
grab_keyboard(".*keyboard.*", root_keymap)

hamidzr avatar Oct 28 '21 06:10 hamidzr

if f is held treat hjkl as arrow keys.

I have this setup, works great:

# Arrow Keys
fn - h : skhd -k "left"
fn - j : skhd -k "down"
fn - k : skhd -k "up"
fn - l : skhd -k "right"

PhrantiK avatar Nov 01 '21 11:11 PhrantiK

I'm trying to map ctrl - insert/del/home/end/pgup/pgdw and it's not working. For example ctrl - 0x75 does nothing. Any clues? Thanks.

Edit: the literals delete and pagedown work, but home and end do not...

diocletiann avatar Apr 15 '22 15:04 diocletiann

I can't seem to bind period . and comma ,:

alt - 0x2b : yabai -m window --focus north
alt - 0x2f : yabai -m window --focus east

This actually corrupts alt+0-9

Try writing it in capital case, i.e. 0x2B instead of 0x2b.

what if it doesn't have any alphabets ?

noelzubin avatar Dec 28 '22 07:12 noelzubin

if f is held treat hjkl as arrow keys.

I have this setup, works great:

# Arrow Keys
fn - h : skhd -k "left"
fn - j : skhd -k "down"
fn - k : skhd -k "up"
fn - l : skhd -k "right"

If you are a Linux user, I would suggest this

# Arrow Keys
ctrl - b : skhd -k "left"
ctrl - n : skhd -k "down"
ctrl - p : skhd -k "up"
ctrl - f : skhd -k "right"

hellomyzn avatar Jan 29 '23 02:01 hellomyzn

Is there wa way to define chords or leader keys? Such as in VSCode, Command-K exposes a new set of key bindings, and in tmux, control-B will do the same. Can we do this in skhd?

robrecord avatar Jan 30 '23 11:01 robrecord

Is there wa way to define Chords? Such as in VSCode, Command-K exposes a new set of key bindings, and in tmux, control-B will do the same. Can we do this in skhd?

There's a support for that with "modes". I have this example in my rcfile, who knows from where now..

# add an on_enter command to the default mode
:: default : yabai -m config active_window_border_color 0xaa33bbaa
#
# defines a new mode 'test' with an on_enter command, that captures keypresses
:: test @ : yabai -m config active_window_border_color 0xff24ccaa
#
# from 'default' mode, activate mode 'test'
cmd - x ; test
#
# from 'test' mode, activate mode 'default'
test < cmd - x ; default
#
# launch a new terminal instance when in either 'default' or 'test' mode
default, test < cmd - return : open -na /Applications/Terminal.app

maricn avatar Feb 03 '23 11:02 maricn

anyone know how to map the backtick key?

davelongdev avatar Mar 21 '23 23:03 davelongdev

anyone know how to map the backtick key?

try 0x32

PhrantiK avatar Mar 22 '23 15:03 PhrantiK

anyone know how to map the backtick key?

try 0x32

thanks! got it working. 👍

davelongdev avatar Mar 22 '23 16:03 davelongdev

Hi,

I use a keyboard on Mac with the Globe key. Any idea on how to use it with SKHD ? I tried the skhd -o to get the key press associated without any result.

AxZxP avatar Jun 30 '23 13:06 AxZxP

I do get keycode: 0x3F flags: 00000000100000000000000100000000 when i hold the globe key, i’ll try mapping it later.

tshirtman avatar Jul 19 '23 15:07 tshirtman

Trying to map tab key, any ideas?

alt + TAB - h : yabai -m window --display recent; yabai -m display --focus recent

I tried to use "0x30" from keycode image and "0x30001" from observer.

thedael avatar Aug 12 '23 12:08 thedael

anyone know how to map the backtick key?

try 0x32

If anyone wonders: this pegs the shortcut to a specific physical key position. If the user changes keyboard layout, it triggers on whichever character happens to be at that physical position in the new layout. See this issue for more information

rwijtvliet avatar Oct 19 '23 19:10 rwijtvliet

Trying to map tab key, any ideas?

alt + TAB - h : yabai -m window --display recent; yabai -m display --focus recent

I tried to use "0x30" from keycode image and "0x30001" from observer.

For tab, it's just tab, i.e., lowercase. Not sure if it works trying to use tab as a modifier though.

rwijtvliet avatar Oct 19 '23 19:10 rwijtvliet

I do get keycode: 0x3F flags: 00000000100000000000000100000000 when i hold the globe key, i’ll try mapping it later.

Were you successful? I'm trying to bind the emoji-menu (globe+e) to a shortcut, but can't get it to work.

rwijtvliet avatar Nov 24 '23 17:11 rwijtvliet

As I constantly switch between Mac and Linux and have a regular "Windows" style keyboard I wanted to remap the Windows Switch from cmd tab to lalt tab.

I tried several variations but non works.

I have

# alt tab remapping
lalt - tab: skhd -k "ctrl - tab"

for a brief test I replaced it with

# alt tab remapping
lalt - tab: skhd -k "ctrl - x"

which nicely prints a x whenever I press option+tab.

What's the correct pattern to submit an lalt+tab event?

Thanks! And thanks for that great tool. I couldn't get Karabiner Elements to work due to limitations of my company.

resolved: was my issue. I swapped cmd/ctrl within MacOS. Need to skhd -k "cmd - tab"

Peter-Ries avatar Dec 14 '23 08:12 Peter-Ries

if f is held treat hjkl as arrow keys.

I have this setup, works great:

# Arrow Keys
fn - h : skhd -k "left"
fn - j : skhd -k "down"
fn - k : skhd -k "up"
fn - l : skhd -k "right"

Thank you very much!!!!!

Zdmai avatar Feb 16 '24 12:02 Zdmai