Skip to content

Instantly share code, notes, and snippets.

@panzerstadt
Last active June 17, 2024 14:50
Show Gist options
  • Save panzerstadt/51bce7f94859a0fda728fae1cbfbb963 to your computer and use it in GitHub Desktop.
Save panzerstadt/51bce7f94859a0fda728fae1cbfbb963 to your computer and use it in GitHub Desktop.
QMK keycode to open a program

most of the above file is copied from the default keymap.c file from the hifumi keymap. the above file is a full copy pasted keymap.c, ready for use on a hifumi 6-key macropad, keymaps doing:

first col second col third col
page down up arrow start steam
left arrow down arrow right arrow

TLDR: on your keymap:

  1. declare an enum called custom_keycodes
enum custom_keycodes {
    STEAM = SAFE_RANGE, // SAFE_RANGE prevents it from using a clashing keycode
};
  1. create a function called process_record_user with:
    • a SEND_STRING(SS_TAP(X_LGUI) "steam" SS_DELAY(500) SS_TAP(X_ENT)); where the text in the double quotes is anything you type in your windows searchbar
    • this essentially taps the windows button, types your text, wait a bit for search to finish, then press ENTER. et voila! opens your program.
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
    switch (keycode) {
        case STEAM:
            if (record->event.pressed) {
                SEND_STRING(SS_TAP(X_LGUI) "steam" SS_DELAY(500) SS_TAP(X_ENT));
            } else {
                // when keycode is released
            }
            break;
    }
    return true;
}
  1. use that function in your keymap
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
    [DEFAULT] = LAYOUT(
        KC_PGDN, KC_UP,   STEAM, // used my top right key for the 'open steam' macro
        KC_LEFT, KC_DOWN, KC_RIGHT
    ),
    // the rest of the kepmap layers if needed
/* Copyright 2019 zk-phi
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include QMK_KEYBOARD_H
#ifdef RGBLIGHT_ENABLE
//Following line allows macro to read current RGB settings
extern rgblight_config_t rgblight_config;
#endif
enum layers {
DEFAULT,
RAISE,
LOWER,
ADJUST
};
enum custom_keycodes {
STEAM = SAFE_RANGE,
};
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case STEAM:
if (record->event.pressed) {
SEND_STRING(SS_TAP(X_LGUI) "steam" SS_DELAY(500) SS_TAP(X_ENT));
} else {
// when keycode is released
}
break;
}
return true;
}
// below is for kepmaps for a hifumi 6 key macropad
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[DEFAULT] = LAYOUT(
KC_PGDN, KC_UP, STEAM,
KC_LEFT, KC_DOWN, KC_RIGHT
),
[RAISE] = LAYOUT(
_______, KC_PGUP, MO(ADJUST),
KC_HOME, KC_PGDN, KC_END
),
[LOWER] = LAYOUT(
MO(ADJUST), _______, _______,
_______, _______, _______
),
[ADJUST] = LAYOUT(
_______, RGB_TOG, _______,
RGB_MODE_SNAKE, RGB_MODE_PLAIN, RGB_HUI
)
};
@GeneralDisk
Copy link

Running SS_LGUI('r') is a good idea, though you still need to wait 10ms for the run box to open else the string stream following the tap will cutoff the first character.

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