Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keywords (modifiers and literals) #1

Open
koekeishiya opened this issue Aug 7, 2017 · 34 comments
Open

keywords (modifiers and literals) #1

koekeishiya opened this issue Aug 7, 2017 · 34 comments

Comments

@koekeishiya
Copy link
Owner

koekeishiya commented Aug 7, 2017

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.

@dzfranklin
Copy link

Consider looking at cliclick as well.

@Njiallu
Copy link

Njiallu commented Mar 23, 2018

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

@koekeishiya
Copy link
Owner Author

koekeishiya commented Mar 23, 2018

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.

@jpo-joyent
Copy link

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

cmd - 0x32: ...

works :)

@janwirth
Copy link

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

@dominiklohmann
Copy link

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

@rafi
Copy link

rafi commented Oct 31, 2019

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

@ysida
Copy link

ysida commented Oct 7, 2020

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.

@DanielVolz
Copy link

DanielVolz commented Nov 30, 2020

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"

@andy-zhou
Copy link

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

@andryandrew
Copy link

andryandrew commented Oct 13, 2021

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.

@hamidzr
Copy link

hamidzr commented Oct 28, 2021

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)

@PhrantiK
Copy link

PhrantiK commented Nov 1, 2021

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"

@diocletiann
Copy link

diocletiann commented Apr 15, 2022

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

@noelzubin
Copy link

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 ?

@hellomyzn
Copy link

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"

@robrecord
Copy link

robrecord commented Jan 30, 2023

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?

@maricn
Copy link

maricn commented Feb 3, 2023

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

@davelongdev
Copy link

anyone know how to map the backtick key?

@PhrantiK
Copy link

anyone know how to map the backtick key?

try 0x32

@davelongdev
Copy link

anyone know how to map the backtick key?

try 0x32

thanks! got it working. 👍

@AxZxP
Copy link

AxZxP commented Jun 30, 2023

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.

@tshirtman
Copy link

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

@thedael
Copy link

thedael commented Aug 12, 2023

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.

@rwijtvliet
Copy link

rwijtvliet commented Oct 19, 2023

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
Copy link

rwijtvliet commented Oct 19, 2023

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
Copy link

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.

@Peter-Ries
Copy link

Peter-Ries commented Dec 14, 2023

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"

@Zdmai
Copy link

Zdmai commented Feb 16, 2024

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

@rainzm
Copy link

rainzm commented Apr 1, 2024

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

@Zdmai
Copy link

Zdmai commented Apr 1, 2024

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

yeah!!! compare to karabiner

@zerogtiger
Copy link

How can I defined multiple letter keys to perform an action? For instance, only perform an action if lctrl + D + H is pressed?

@kerryj89
Copy link

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

Exactly the same for me.

@martinengelke
Copy link

martinengelke commented Dec 12, 2024

I discovered a nifty trick, which is maybe not intended to be like that but can be quite useful:
fn works as mod as well as key if you use the 0xB3 instead the literal
If you then set capslock to fn in macOS settings you can then use capslock as escape key as well as a modifier.

e.g.:

0xB3 : skhd -k escape
lcmd - 0xB3 ; tiling
fn - c :    echo "hello capslock"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests