Skip to content

Instantly share code, notes, and snippets.

@grafov
Last active September 8, 2025 18:05
Show Gist options
  • Save grafov/c5833c9c3763d265c6dc6108c5fca76c to your computer and use it in GitHub Desktop.
Save grafov/c5833c9c3763d265c6dc6108c5fca76c to your computer and use it in GitHub Desktop.

Revisions

  1. grafov revised this gist Sep 9, 2024. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions keymap.c
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    // Not for copypaste! It is only part of keymap.c!
    // You should adapt the code above for your keyboard especially for your layers.
    // WARNING! You could be banned in Valve games because the feautre treated by Valve as a cheat.
    //
    // It uses two user hooks: layer_state_set_user() and process_record_user() as defined by QMK.

    // Example enum with layers.
  2. grafov revised this gist Sep 9, 2024. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion keymap.c
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    // Not for copypaste! You should adapt the code above for your keyboard especially for your layers.
    // Not for copypaste! It is only part of keymap.c!
    // You should adapt the code above for your keyboard especially for your layers.
    // It uses two user hooks: layer_state_set_user() and process_record_user() as defined by QMK.

    // Example enum with layers.
  3. grafov created this gist Sep 9, 2024.
    73 changes: 73 additions & 0 deletions keymap.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,73 @@
    // Not for copypaste! You should adapt the code above for your keyboard especially for your layers.
    // It uses two user hooks: layer_state_set_user() and process_record_user() as defined by QMK.

    // Example enum with layers.
    enum layers {
    DEFAULT_LAYER,
    GAME_LAYER,
    // ...
    }


    // global var that keeps current layer
    uint8_t cur_layer = YOUR_DEFAULT_LAYER;

    // Hook that triggered on a layer state change.
    layer_state_t layer_state_set_user(layer_state_t state) {
    static uint8_t old_layer = 0xff;
    cur_layer = get_highest_layer(state);

    // ... handle other things on layer change
    }



    // Hook on the each key press/release
    bool process_record_user(uint16_t keycode, keyrecord_t *record) {

    // SNAP TAP (separate A/D key press in games)
    static bool apressed = false;
    static bool dpressed = false;
    // Apply only for GAME_LAYER and not mess A/D keys for other layers.
    if (cur_layer == GAME_LAYER) {
    switch(keycode) {
    case KC_A:
    if (record->event.pressed) {
    apressed = true;
    if (dpressed) {
    SEND_STRING(SS_UP(X_D));
    dpressed = false;
    };
    } else {
    // to prevent double key release
    if (!apressed) {
    return false;
    }
    apressed = false;
    }
    return true;
    case KC_D:
    if (record->event.pressed) {
    dpressed = true;
    if (apressed) {
    SEND_STRING(SS_UP(X_A));
    };
    } else {
    // to prevent double key release
    if (!dpressed) {
    return false;
    }
    dpressed = false;
    }
    if (!record->event.pressed) {
    // to prevent double release
    if (dpressed) {
    return false;
    }
    }
    return true;
    }
    }

    // ... handle other key presses
    }