Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong keycode with Custom Shift Keys Feature #5

Closed
wheredoesyourmindgo opened this issue Mar 2, 2022 · 6 comments
Closed

Wrong keycode with Custom Shift Keys Feature #5

wheredoesyourmindgo opened this issue Mar 2, 2022 · 6 comments

Comments

@wheredoesyourmindgo
Copy link

wheredoesyourmindgo commented Mar 2, 2022

I'm getting the incorrect keycode when I use the custom shift keys feature with keycodes that don't require a shift press, ex. comma and opening arrow bracket --> comma and semi-colon. The shifted code is always being returned, in my example, the colon is firing instead of the semi-colon. My workaround is to use unregister_mods() over del_mods(). Does that seem like the proper fix?

del_mods(MOD_MASK_SHIFT);

@wheredoesyourmindgo
Copy link
Author

oh nevermind. it looks like b102238 fixes this with del_weak_mods()

@wheredoesyourmindgo
Copy link
Author

double nevermind, it looks like I'm still having the same issue unless i use use unregister_mods() so i re-opened the issue. sorry about the confusion.

@getreuer
Copy link
Owner

getreuer commented Mar 2, 2022

Thanks for the report and suggested fix!

What kind of shift keys are observing this with? is it the plain KC_LSFT shift keys or something else?

@wheredoesyourmindgo
Copy link
Author

of course.

i'm not sure if i understand the question, but whether i hold the left shift or right shift and press comma I get colon instead of semi-colon. my repo is qmk fork if it helps. if i recall i remember i encountered this same issue in qmk's custom keys feature so maybe I'm missing some detail.

getreuer added a commit that referenced this issue Mar 3, 2022
#5
reports that the shift mod is not correctly cleared, e.g. for the custom
shift key `{KC_COMM, KC_SCLN}`, a `:` is typed instead of `;`. To test a
plausible fix, this commit adds a `send_keyboard_report()` call between
removing the shift mods and registering the keycode.
@getreuer
Copy link
Owner

getreuer commented Mar 3, 2022

Thanks for sharing your keymap. It's awesome to see all the custom code you have in there, I'll be studying this.

About my earlier question, I was thinking your shift keys could be one-shot mods or something like that with special handling, vs. the plain KC_LSFT and KC_RSFT keys. I wouldn't be surprised if the source of this bug is an edge case in how custom_shift_keys interacts with another special feature.

I see your keymap can apply shifts in several ways, including through a userspace implementation of one-shot mods (XOSM_LSFT) and a magic_shift feature that applies shift under combinations of (other mods) + layer key (if I understood correctly). Do you observe the : vs. ; bug with any of these methods of shifting, or one in particular?

My workaround is to use unregister_mods() over del_mods(). Does that seem like the proper fix?

Thanks again for the suggestion. I looked further into this. When a custom shift key is pressed with a shift mod active, the current code does

del_mods(MOD_MASK_SHIFT);
del_weak_mods(MOD_MASK_SHIFT);
register_code16(registered_keycode);

Under the hood, unregister_mods() is (code link):

void unregister_mods(uint8_t mods) {
    if (mods) {
        del_mods(mods);
        send_keyboard_report();
    }
}

This function is simply del_mods() + send_keyboard_report(). I wouldn't have thought that making this additional send_keyboard_report() has an effect since register_code16() itself sends a keyboard report. But I haven't been able to repro the bug to test such things. Maybe the difference is this extra report sequences the release of the shift key before the ; key is pressed. Maybe whether this matters depends on the OS.

I suggest we test that. I just pushed a commit df11113 to add a send_keyboard_report() call between removing the shift mods and registering the keycode. Please pull or copy this change to your keymap and test whether this fixes the bug.

If it's possible, it would also help if you could test your keymap with other shift-handling features disabled, like the userspace oneshot and magic_shift. That might narrow down this bug to some edge-case interaction between our custom codes.

getreuer added a commit that referenced this issue Mar 6, 2022
This commit changes uses of `add_weak_mods()` to `register_weak_mods()`
so that a keyboard report is sent after setting the shift mod but before
registering the current key press.

This appears to fix a bug on Mac OS, where Caps Word does not shift the
keys. This seems to be essentially the same bug reported in
#5
about weak mod use in custom_shift_keys.

Thank you, @wheredoesyourmindgo and u/uolot for reporting and help
fixing these bugs!
@getreuer
Copy link
Owner

getreuer commented Mar 6, 2022

An update: I just got a similar bug report from reddit user u/uolot about weak mods in Caps Word. Interestingly, the bug there was also happening on Mac OS and fixed when adding a send_keyboard_report() call after setting mods and before registering the next key. This fits with what I was thinking: adding this send_keyboard_report() call sequences the shift release vs. next key, so that the OS knows not to shift that key. Otherwise, without this send_keyboard_report(), maybe it is OS dependent how exactly it treats the next key event. Maybe that explains how I haven't run into this problem on Linux.

Thank you both for reporting and help fixing it! It sounds like we have solved both bugs, but please reopen if there are still problems.

@getreuer getreuer closed this as completed Mar 6, 2022
fride added a commit to fride/qmk-keymap that referenced this issue Aug 5, 2024
* This seems to be ok.

* add the planck.

* prepare for something else.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants