Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include QMK_KEYBOARD_H
- // Declare the variables we use
- #define IRONY_HOLD_DELAY 500
- uint16_t irony_pressed_time;
- bool irony_active = false;
- bool irony_shifted = false;
- char irony_str[4] = "⸮";
- char bang_str[4] = "‽";
- // Declare custom keycode
- enum custom_keycodes {
- IRONY,
- };
- // Assign your key to IRONY
- const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
- [0] = LAYOUT_keyboard_layout(IRONY),
- };
- bool process_record_user(uint16_t keycode, keyrecord_t* record) {
- switch (keycode) {
- case IRONY:
- // Check if shifted
- if ((get_mods() & MOD_MASK_SHIFT)) {
- irony_shifted = true;
- } else {
- irony_shifted = false;
- }
- if (record->event.pressed) {
- // Send the intial character right away if pressed
- if (irony_shifted) {
- send_unicode_string(bang_str);
- } else {
- send_unicode_string(irony_str);
- }
- //Start the repeater timer
- irony_active = true;
- irony_pressed_time = timer_read();
- } else {
- //Stop the repeater if the key is released
- irony_active = false;
- irony_pressed_time = 0;
- irony_shifted = false;
- }
- return false;
- }
- return true;
- }
- // Runs every refresh of the board, ie very frequently
- void matrix_scan_user(void) {
- // Check if the key is being held down
- if (irony_active) {
- // Check if the initial delay timer has elapsed yet
- if (timer_elapsed(irony_pressed_time) >= IRONY_HOLD_DELAY) {
- // Optionally check again if we are shifted
- // This will allow the output to change if you press or release shift while still holding the key
- /***************************************
- if ((get_mods() & MOD_MASK_SHIFT)) {
- irony_shifted = true;
- } else {
- irony_shifted = false;
- }
- **************************************/
- if (irony_shifted) {
- send_unicode_string(bang_str);
- } else {
- send_unicode_string(irony_str);
- }
- }
- }
- }
- /* This all should be lean enough to run these macros for every key on your board if you wanted.
- * That saids, I'm sure it could be improved upon, and fair warning this was stripped and modified
- * from my personal board's code, so it may have bugs relating to my poor copy-pasting skills or
- * my poor coding skills. However, it does run and appears to work as expected on my board.
- *
- * The benefit to using this method rather than unicode hex codes
- * or defining unicode keys and using tap_code instead of send_unicode_string is
- * that it allows for way more flexibility (and it's easy to copy paste the character you want!)
- * You can even use emoji and/or multiple characters!
- ***** NOTE: For multiple characters and some emoji you may need to increase the array size for the strings ****/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement