getreuer / qmk-keymap

My keymap & reusable QMK gems
Apache License 2.0
301 stars 45 forks source link

[Bug] LSHFT applied to SELWORD not working #39

Closed LuiFerreiraD closed 1 month ago

LuiFerreiraD commented 1 year ago

Hi, I used your select_word modification to my numpad, and it works perfectly! I am grateful for you posting helpful tricks. I just have a problem; I have a custom keycode (SELWORD) to call the function whenever it's pressed. I have another key on my layout that is LSFT(SELWORD), but when I press it, the usual select word is executed, not the select line. I am sorry if this is a basic question/issue - newbie in qmk here. I should add that I am running on MacOS Ventura, with a custom Keycrhon q0. I do have the #define MAC_HOTKEYS enabled. I really appreciate any help you can provide.

getreuer commented 8 months ago

Good question! LSFT(kc) is limited to kc being a basic keycode, which unfortunately excludes custom keycodes like SELWORD. Other compound keycodes (LCTL, MT, LT, ...) are similarly limited.

The root of the problem is that QMK represents every keycode as a 16-bit integer. When writing a compound keycode like LSFT(kc), the base keycode kc is packed along with metadata indicating the LSFT mod in the 16-bit keycode To make it all fit in 16 bits, the base keycode it limited to 8 bits.

Here is a potential workaround:

  1. Define a second custom keycode, say, SELLINE.
  2. In process_record_user(), do
bool process_record_user(uint16_t keycode, keyrecord_t* record) {
  if (!process_select_word(keycode, record, SELWORD)) { return false; }

  switch (keycode) {
    case SELLINE:
      register_mods(MOD_BIT(KC_LSFT));  // Hold LSFT.
      process_select_word(keycode, record, SELLINE);
      clear_mods();  // Release LSFT.
      return false;

    // Other macros...
  }

  return true;
}