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

Document examples on intercepting Mod-Tap #14502

Merged
merged 21 commits into from
Oct 4, 2021
Merged
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions docs/mod_tap.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,78 @@ You may also run into issues when using Remote Desktop Connection on Windows. Be
To fix this, open Remote Desktop Connection, click on "Show Options", open the the "Local Resources" tab, and in the keyboard section, change the drop down to "On this Computer". This will fix the issue, and allow the characters to work correctly.
It can also be mitigated by increasing [`TAP_CODE_DELAY`](config_options.md#behaviors-that-can-be-configured).

## Intercepting Mod-Taps

### Changing tap function

Basic keycode limitation with Mod-Tap can be worked around by intercepting it in `process_record_user`. For example, shifted keycode `KC_DQUO` cannot be used with `MT()` because it is a 16-bit keycode alias of `LSFT(KC_QUOT)`. But the following custom code can be used to intercept the "tap" function to manually send `KC_DQUO`:

```c
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case LCTL_T(KC_DQUO):
filterpaper marked this conversation as resolved.
Show resolved Hide resolved
if (record->tap.count && record->event.pressed) {
tap_code16(KC_DQUO); // Send KC_DQUO on tap
return false; // Return false to ignore further processing of key
}
break;
}
return true;
}
```

### Changing hold function

Likewise, the same custom code can also be used to intercept the hold function to send custom user key code. The following example uses `LT(0, kc)`, a current-layer Mod-Tap with no practical use, to add cut, copy and paste function to X,C and V keys when they are held down:
filterpaper marked this conversation as resolved.
Show resolved Hide resolved

```c
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case LT(0,KC_X):
if (record->tap.count && record->event.pressed) {
return true; // Return true for normal processing of tap keycode
} else if (record->event.pressed) {
tap_code16(C(KC_X)); // Intercept hold function to send Ctrl-X
}
return false;
case LT(0,KC_C):
if (record->tap.count && record->event.pressed) {
return true; // Return true for normal processing of tap keycode
} else if (record->event.pressed) {
tap_code16(C(KC_C)); // Intercept hold function to send Ctrl-C
}
return false;
case LT(0,KC_V):
if (record->tap.count && record->event.pressed) {
return true; // Return true for normal processing of tap keycode
} else if (record->event.pressed) {
tap_code16(C(KC_V)); // Intercept hold function to send Ctrl-V
}
return false;
}
return true;
}
```

### Changing both tap and hold

This last example uses both tap and hold function of `LT()` to create a copy-on-tap, paste-on-hold key with `LT(0,KC_NO)`:

```c
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case LT(0,KC_NO):
if (record->tap.count && record->event.pressed) {
tap_code16(C(KC_C)); // Intercept tap function to send Ctrl-C
} else if (record->event.pressed) {
tap_code16(C(KC_V)); // Intercept hold function to send Ctrl-V
}
return false;
}
return true;
}
```

## Other Resources

See the [Tap-Hold Configuration Options](tap_hold.md) for additional flags that tweak Mod-Tap behavior.