1 #include QMK_KEYBOARD_H
2 #include "tetris_text.h"
5 #define GRAVE_MODS (MOD_BIT(KC_LSHIFT)|MOD_BIT(KC_RSHIFT)|MOD_BIT(KC_LGUI)|MOD_BIT(KC_RGUI)|MOD_BIT(KC_LALT)|MOD_BIT(KC_RALT))
7 // Each layer gets a name for readability, which is then used in the keymap matrix below.
8 // The underscores don't mean anything - you can have a layer called STUFF or any other name.
9 // Layer names don't all need to be of the same length, obviously, and you can also skip them
10 // entirely and just use numbers.
15 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
16 /* Keymap _BL: Base Layer (Default Layer)
19 F(0), KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_GRV, KC_BSPC, KC_PGUP,
20 KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_PGDN,
21 KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_NUHS, KC_ENT,
22 KC_LSFT, KC_NUBS, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RO, KC_RSFT, KC_UP,
23 KC_LCTL, KC_LGUI, KC_LALT, KC_MHEN, KC_SPC,KC_SPC, KC_HENK, KC_RALT, KC_RCTL, MO(_FL), KC_LEFT, KC_DOWN, KC_RGHT),
25 /* Keymap _FL: Function Layer
28 KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, KC_DEL, BL_STEP,
29 _______, _______, _______,_______,_______,F(1) ,_______,_______,KC_PSCR,KC_SLCK, KC_PAUS, _______, _______, _______, _______,
30 _______, _______, MO(_CL),_______,_______,_______,_______,_______,_______,_______, _______, _______, _______, _______,
31 _______, _______, _______,_______,_______,_______,_______,_______,_______,_______, _______, _______, _______, _______, KC_PGUP,
32 _______, _______, _______, _______, _______,_______, _______, _______, _______, MO(_FL), KC_HOME, KC_PGDN, KC_END),
34 /* Keymap _CL: Control layer
37 _______, _______, _______,_______,_______,_______,_______,_______,_______,_______, _______, _______, _______, _______, RGB_TOG, RGB_VAI,
38 _______, _______, _______,_______,RESET, _______,_______,_______,_______,_______, _______, _______, _______, _______, RGB_VAD,
39 _______, _______, MO(_CL),_______,_______,_______,_______,_______,_______,_______, _______, _______, _______, _______,
40 MO(_FL), _______, _______,_______,_______,_______,_______,_______,_______,_______, _______, _______, _______, MO(_FL), RGB_SAI,
41 _______, _______, _______,_______, RGB_MOD, RGB_MOD, _______, _______, _______, _______, RGB_HUD, RGB_SAD, RGB_HUI),
44 /* This is a list of user defined functions. F(N) corresponds to item N
47 const uint16_t PROGMEM fn_actions[] = {
48 [0] = ACTION_FUNCTION(0), // Calls action_function()
49 [1] = ACTION_FUNCTION(1)
52 static uint8_t tetris_key_presses = 0;
53 static uint16_t tetris_timer = 0;
54 static uint8_t tetris_running = 0;
55 static int tetris_keypress = 0;
57 void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) {
58 static uint8_t mods_pressed;
63 // clueboard specific hook to make escape quite tetris
69 /* Handle the combined Grave/Esc key
71 mods_pressed = get_mods()&GRAVE_MODS; // Check to see what mods are pressed
73 if (record->event.pressed) {
74 /* The key is being pressed.
79 send_keyboard_report();
82 send_keyboard_report();
85 /* The key is being released.
90 send_keyboard_report();
93 send_keyboard_report();
98 if (record->event.pressed) {
102 // set randomness using total number of key presses
103 tetris_start(tetris_key_presses);
113 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
114 if (record->event.pressed) {
115 tetris_key_presses++;
118 if (tetris_running && record->event.pressed) {
121 case KC_UP: tetris_keypress = 1; break;
122 case KC_LEFT: tetris_keypress = 2; break;
123 case KC_DOWN: tetris_keypress = 3; break;
124 case KC_RIGHT: tetris_keypress = 4; break;
125 // Make ESC stop tetris (on keyboards other than clueboard)
126 // case KC_ESC: tetris_running = 0; return false;
128 if (tetris_keypress != 0) {
136 // Runs constantly in the background, in a loop.
137 void matrix_scan_user(void) {
138 if (tetris_running) {
140 if (tetris_timer > 1000) {
141 // every 1000 times this is run is about 100 ms.
142 if (!tetris_tick(100)) {
151 void send_keycode(uint16_t keycode) {
152 register_code(keycode);
153 unregister_code(keycode);
156 void send_keycode_shift(uint16_t keycode) {
157 register_code(KC_LSFT);
158 register_code(keycode);
159 unregister_code(keycode);
160 unregister_code(KC_LSFT);
163 void tetris_send_up(void) {
166 void tetris_send_left(void) {
167 send_keycode(KC_LEFT);
169 void tetris_send_down(void) {
170 send_keycode(KC_DOWN);
172 void tetris_send_right(void) {
173 send_keycode(KC_RGHT);
175 void tetris_send_backspace(void) {
176 send_keycode(KC_BSPC);
178 void tetris_send_delete(void) {
179 send_keycode(KC_DEL);
182 void tetris_send_string(const char *s) {
183 for (int i = 0; s[i] != 0; i++) {
184 if (s[i] >= 'a' && s[i] <= 'z') {
185 send_keycode(KC_A + (s[i] - 'a'));
186 } else if (s[i] >= 'A' && s[i] <= 'Z') {
187 send_keycode_shift(KC_A + (s[i] - 'A'));
188 } else if (s[i] >= '1' && s[i] <= '9') {
189 send_keycode(KC_1 + (s[i] - '1'));
192 case ' ': send_keycode(KC_SPACE); break;
193 case '.': send_keycode(KC_DOT); break;
194 case '0': send_keycode(KC_0); break;
200 void tetris_send_newline(void) {
201 send_keycode(KC_ENT);
204 int tetris_get_keypress(void) {
205 int out = tetris_keypress;