Skip to content

Makes Key Lock accessible from code enabling Locking Modifiers #22206#26330

Open
brotheramai wants to merge 3 commits into
qmk:developfrom
brotheramai:key_lock_util
Open

Makes Key Lock accessible from code enabling Locking Modifiers #22206#26330
brotheramai wants to merge 3 commits into
qmk:developfrom
brotheramai:key_lock_util

Conversation

@brotheramai

Copy link
Copy Markdown

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

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Keyboard (addition or update)
  • Keymap/layout (addition or update)
  • Documentation

Issues Fixed or Closed by This PR

These are all already closed, but would be at least partially addressed by this PR.

Checklist

  • My code follows the code style of this project: C, Python
  • I have read the PR Checklist document and have made the appropriate changes.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

@zvecr
zvecr changed the base branch from master to develop July 14, 2026 03:27
Comment thread quantum/process_keycode/process_key_lock.c Outdated
Comment thread quantum/process_keycode/process_key_lock.c Outdated
Comment thread quantum/process_keycode/process_key_lock.c Outdated
Comment thread quantum/process_keycode/process_key_lock.c Outdated
Comment thread quantum/process_keycode/process_key_lock.h Outdated
Comment thread docs/features/key_lock.md Outdated
Comment thread docs/features/key_lock.md Outdated
Comment thread docs/features/key_lock.md Outdated
brotheramai and others added 2 commits July 19, 2026 16:30
Co-authored-by: Drashna Jaelre <drashna@live.com>
Co-authored-by: Joel Challis <git@zvecr.com>
process_key_lock(&translated_keycode, &record);
record.event.pressed = false;
process_key_lock(&translated_keycode, &record);
} No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}

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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void cancel_key_lock(void) {
void key_lock_cancel(void) {

Comment thread docs/features/key_lock.md
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 |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 |

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread docs/features/key_lock.md
## Examples

Force certain modifiers, in this case `RCTL`, `RSFT`, and `RALT` to toggle on/off like Caps Lock when pressed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants