-
Notifications
You must be signed in to change notification settings - Fork 55
Keyboard inject_switch
HASUMI Hitoshi edited this page Aug 12, 2022
·
6 revisions
0.9.17+
Keyboard#inject_switch will inject a switch position in the keymap as if it was tapped:
kbd.inject_switch(0, 1)
# ^ ^col position
# |
# row positionLet's say you have a 1x4 matrix macro pad that has a rotary encoder:
kbd.init_pins(
[1],
[10, 11, 12, 13]
)
kbd.add_layer :default, %i[
KC_LEFT KC_DOWN KC_UP KC_RIGHT
]
encoder = RotaryEncoder.new(15, 16)
encoder.clockwise do
kbd.send_key :KC_VOLU
end
encoder.counterclockwise do
kbd.send_key :KC_VOLD
end
kbd.append encoderIt works. But you can also use inject_switch with "vacant" matrix:
kbd.init_pins(
- [1],
+ [1, 2], # (*)
[10, 11, 12, 13]
)
kbd.add_layer :default, %i[
KC_LEFT KC_DOWN KC_UP KC_RIGHT
+ KC_VOLU KC_VOLD KC_NO KC_NO
]
encoder = RotaryEncoder.new(15, 16)
encoder.clockwise do
- kbd.send_key :KC_VOLU
+ kbd.inject_switch(1, 0)
end
encoder.counterclockwise do
- kbd.send_key :KC_VOLD
+ kbd.inject_switch(1, 1)
end
kbd.append encoderThe advantage of this method is that you can re-assign keycodes to the encoder by VIA/Remap.
See also Rotary encoder and VIA and Remap.
Note: (*) GPIO 2 ideally should be connected to GND via a resistor though, it generally can be just floated.
- Getting started
- Keyboard features
- Keycodes (ja)
- Mouse (ja)
- Layers and mode key (ja)
- Debounce
- Composite key
- Split-type keyboard
- Keyscan matrix
- Num Lock, Caps Lock and Scroll Lock
- Useful methods that make you free
- BIOS mode
- Other features
- Examples
- Development
- Contribute to the Wiki
- FAQ