zmkfirmware / zmk

ZMK Firmware Repository
https://zmk.dev/
MIT License
2.64k stars 2.71k forks source link

Can't get SHIFT-SPACE to issue TAB (with karabiner elements) #1685

Open yanshay opened 1 year ago

yanshay commented 1 year ago

I am trying to get SPACE function as TAB when pressing SHIFT-SPACE. I am using mod morph as follows:

    spc_tab: space_tab {
            compatible = "zmk,behavior-mod-morph";
            label = "SPACE-TAB";
            #binding-cells = <0>;
            bindings = <&kp SPACE>, <&kp TAB>;
            mods = <(MOD_LSFT)>;
        };

However it issues a SHIFT-TAB and not a TAB. This is what I see in karabiner event viewe:

  {
    "type": "down",
    "name": {"key_code":"left_shift"},
    "usagePage": "7 (0x0007)",
    "usage": "225 (0x00e1)",
    "misc": "flags left_shift"
  },
  {
    "type": "down",
    "name": {"key_code":"tab"},
    "usagePage": "7 (0x0007)",
    "usage": "43 (0x002b)",
    "misc": "flags left_shift"  <--
  },
  {
    "type": "up",
    "name": {"key_code":"left_shift"},
    "usagePage": "7 (0x0007)",
    "usage": "225 (0x00e1)",
    "misc": ""
  },
  {
    "type": "up",
    "name": {"key_code":"tab"},
    "usagePage": "7 (0x0007)",
    "usage": "43 (0x002b)",
    "misc": ""
  },

I even tried adding keep-mods = <0>; and it didnt change a thing. so why is the mod being sent together with the key? it practically means I cant get to issue TAB using SHIFT-SPACE.

I just noticed this happens only on the first TAB, the following ones dont show the left_shift flag even though the SHIFT is still pressed

  {
    "type": "down",
    "name": {"key_code":"tab"},
    "usagePage": "7 (0x0007)",
    "usage": "43 (0x002b)",
    "misc": ""
  },
  {
    "type": "up",
    "name": {"key_code":"tab"},
    "usagePage": "7 (0x0007)",
    "usage": "43 (0x002b)",
    "misc": ""
  },

I also need to mention that the shift itself is coming from &mt LSHIFT ESC

caksoylar commented 1 year ago

This came up a couple of times in the Discord server, but only seems to be related to KA360 Pro somehow, e.g. https://discord.com/channels/719497620560543766/1055137812481060884/1055137812481060884. There is a corresponding issue at https://github.com/KinesisCorporation/Adv360-Pro-ZMK/issues/83. One thing I might try since those issues came up is disabling NKRO since that is one difference I noticed between usual ZMK setups and KA360.

yanshay commented 1 year ago

I tried disabling NKRO and it didn't help.

To make sure I disabled properly, I am building locally using podman and changed that flag from 'y' to 'n' on both left and right keyboards in the local files.

Any other ideas?

ReFil commented 1 year ago

I maintain the adv360 pro firmware, no idea why this is happening as all the keys and macro stuff is straight from ZMK main, there's only changes to the RGB code to add a couple unique effects, and minor tweaks to split connection handling.

There's currently an open PR #1454 to add support for the ADV360 Pro in zmk main. @yanshay maybe try adding your macro to that firmware and trying again to see if it's the changes made to the zmk branch or a problem in the configuration files?

yanshay commented 1 year ago

There's currently an open PR #1454 to add support for the ADV360 Pro in zmk main. @yanshay maybe try adding your macro to that firmware and trying again to see if it's the changes made to the zmk branch or a problem in the configuration files?

