rmk icon indicating copy to clipboard operation
rmk copied to clipboard

Built-in aliases for shifted symbols

Open alex-tdrn opened this issue 6 months ago • 2 comments

Currently, if a user wants to refer to shifted symbols in their keymap they have to write something like shifted!(Kc1) in their keymap. Of course, this is hard to read later when tweaking the keymap, without looking up what symbol that is exactly. The alternative is to manually add aliases for these keys:

pub(crate) mod shifted_aliases {
    pub const EXCLAMATION: KeyAction = shifted!(Kc1);
    pub const AT_SIGN: KeyAction = shifted!(Kc2);
    pub const HASH: KeyAction = shifted!(Kc3);
    pub const DOLLAR: KeyAction = shifted!(Kc4);
    pub const PERCENT: KeyAction = shifted!(Kc5);
    pub const CARET: KeyAction = shifted!(Kc6);
    pub const AMPERSAND: KeyAction = shifted!(Kc7);
    pub const STAR: KeyAction = shifted!(Kc8);
    pub const LEFT_ROUND_BRACKET: KeyAction = shifted!(Kc9);
    pub const RIGHT_ROUND_BRACKET: KeyAction = shifted!(Kc0);
    pub const UNDERSCORE: KeyAction = shifted!(Minus);
    pub const PLUS: KeyAction = shifted!(Equal);
    pub const LEFT_CURLY_BRACKET: KeyAction = shifted!(LeftBracket);
    pub const RIGHT_CURLY_BRACKET: KeyAction = shifted!(RightBracket);
    pub const PIPE: KeyAction = shifted!(Backslash);
    pub const COLON: KeyAction = shifted!(Semicolon);
    pub const DOUBLE_QUOTE: KeyAction = shifted!(Quote);
    pub const LEFT_ANGLED_BRACKET: KeyAction = shifted!(Comma);
    pub const RIGHT_ANGLED_BRACKET: KeyAction = shifted!(Dot);
    pub const QUESTION: KeyAction = shifted!(Slash);
    pub const TILDE: KeyAction = shifted!(Grave);
}

This has the drawback that shifted keys now look like "2nd class citizens" in the config, because of the casing.

ZMK makes no distinction between shifted and unshifted keys in its user interface, or at least offers built-in aliases for the shifted variants.

alex-tdrn avatar Jul 07 '25 18:07 alex-tdrn

if you would use config file there this is possible:

[aliases] "~"="WM(Grave, LShift)" "!"="WM(Kc1, LShift)" "@"="WM(Kc2, LShift)" "#"="WM(Kc3, LShift)" "$"="WM(Kc4, LShift)" "%"="WM(Kc5, LShift)" "^"="WM(Kc6, LShift)" "&"="WM(Kc7, LShift)" "*"="WM(Kc8, LShift)" "("="WM(Kc9, LShift)" ")"="WM(Kc0, LShift)" "-"="Minus" "_"="WM(Minus, LShift)" "="="Equal" "+"="WM(Equal, LShift)" "["="LeftBracket" "{"="WM(LeftBracket, LShift)" "]"="RightBracket" "}"="WM(RightBracket, LShift)" "\"="Backslash" "|"="WM(Backslash, LShift)" ";"="Semicolon" ":"="WM(Semicolon, LShift)" "'"="Quote" """="WM(Quote, LShift)" ","="Comma" "<"="WM(Comma, LShift)" "."="Dot" ">"="WM(Dot, LShift)" "/"="Slash" "?"="WM(Slash, LShift)"

then your keymap may look loke this:

[[layer]] name = "qwerty" keys =""" Esc Q W E R T Y U I O P LAlt OSL(sym) A S D F G H J K L @; OSM(LShift) OSM(LCtrl) Z X C V B N M @, @. @/ OSM(LGui) OSL(media) LT(shift_nav, Space) LT(num, Tab) MT(Enter, RShift) LT(nav, Backspace) LT(num, Delete) """

tib888 avatar Jul 08 '25 21:07 tib888

if you would use config file there this is possible:

[aliases] "~"="WM(Grave, LShift)" "!"="WM(Kc1, LShift)" "@"="WM(Kc2, LShift)" "#"="WM(Kc3, LShift)" "$"="WM(Kc4, LShift)" "%"="WM(Kc5, LShift)" "^"="WM(Kc6, LShift)" "&"="WM(Kc7, LShift)" "*"="WM(Kc8, LShift)" "("="WM(Kc9, LShift)" ")"="WM(Kc0, LShift)" "-"="Minus" "_"="WM(Minus, LShift)" "="="Equal" "+"="WM(Equal, LShift)" "["="LeftBracket" "{"="WM(LeftBracket, LShift)" "]"="RightBracket" "}"="WM(RightBracket, LShift)" ""="Backslash" "|"="WM(Backslash, LShift)" ";"="Semicolon" ":"="WM(Semicolon, LShift)" "'"="Quote" """="WM(Quote, LShift)" ","="Comma" "<"="WM(Comma, LShift)" "."="Dot" ">"="WM(Dot, LShift)" "/"="Slash" "?"="WM(Slash, LShift)"

then your keymap may look loke this:

[[layer]] name = "qwerty" keys =""" Esc Q W E R T Y U I O P LAlt OSL(sym) A S D F G H J K L @; OSM(LShift) OSM(LCtrl) Z X C V B N M @, @. @/ OSM(LGui) OSL(media) LT(shift_nav, Space) LT(num, Tab) MT(Enter, RShift) LT(nav, Backspace) LT(num, Delete) """

Ah good to know, thank you! that does not look too bad. I would like to use rust though, partly for macro support, which is not yet available in the config, and partly because I want to play around with some custom logic for key processing later, as well as adding support for my displays.

Anyway, the issue of aliases for shifted symbols is not that big of a deal honestly, just wanted to request it as a nice to have. But if it's unclear where/how these might fit into the codebase, this issue can be closed, no problem. I don't have a proposal for where these would fit either.

alex-tdrn avatar Jul 09 '25 20:07 alex-tdrn