Skip to content

Commit

Permalink
Keymap for random key presses for the scrabblepad (qmk#4356)
Browse files Browse the repository at this point in the history
* Random key presses for scrabblepad

* Fix keymap code comments

* Remove unused methods as per code review
  • Loading branch information
gorbachev authored and djthread committed Mar 17, 2019
1 parent ae6e838 commit ae6c911
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
75 changes: 75 additions & 0 deletions keyboards/scrabblepad/keymaps/random/keymap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include "scrabblepad.h"
#include <stdlib.h>

static uint16_t keystroke;
static bool shift_pressed;

static int lower = (int) KC_A;
static int upper = (int) KC_Z;

uint16_t random_keycode(void) {
return lower + (rand() % (upper - lower + 1));
};

enum custom_keycodes {
RND_KEY = SAFE_RANGE
};

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch(keycode) {
case RND_KEY:
if (record->event.pressed) {
keystroke = random_keycode();
if (rand() % 2 > 0) {
shift_pressed = 1;
register_code(KC_LSHIFT);
}
register_code(keystroke);
} else {
if (shift_pressed > 0) {
unregister_code(KC_LSHIFT);
}
unregister_code(keystroke);
}

return false;

default:
return true;
}

return true;
}

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = LAYOUT( /* Base */
RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, \
RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, \
RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, \
RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, \
RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, \
RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, \
RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, \
RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RESET, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, \
RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, \
RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, \
RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, \
RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, \
RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, \
RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, \
RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY, RND_KEY
),
};


void matrix_init_user(void) {

}

void matrix_scan_user(void) {

}

void led_set_user(uint8_t usb_led) {

}
5 changes: 5 additions & 0 deletions keyboards/scrabblepad/keymaps/random/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Scrabblepad keymap with every key press random

Every key produces a random key press, except the middle key, which is reserved for resetting the board.

The random key press is selected between KC_A and KC_Z keycodes.

0 comments on commit ae6c911

Please sign in to comment.