Achieve functional footboard sending alt+number

This commit is contained in:
Maximilian Friedersdorff 2025-10-26 22:19:19 +00:00
parent 8136e6499c
commit b8c173a5b8
2 changed files with 12 additions and 31 deletions

View file

@ -1,21 +1,10 @@
char n_buttons = 7; char n_buttons = 7;
char button_pins[] = {0, 1, 2, 3, 4, 5, 6}; char button_pins[] = {0, 1, 2, 3, 4, 5, 6};
char pin_state[] = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH}; char pin_state[] = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH};
char modKey = (char) KEY_LEFT_CTRL; char modKey = (char) MODIFIERKEY_CTRL;
char buttons[7][6] = { int buttons[7] = {KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7};
{'1'},
{'2'},
{'3'},
{'4'},
{'5'},
{'6'},
{'7'}
};
char sequence_length[] = {1, 1, 1, 1, 1, 1, 1};
void setup() { void setup() {
@ -23,7 +12,6 @@ void setup() {
for (int i = 0; i < n_buttons; ++i) { for (int i = 0; i < n_buttons; ++i) {
pinMode(button_pins[i], INPUT_PULLUP); pinMode(button_pins[i], INPUT_PULLUP);
} }
Keyboard.begin();
} }
@ -41,23 +29,15 @@ void loop() {
void set_button_state(int button_i, char state) { void set_button_state(int button_i, char state) {
char *sequence = buttons[button_i]; char key = buttons[button_i];
char len = sequence_length[button_i];
if (sequence_length[button_i] == 1) {
if (state == LOW) { if (state == LOW) {
Keyboard.press(modKey); Keyboard.set_modifier(MODIFIERKEY_ALT);
Keyboard.press(sequence[0]); Keyboard.set_key1(key);
Keyboard.send_now();
} else { } else {
Keyboard.releaseAll(); Keyboard.set_modifier(0);
} Keyboard.set_key1(0);
} else if(state == LOW) { Keyboard.send_now();
Keyboard.press(modKey);
for (int i = 0; i < len; ++i) {
Keyboard.press(sequence[i]);
Keyboard.release(sequence[i]);
delay(12);
}
Keyboard.releaseAll();
} }
} }

1
sketch.yaml Normal file
View file

@ -0,0 +1 @@
default_fqbn: teensy:avr:teensyLC:usb=keyboard,opt=o1lto