mirror of
https://github.com/firewalkwithm3/qmk_firmware.git
synced 2024-11-22 11:30:30 +08:00
Generate switch statement helpers for keycode ranges (#20059)
This commit is contained in:
parent
fbbb221a31
commit
b31426252e
|
@ -94,6 +94,14 @@ def _generate_helpers(lines, keycodes):
|
|||
hi = keycodes["keycodes"][f'0x{codes[1]:04X}']['key']
|
||||
lines.append(f'#define IS_{ _translate_group(group).upper() }_KEYCODE(code) ((code) >= {lo} && (code) <= {hi})')
|
||||
|
||||
lines.append('')
|
||||
lines.append('// Switch statement Helpers')
|
||||
for group, codes in temp.items():
|
||||
lo = keycodes["keycodes"][f'0x{codes[0]:04X}']['key']
|
||||
hi = keycodes["keycodes"][f'0x{codes[1]:04X}']['key']
|
||||
name = f'{ _translate_group(group).upper() }_KEYCODE_RANGE'
|
||||
lines.append(f'#define { name.ljust(35) } {lo} ... {hi}')
|
||||
|
||||
|
||||
def _generate_aliases(lines, keycodes):
|
||||
# Work around ChibiOS ch.h include guard
|
||||
|
|
|
@ -1420,3 +1420,25 @@ enum qk_keycode_defines {
|
|||
#define IS_QUANTUM_KEYCODE(code) ((code) >= QK_BOOTLOADER && (code) <= QK_ALT_REPEAT_KEY)
|
||||
#define IS_KB_KEYCODE(code) ((code) >= QK_KB_0 && (code) <= QK_KB_31)
|
||||
#define IS_USER_KEYCODE(code) ((code) >= QK_USER_0 && (code) <= QK_USER_31)
|
||||
|
||||
// Switch statement Helpers
|
||||
#define INTERNAL_KEYCODE_RANGE KC_NO ... KC_TRANSPARENT
|
||||
#define BASIC_KEYCODE_RANGE KC_A ... KC_EXSEL
|
||||
#define SYSTEM_KEYCODE_RANGE KC_SYSTEM_POWER ... KC_SYSTEM_WAKE
|
||||
#define CONSUMER_KEYCODE_RANGE KC_AUDIO_MUTE ... KC_LAUNCHPAD
|
||||
#define MOUSE_KEYCODE_RANGE KC_MS_UP ... KC_MS_ACCEL2
|
||||
#define MODIFIER_KEYCODE_RANGE KC_LEFT_CTRL ... KC_RIGHT_GUI
|
||||
#define SWAP_HANDS_KEYCODE_RANGE QK_SWAP_HANDS_TOGGLE ... QK_SWAP_HANDS_ONE_SHOT
|
||||
#define MAGIC_KEYCODE_RANGE QK_MAGIC_SWAP_CONTROL_CAPS_LOCK ... QK_MAGIC_TOGGLE_ESCAPE_CAPS_LOCK
|
||||
#define MIDI_KEYCODE_RANGE QK_MIDI_ON ... QK_MIDI_PITCH_BEND_UP
|
||||
#define SEQUENCER_KEYCODE_RANGE QK_SEQUENCER_ON ... QK_SEQUENCER_STEPS_CLEAR
|
||||
#define JOYSTICK_KEYCODE_RANGE QK_JOYSTICK_BUTTON_0 ... QK_JOYSTICK_BUTTON_31
|
||||
#define PROGRAMMABLE_BUTTON_KEYCODE_RANGE QK_PROGRAMMABLE_BUTTON_1 ... QK_PROGRAMMABLE_BUTTON_32
|
||||
#define AUDIO_KEYCODE_RANGE QK_AUDIO_ON ... QK_AUDIO_VOICE_PREVIOUS
|
||||
#define STENO_KEYCODE_RANGE QK_STENO_BOLT ... QK_STENO_COMB_MAX
|
||||
#define MACRO_KEYCODE_RANGE QK_MACRO_0 ... QK_MACRO_31
|
||||
#define BACKLIGHT_KEYCODE_RANGE QK_BACKLIGHT_ON ... QK_BACKLIGHT_TOGGLE_BREATHING
|
||||
#define RGB_KEYCODE_RANGE RGB_TOG ... RGB_MODE_TWINKLE
|
||||
#define QUANTUM_KEYCODE_RANGE QK_BOOTLOADER ... QK_ALT_REPEAT_KEY
|
||||
#define KB_KEYCODE_RANGE QK_KB_0 ... QK_KB_31
|
||||
#define USER_KEYCODE_RANGE QK_USER_0 ... QK_USER_31
|
||||
|
|
|
@ -59,19 +59,19 @@ action_t action_for_keycode(uint16_t keycode) {
|
|||
(void)mod;
|
||||
|
||||
switch (keycode) {
|
||||
case KC_A ... KC_EXSEL:
|
||||
case KC_LEFT_CTRL ... KC_RIGHT_GUI:
|
||||
case BASIC_KEYCODE_RANGE:
|
||||
case MODIFIER_KEYCODE_RANGE:
|
||||
action.code = ACTION_KEY(keycode);
|
||||
break;
|
||||
#ifdef EXTRAKEY_ENABLE
|
||||
case KC_SYSTEM_POWER ... KC_SYSTEM_WAKE:
|
||||
case SYSTEM_KEYCODE_RANGE:
|
||||
action.code = ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(keycode));
|
||||
break;
|
||||
case KC_AUDIO_MUTE ... KC_LAUNCHPAD:
|
||||
case CONSUMER_KEYCODE_RANGE:
|
||||
action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(keycode));
|
||||
break;
|
||||
#endif
|
||||
case KC_MS_UP ... KC_MS_ACCEL2:
|
||||
case MOUSE_KEYCODE_RANGE:
|
||||
action.code = ACTION_MOUSEKEY(keycode);
|
||||
break;
|
||||
case KC_TRANSPARENT:
|
||||
|
|
Loading…
Reference in a new issue