Skip to content

Commit

Permalink
Merge pull request #21 from takkanm/add_alias
Browse files Browse the repository at this point in the history
Add aliased key code as QMK
  • Loading branch information
hasumikin authored Sep 17, 2021
2 parents 7942ae5 + a11ac2c commit bc23e52
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 3 deletions.
78 changes: 75 additions & 3 deletions src/ruby/lib/keyboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,76 @@ class Keyboard
'>',
'?'
]
KC_ALIASES = {
KC_ENT: :KC_ENTER,
KC_ESC: :KC_ESCAPE,
KC_BSPC: :KC_BSPACE,
KC_SPC: :KC_SPACE,
KC_MINS: :KC_MINUS,
KC_EQL: :KC_EQUAL,
KC_LBRC: :KC_LBRACKET,
KC_RBRC: :KC_RBRACKET,
KC_BSLS: :KC_BSLASH,
# KC_NUHS: :KC_NONUS_HASH,
# KC_SCLN: :KC_SCOLON,
KC_QUOT: :KC_QUOTE,
KC_GRV: :KC_GRAVE,
KC_ZKHK: :KC_GRAVE,
KC_COMM: :KC_COMMA,
KC_SLSH: :KC_SLASH,
# KC_NUBS: :KC_NONUS_BSLASH,
# KC_CLCK: :KC_CAPSLOCK,
KC_CAPS: :KC_CAPSLOCK,
# KC_SLCK: :KC_SCROLLLOCK,
# KC_BRMD: :KC_SCROLLLOCK,
# KC_NLCK: :KC_NUMLOCK,
# KC_LCTRL: :KC_LCTL,
# KC_LSHIFT: :KC_LSFT,
# KC_LOPT: :KC_LALT,
# KC_LCMD: :KC_LGUI,
# KC_LWIN: :KC_LGUI,
# KC_RCTRL: :KC_RCTL,
# KC_RSHIFT: :KC_RSFT,
# KC_ROPT: :KC_RALT,
# KC_ALGR: :KC_RALT,
# KC_RCMD: :KC_RGUI,
# KC_RWIN: :KC_RGUI,
KC_HAEN: :KC_LANG1,
KC_HANJ: :KC_LANG2,
# KC_PSCR: :KC_PSCREEN,
# KC_PAUS: :KC_PAUSE,
# KC_BRK: :KC_PAUSE,
# KC_BRMU: :KC_PAUSE,
KC_INS: :KC_INSERT,
KC_DEL: :KC_DELETE,
KC_PGDN: :KC_PGDOWN,
KC_RGHT: :KC_RIGHT,
# KC_APP: :KC_APPLICATION,
# KC_EXEC: :KC_EXECUTE,
# KC_SLCT: :KC_SELECT,
# KC_AGIN: :KC_AGAIN,
# KC_PSTE: :KC_PASTE,
# KC_ERAS: :KC_ALT_ERASE,
# KC_CLR: :KC_CLEAR,
# KC_PSLS: :KC_KP_SLASH,
# KC_PAST: :KC_KP_ASTERISK,
# KC_PMNS: :KC_KP_MINUS,
# KC_PPLS: :KC_KP_PLUS,
# KC_PENT: :KC_KP_ENTER,
# KC_P1: :KC_KP_1,
# KC_P2: :KC_KP_2,
# KC_P3: :KC_KP_3,
# KC_P4: :KC_KP_4,
# KC_P5: :KC_KP_5,
# KC_P6: :KC_KP_6,
# KC_P7: :KC_KP_7,
# KC_P8: :KC_KP_8,
# KC_P9: :KC_KP_9,
# KC_P0: :KC_KP_0,
# KC_PDOT: :KC_KP_DOT,
# KC_PEQL: :KC_KP_EQUAL,
XXXXXXX: :KC_NO,
}
letter = nil

def initialize
Expand Down Expand Up @@ -437,6 +507,7 @@ def add_layer(name, map)
cols_size = @split ? @cols.size * 2 : @cols.size
map.each do |key|
new_map[row_index] = Array.new(@cols.size) if col_index == 0
key = KC_ALIASES[key] ? KC_ALIASES[key] : key
keycode_index = KEYCODE.index(key)
new_map[row_index][col_index] = if keycode_index
keycode_index * -1
Expand Down Expand Up @@ -475,11 +546,12 @@ def define_mode_key(key_name, param)
on_release_action = case on_release.class
when Symbol
# @type var on_release: Symbol
keycode_index = KEYCODE.index(on_release)
key = KC_ALIASES[on_release] ? KC_ALIASES[on_release] : on_release
keycode_index = KEYCODE.index(key)
if keycode_index
keycode_index * -1
elsif KEYCODE_SFT[on_release]
(KEYCODE_SFT[on_release] + 0x100) * -1
elsif KEYCODE_SFT[key]
(KEYCODE_SFT[key] + 0x100) * -1
end
when Array
# @type var on_release: Array[Symbol]
Expand Down
1 change: 1 addition & 0 deletions src/ruby/sig/keyboard.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Keyboard
KEYCODE: Array[Symbol]
KEYCODE_SFT: Hash[Symbol, Integer]
LETTER: Array[String | Symbol | nil]
KC_ALIASES: Hash[Symbol, Symbol]

@SHIFT_LETTER_OFFSET_A: Integer
@SHIFT_LETTER_OFFSET_UNDS: Integer
Expand Down

0 comments on commit bc23e52

Please sign in to comment.