-
-
Notifications
You must be signed in to change notification settings - Fork 40.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keymap for random key presses for the scrabblepad #4356
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,95 @@ | ||||||
#include "scrabblepad.h" | ||||||
#include <stdlib.h> | ||||||
|
||||||
static uint16_t keystroke; | ||||||
static bool shift_pressed; | ||||||
|
||||||
static int lower = (int) KC_A; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest turning these into preprocessor constants so that you don't have to worry about the type here.
Suggested change
|
||||||
static int upper = (int) KC_Z; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above.
Suggested change
|
||||||
|
||||||
uint16_t random_keycode(void) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you're only generating basic keycodes, you should probably narrow the type to
Suggested change
|
||||||
return lower + (rand() % (upper - lower + 1)); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It probably doesn't matter for this use case, but this way of generating random numbers in a range has very poor uniformity (it favors lower numbers most of the time). Here is a slightly better way to do it:
Suggested change
( |
||||||
}; | ||||||
|
||||||
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(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is a function somewhere for a random keypress There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I couldn't find one searching the codebase. The only random stuff I see is picking a random macro from an array of strings, some RGB animation stuff and one keymap with random number stuff embedded into the keymap.c file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
if (rand() % 2 > 0) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above regarding uniformity.
Suggested change
|
||||||
shift_pressed = 1; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use
Suggested change
|
||||||
register_code(KC_LSHIFT); | ||||||
} | ||||||
register_code(keystroke); | ||||||
} else { | ||||||
if (shift_pressed > 0) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Writing it like this suggests that
Suggested change
|
||||||
unregister_code(KC_LSHIFT); | ||||||
} | ||||||
unregister_code(keystroke); | ||||||
} | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary newline here.
Suggested change
|
||||||
return false; | ||||||
|
||||||
default: | ||||||
return true; | ||||||
} | ||||||
|
||||||
return true; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is unnecessary since the
Suggested change
|
||||||
} | ||||||
|
||||||
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 | ||||||
), | ||||||
}; | ||||||
|
||||||
|
||||||
const uint16_t PROGMEM fn_actions[] = { | ||||||
drashna marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
}; | ||||||
|
||||||
const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) | ||||||
drashna marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
{ | ||||||
// MACRODOWN only works in this function | ||||||
switch(id) { | ||||||
case 0: | ||||||
if (record->event.pressed) { | ||||||
register_code(KC_RSFT); | ||||||
} else { | ||||||
unregister_code(KC_RSFT); | ||||||
} | ||||||
break; | ||||||
} | ||||||
return MACRO_NONE; | ||||||
}; | ||||||
|
||||||
|
||||||
void matrix_init_user(void) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no need to define these functions if they're going to be empty.
Suggested change
|
||||||
|
||||||
} | ||||||
|
||||||
void matrix_scan_user(void) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
} | ||||||
|
||||||
void led_set_user(uint8_t usb_led) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
} |
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment regarding
random_keycode
return type.