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

Documentation: incorrect code pattern in feature_advanced_keycodes.md #20361

Closed
dloidolt opened this issue Apr 7, 2023 · 1 comment · Fixed by #20512
Closed

Documentation: incorrect code pattern in feature_advanced_keycodes.md #20361

dloidolt opened this issue Apr 7, 2023 · 1 comment · Fixed by #20512

Comments

@dloidolt
Copy link
Contributor

dloidolt commented Apr 7, 2023

Issue Description

The feature_advanced_keycodes.md has this part:

To check that only a specific set of mods is active at a time, AND the modifier state and your desired mod mask as explained above and compare the result to the mod mask itself: get_mods() & <mod mask> == <mod mask>.

For example, let's say you want to trigger a piece of custom code if one-shot left control and one-shot left shift are on but every other one-shot mods are off. To do so, you can compose the desired mod mask by combining the mod bits for left control and shift with (MOD_BIT(KC_LCTL) | MOD_BIT(KC_LSFT)) and then plug it in: get_oneshot_mods() & (MOD_BIT(KC_LCTL) | MOD_BIT(KC_LSFT)) == (MOD_BIT(KC_LCTL) | MOD_BIT(KC_LSFT)). Using MOD_MASK_CS instead for the mod bitmask would have forced you to press four modifier keys (both versions of control and shift) to fulfill the condition.

However the pattern get_mods() & <mod mask> == <mod mask> does not check if only a specific set is active at a time. This expression is also true when a mod is pressed together with the specific mod.
I think the correct pattern is get_mods() == <mod mask>

I am not a QMK expert, but something I noticed with the first code example in feature_advanced_keycodes.md: should the first code example be implemented with Key Overrides?

@filterpaper
Copy link
Contributor

filterpaper commented Apr 11, 2023

This expression is also true when a mod is pressed together with the specific mod.

Do you mean that when Left Ctrl + Shift is held together, the following is true?

get_mods() & MOD_MASK_SHIFT == MOD_MASK_SHIFT

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

Successfully merging a pull request may close this issue.

2 participants