You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.8 KiB

  1. # The Leader Key: A New Kind of Modifier
  2. If you've ever used Vim, you know what a Leader key is. If not, you're about to discover a wonderful concept. :) Instead of hitting Alt+Shift+W for example (holding down three keys at the same time), what if you could hit a _sequence_ of keys instead? So you'd hit our special modifier (the Leader key), followed by W and then C (just a rapid succession of keys), and something would happen.
  3. That's what `KC_LEAD` does. Here's an example:
  4. 1. Pick a key on your keyboard you want to use as the Leader key. Assign it the keycode `KC_LEAD`. This key would be dedicated just for this -- it's a single action key, can't be used for anything else.
  5. 2. Include the line `#define LEADER_TIMEOUT 300` somewhere in your keymap.c file, probably near the top. The 300 there is 300ms -- that's how long you have for the sequence of keys following the leader. You can tweak this value for comfort, of course.
  6. 3. Within your `matrix_scan_user` function, do something like this:
  7. ```
  8. LEADER_EXTERNS();
  9. void matrix_scan_user(void) {
  10. LEADER_DICTIONARY() {
  11. leading = false;
  12. leader_end();
  13. SEQ_ONE_KEY(KC_F) {
  14. register_code(KC_S);
  15. unregister_code(KC_S);
  16. }
  17. SEQ_TWO_KEYS(KC_A, KC_S) {
  18. register_code(KC_H);
  19. unregister_code(KC_H);
  20. }
  21. SEQ_THREE_KEYS(KC_A, KC_S, KC_D) {
  22. register_code(KC_LGUI);
  23. register_code(KC_S);
  24. unregister_code(KC_S);
  25. unregister_code(KC_LGUI);
  26. }
  27. }
  28. }
  29. ```
  30. As you can see, you have three function. you can use - `SEQ_ONE_KEY` for single-key sequences (Leader followed by just one key), and `SEQ_TWO_KEYS` and `SEQ_THREE_KEYS` for longer sequences. Each of these accepts one or more keycodes as arguments. This is an important point: You can use keycodes from **any layer on your keyboard**. That layer would need to be active for the leader macro to fire, obviously.