tmk / tmk_keyboard

Keyboard firmwares for Atmel AVR and Cortex-M
3.98k stars 1.7k forks source link

Help writing a simple function #700

Closed raphprogrammer closed 3 years ago

raphprogrammer commented 3 years ago

I'm trying to use tmk and running into an issues that both seems like it should be simple, so I assume there's just something basic I'm missing.

I want holding left gui and left control at the same time to act as if I'm holding left shift and left control. This isn t working and instead ends up with weird combinations of shift or control or gui permanently held down. I'd also like left gui to just display gui if I tap it. The relevant part of my code is below.

void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) { switch (id) { case KC_LCTRL: case KC_LGUI: if(record->event.pressed){ add_mods(MOD_BIT(id)); if((get_mods() & MOD_BIT(KC_LCTRL)) && (get_mods() & MOD_BIT(KC_LGUI))){ del_mods(MOD_BIT(KC_LGUI));
add_mods(MOD_BIT(KC_LSHIFT)); } } else{ if((get_mods() & MOD_BIT(KC_LCTRL)) && (get_mods() & MOD_BIT(KC_LGUI))){ del_mods(MOD_BIT(KC_LSHIFT));
add_mods(MOD_BIT(KC_LGUI)); } del_mods(MOD_BIT(id)); } send_keyboard_report(); break; } }

raphprogrammer commented 3 years ago

I worked this out, apparently using unregister_mods and register_mods fixed it