Advertisement
rootiest

qmk-irony-updated

May 25th, 2021 (edited)
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.15 KB | None | 0 0
  1. #include QMK_KEYBOARD_H
  2.  
  3. // Declare the variables we use
  4. #define IRONY_HOLD_DELAY 500
  5. uint16_t irony_pressed_time;
  6. bool     irony_active  = false;
  7. bool     irony_shifted = false;
  8. char     irony_str[4]  = "⸮";
  9. char     bang_str[4]   = "‽";
  10.  
  11. // Declare custom keycode
  12. enum custom_keycodes {
  13.     IRONY,
  14. };
  15.  
  16. // Assign your key to IRONY
  17. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  18.     [0] = LAYOUT_keyboard_layout(IRONY),
  19. };
  20.  
  21. bool process_record_user(uint16_t keycode, keyrecord_t* record) {
  22.     switch (keycode) {
  23.         case IRONY:
  24.             // Check if shifted
  25.             if ((get_mods() & MOD_MASK_SHIFT)) {
  26.                 irony_shifted = true;
  27.             } else {
  28.                 irony_shifted = false;
  29.             }
  30.             if (record->event.pressed) {
  31.                 // Send the intial character right away if pressed
  32.                 if (irony_shifted) {
  33.                     send_unicode_string(bang_str);
  34.                 } else {
  35.                     send_unicode_string(irony_str);
  36.                 }
  37.                 //Start the repeater timer
  38.                 irony_active       = true;
  39.                 irony_pressed_time = timer_read();
  40.             } else {
  41.                 //Stop the repeater if the key is released
  42.                 irony_active       = false;
  43.                 irony_pressed_time = 0;
  44.                 irony_shifted      = false;
  45.             }
  46.             return false;
  47.     }
  48.     return true;
  49. }
  50.  
  51. // Runs every refresh of the board, ie very frequently
  52. void matrix_scan_user(void) {
  53.     // Check if the key is being held down
  54.     if (irony_active) {
  55.         // Check if the initial delay timer has elapsed yet
  56.         if (timer_elapsed(irony_pressed_time) >= IRONY_HOLD_DELAY) {
  57.             // Optionally check again if we are shifted
  58.             // This will allow the output to change if you press or release shift while still holding the key
  59.             /***************************************
  60.              if ((get_mods() & MOD_MASK_SHIFT)) {
  61.                 irony_shifted = true;
  62.             } else {
  63.                 irony_shifted = false;
  64.             }
  65.             **************************************/
  66.             if (irony_shifted) {
  67.                 send_unicode_string(bang_str);
  68.             } else {
  69.                 send_unicode_string(irony_str);
  70.             }
  71.         }
  72.     }
  73. }
  74. /* This all should be lean enough to run these macros for every key on your board if you wanted.
  75.  * That saids, I'm sure it could be improved upon, and fair warning this was stripped and modified
  76.  * from my personal board's code, so it may have bugs relating to my poor copy-pasting skills or
  77.  * my poor coding skills. However, it does run and appears to work as expected on my board.
  78.  *
  79.  * The benefit to using this method rather than unicode hex codes
  80.  * or defining unicode keys and using tap_code instead of send_unicode_string is
  81.  * that it allows for way more flexibility (and it's easy to copy paste the character you want!)
  82.  * You can even use emoji and/or multiple characters!
  83.  ***** 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