@ReFil Happy to try, how do I do that? I only know how to use the Advantage-ZMK-Pro repo which includes only configuration. I tried pointing to the branch in the west.yaml (and I'm building locally using podman) and got an error devicetree error: /app/config/adv360.keymap:111 (column 47): parse error: expected number or parenthesized expression, especially since my config file doesn't have so many lines, so I'm probably doing something wrong.

Can you guide me how to build a firmware based on that branch with my config?

ReFil commented 1 year ago

Apologies, i thought i typed out a guide but it must have not posted or something.

It's easiest if you use the VSCode and Docker method detailed on the ZMK docs, you can follow this guide: https://zmk.dev/docs/development/setup

Once you get to "Get source code" Use this link instead: https://github.com/ReFil/zmk.git and then type git checkout advantage360

Once this is complete you want to add your macro that doesnt work into the keymap for the new board definition. you want to go to the directory you cloned in the "Get source code step" go to zmk folder/app/boards/arm/adv360pro/adv360pro.keymap

Do not just copy the keymap file from your config repo, the custom branch has some keys that are not compatible, that is why your compilation with podman didn't work.

yanshay commented 1 year ago

@ReFil Thanks, I'll try that. In the mean time I did some more research and tried using urob https://github.com/urob/adv360-demo-config. What's strange is that while in Karabiner Event Viewer the events are the same, the actual behavior of the Tab using Shift-Space there is correct (so the way Tab should behave, for example in the Terminal) while with the standard Advantage Pro it is not (behaves differently, different to explain exactly what it does). Are there elements of the keystrokes that are not shown in Karabiner Event Viewer?

yanshay commented 1 year ago

@ReFil I managed to build, I hope I did it correctly, the symptoms are the same. Shift + Mod-Morph on first press cause a shift to be sent (bug) and the second press isn't shifted (functions correctly). With Urbo repo this doesn't happen.

Does it mean it's a bug with zmk and on all keyboards? Or something to do with the Advantage Pro 360 zmk configurations?

ReFil commented 1 year ago

If it doesn't happen on the urob repo it sounds like there's a problem with the config files. I will continue to investigate

yanshay commented 1 year ago

@ReFil I made some progress here. It seems like the issue has to do with Karabiner Elements and not with urob repo vs. other zmk. When in karabiner elements in the devices page I have "Modify events" enabled then the faulty behavior takes place. Without it enabled it works as expected. For some reason when I switched to urob generated firmware (which caused a need to reset bluetooth settings) that toggle got disabled. However, this doesn't solve my problem since once I disable it karabiner stops processing keyboard events and I loose configurations. Note that this happens also when I clean all my configurations in karabiner elements so it isn't supposed to do anything. Does anyone know what does karabiner do that could cause that behavior?

yanshay commented 1 year ago

But going back to the original event sequence, is the set of events the mod-morph generates is correct? The way I read the events sequence it is indeed shifted tab and not tab. I'v seen all kinds of discussions about mod-morph ability to swallow mods (#1114) and masked-mod functionality that I see in the code but was removes from the attributes yaml. But couldn't find a solution to this issue.

divsmith commented 1 year ago

I encountered this as well on a nice!nano in MacOS. Karabiner itself appears to reorder events for modifier keys when Modify events is enabled.

I have a mod-morph configured to send comma , normally and semicolon ; when left shift is held:

comma_colon: COMMA_SEMICOLON {
        compatible = "zmk,behavior-mod-morph";
        label = "COMMA_SEMICOLON";
        #binding-cells = <0>;
        bindings = <&kp COMMA>, <&kp SEMI>;
        mods = <(MOD_LSFT)>;
};

Holding down left shift and pressing comma with Modifiers enabled results in the following logs:

[
  {
    "type": "down",
    "name": {"key_code":"left_shift"},
    "usagePage": "7 (0x0007)",
    "usage": "225 (0x00e1)",
    "misc": "flags left_shift"
  },
  {
    "type": "down",
    "name": {"key_code":"semicolon"},
    "usagePage": "7 (0x0007)",
    "usage": "51 (0x0033)",
    "misc": "flags left_shift"
  },
  {
    "type": "up",
    "name": {"key_code":"left_shift"},
    "usagePage": "7 (0x0007)",
    "usage": "225 (0x00e1)",
    "misc": ""
  },
  {
    "type": "up",
    "name": {"key_code":"semicolon"},
    "usagePage": "7 (0x0007)",
    "usage": "51 (0x0033)",
    "misc": ""
  }
]

The shift up is reordered to come after the semicolon down, resulting in : instead of ;

Once Modifiers enabled is turned off the same test results in the expected behavior:

[
  {
    "type": "down",
    "name": {"key_code":"left_shift"},
    "usagePage": "7 (0x0007)",
    "usage": "225 (0x00e1)",
    "misc": "flags left_shift"
  },
  {
    "type": "down",
    "name": {"key_code":"semicolon"},
    "usagePage": "7 (0x0007)",
    "usage": "51 (0x0033)",
    "misc": "flags left_shift"
  },
  {
    "type": "up",
    "name": {"key_code":"left_shift"},
    "usagePage": "7 (0x0007)",
    "usage": "225 (0x00e1)",
    "misc": ""
  },
  {
    "type": "up",
    "name": {"key_code":"semicolon"},
    "usagePage": "7 (0x0007)",
    "usage": "51 (0x0033)",
    "misc": ""
  }
]
fabianpage commented 1 year ago

I get the same problem. (I have a combo which sends 1 without shift and F1 with shift.) When I press shift, the first F1 will be sent with shift, the following ones without.

mskvsk commented 10 months ago

Same thing

right_br: right_and_brightness_inc {
                compatible = "zmk,behavior-mod-morph";
                label = "BRIGHTNESS_UP_DOWN";
                #binding-cells = <0>;
                bindings = <&kp RIGHT>, <&kp C_BRI_UP>;
                        mods = <MOD_LALT>;
                        keep-mods = <0>;
        };

When pressed with Alt, it sends Alt+C_BRI_UP.

I am running it on Corne-isn Zen. Disabling NKRO didn't help.