koekeishiya / skhd

Simple hotkey daemon for macOS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

keywords (modifiers and literals)

koekeishiya opened this issue · 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.

Consider looking at cliclick as well.

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

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.

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

cmd - 0x32: ...

works :)

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

@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.

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

commented

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.

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"

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

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.

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)

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"

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...

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 ?

commented

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"

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?

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

anyone know how to map the backtick key?

anyone know how to map the backtick key?

try 0x32

anyone know how to map the backtick key?

try 0x32

thanks! got it working. 👍

commented

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.

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

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.

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

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.

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.

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"

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!!!!!

@hellomyzn @Zdmai Hi, can you feel the delay of the simulated keypress?

@hellomyzn @Zdmai Hi, can you feel the delay of the simulated keypress?

yeah!!! compare to karabiner