Makes Key Lock accessible from code enabling Locking Modifiers #22206#26330
Open
brotheramai wants to merge 3 commits into
Open
Makes Key Lock accessible from code enabling Locking Modifiers #22206#26330brotheramai wants to merge 3 commits into
brotheramai wants to merge 3 commits into
Conversation
drashna
requested changes
Jul 15, 2026
zvecr
requested changes
Jul 16, 2026
Co-authored-by: Drashna Jaelre <drashna@live.com>
Co-authored-by: Joel Challis <git@zvecr.com>
zvecr
requested changes
Jul 19, 2026
| process_key_lock(&translated_keycode, &record); | ||
| record.event.pressed = false; | ||
| process_key_lock(&translated_keycode, &record); | ||
| } No newline at end of file |
| bool process_key_lock(uint16_t *keycode, keyrecord_t *record); | ||
| bool key_lock_get_state(uint16_t keycode); | ||
| bool key_lock_active(void); | ||
| void key_lock_start(void); |
Member
There was a problem hiding this comment.
Suggested change
| void key_lock_start(void); | |
| void key_lock_start(void); | |
| void key_lock_cancel(void); |
| @@ -22,3 +22,6 @@ | |||
|
|
|||
| void cancel_key_lock(void); | |||
Member
There was a problem hiding this comment.
Suggested change
| void cancel_key_lock(void); | |
| // DEPRECATED | |
| #define cancel_key_lock key_lock_cancel | |
| @@ -57,11 +57,7 @@ static inline uint16_t translate_keycode(uint16_t keycode) { | |||
|
|
|||
| void cancel_key_lock(void) { | |||
Member
There was a problem hiding this comment.
Suggested change
| void cancel_key_lock(void) { | |
| void key_lock_cancel(void) { |
Comment on lines
+23
to
+26
| |begin_key_lock() |Begins the key lock sequence. Mimics pressing QK_LOCK | | ||
| |cancel_key_lock() |Cancels the key lock sequnec if called before a lockable key is pressed| | ||
| |get_key_lock_begun()|Checks whether the key lock sequence has started | | ||
| |get_key_lock_state()|Checks whether a specific key is locked | |
Member
There was a problem hiding this comment.
Suggested change
| |begin_key_lock() |Begins the key lock sequence. Mimics pressing QK_LOCK | | |
| |cancel_key_lock() |Cancels the key lock sequnec if called before a lockable key is pressed| | |
| |get_key_lock_begun()|Checks whether the key lock sequence has started | | |
| |get_key_lock_state()|Checks whether a specific key is locked | | |
| |key_lock_start() |Begins the key lock sequence. Mimics pressing QK_LOCK | | |
| |key_lock_cancel() |Cancels the key lock sequnec if called before a lockable key is pressed| | |
| |key_lock_active() |Checks whether the key lock sequence has started | | |
| |key_lock_get_state()|Checks whether a specific key is locked | |
Author
There was a problem hiding this comment.
How do you typically handle announcing deprecations? Should we add a bit to the row for key_lock_cancel explaining that the cancel_key_lock alias has been deprecated and should be updated?
Member
There was a problem hiding this comment.
Given the feature is fairly low use, and the proposed backwards compatibility, its probably not worth adding anything to the docs. We can add something to breaking changes page to cover this.
| ## Examples | ||
|
|
||
| Force certain modifiers, in this case `RCTL`, `RSFT`, and `RALT` to toggle on/off like Caps Lock when pressed. | ||
|
|
Member
There was a problem hiding this comment.
Suggested change
| ```c | |
| bool pre_process_record_user(uint16_t keycode, keyrecord_t *record) { | |
| if (keycode == KC_RCTL || keycode == KC_RSFT || keycode == KC_RALT) { | |
| if (!key_lock_get_state(keycode) && !key_lock_active()) { | |
| key_lock_start(); // emulates pressing QK_LOCK when needed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds begin_key_lock() which mimics pressing QK_LOCK since tap_code does not accept QK_LOCK and tap_code16 exhibits strange behavior when QK_LOCK is passed (on my machine it types 11).
Adds get_key_lock_begun() which returns whether Key Lock is watching for a key to be locked.
Adds get_key_lock_state() which can be passed a keycode and returns its current lock state.
These combined allow for keymap code that can interact with Key Lock to, for example, make specific modifiers toggle like CAPS LOCK when pressed. See examples section of doc for specifics.
Types of Changes
Issues Fixed or Closed by This PR
These are all already closed, but would be at least partially addressed by this PR.
Checklist