Compare commits

...

3 commits

Author SHA1 Message Date
3f393b3fa3 function and media keys 2021-03-03 18:57:54 +02:00
df9d926770 moving by word 2021-03-03 18:08:51 +02:00
620e6bdb49 gui modifier instead of insert 2021-03-03 17:58:45 +02:00

View file

@ -6,6 +6,7 @@
// using my own masks here since the inbuilt ones conflict with arrow keys etc.
#define MASK_SHIFT 0x100
#define MASK_ALTGR 0x200
#define MASK_CTRL 0x800
const byte PIN_A = 33;
const byte PIN_B = 32;
@ -43,6 +44,9 @@ const int button_characters[6] = { KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F };
const int button_characters_symbol[6] = {
KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6
};
const int button_characters_function[6] = {
KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6
};
/*
backspace, space (keep those two first since they overlap with the rest )
@ -63,8 +67,8 @@ const byte chord_buttons[24] = {
// keypresses for chords in sets of 4
// index 0 is the chord on its own, 1-3 correspond to chord_buttons
const int chord_targets[32] = {
KEY_BACKSPACE, KEY_LEFT, KEY_LEFT, KEY_HOME,
KEY_SPACE, KEY_RIGHT, KEY_RIGHT, KEY_END,
KEY_BACKSPACE, KEY_LEFT + MASK_CTRL, KEY_LEFT, KEY_HOME,
KEY_SPACE, KEY_RIGHT + MASK_CTRL, KEY_RIGHT, KEY_END,
KEY_G, KEY_H, KEY_I, KEY_J,
KEY_K, KEY_L, KEY_M, KEY_N,
KEY_O, KEY_P, KEY_Q, KEY_R,
@ -73,8 +77,8 @@ const int chord_targets[32] = {
0, 0, 0, 0
};
const int chord_targets_symbol[32] = {
KEY_BACKSPACE, KEY_LEFT, KEY_LEFT, KEY_HOME,
KEY_SPACE, KEY_RIGHT, KEY_RIGHT, KEY_END,
0, 0, 0, 0,
0, 0, 0, 0,
KEY_0, KEY_7, KEY_8, KEY_9,
// # @ ½ &
KEY_BACKSLASH, KEY_QUOTE + MASK_SHIFT, KEY_5 + MASK_ALTGR, KEY_7 + MASK_SHIFT,
@ -87,40 +91,58 @@ const int chord_targets_symbol[32] = {
// ) ] > }
KEY_0 + MASK_SHIFT, KEY_RIGHT_BRACE, KEY_PERIOD + MASK_SHIFT, KEY_RIGHT_BRACE + MASK_SHIFT,
};
const int chord_targets_function[32] = {
KEY_MEDIA_PLAY_PAUSE, 0, KEY_MEDIA_PREV_TRACK, 0,
KEY_MEDIA_MUTE, 0, KEY_MEDIA_NEXT_TRACK, 0,
KEY_F7, KEY_F8, KEY_F9, KEY_F10,
KEY_F11, KEY_F12, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0
};
/*
dash, backslash, slash, apostrophe, comma, exclamation point, question mark,
period, up, down, page up, page down, shift, symbol shift, switch keyset,
escape, control, alt, delete, insert, tab, enter
escape, control, alt, delete, function, gui, tab, enter
*/
// TODO: add the middle specials for function keys instead of the weird symbols
const byte specials[22] = {
const byte specials[23] = {
17, 51, 30, 10, 20, 12, 33, 34, 9, 36, 27,
54, 18, 45, 63, 31, 47, 55, 62, 43, 61, 59
54, 18, 45, 63, 31, 47, 55, 62, 29, 43, 61, 59
};
enum Modifier { Shift, SymbolShift, Keyset, Control, Alt };
const int special_action_targets[22] = {
enum Modifier { Shift, SymbolShift, Keyset, Control, Alt, Gui, Function };
const int special_action_targets[23] = {
// - \ / '
KEY_MINUS, KEY_MINUS + MASK_ALTGR, KEY_SLASH, KEY_QUOTE,
// , ! ? .
KEY_COMMA, KEY_1 + MASK_SHIFT, KEY_SLASH + MASK_SHIFT, KEY_PERIOD,
KEY_UP, KEY_DOWN, KEY_PAGE_UP, KEY_PAGE_DOWN,
Modifier::Shift, Modifier::SymbolShift, Modifier::Keyset,
KEY_ESC, Modifier::Control, Modifier::Alt, KEY_DELETE, KEY_INSERT,
KEY_TAB, KEY_ENTER
KEY_ESC, Modifier::Control, Modifier::Alt, KEY_DELETE,
Modifier::Function, Modifier::Gui, KEY_TAB, KEY_ENTER
};
const int special_action_targets_symbol[22] = {
const int special_action_targets_symbol[23] = {
// _ ` ´ "
KEY_MINUS + MASK_SHIFT, KEY_TILDE, KEY_SEMICOLON + MASK_ALTGR, KEY_2 + MASK_SHIFT,
// ; | ~ :
KEY_SEMICOLON, KEY_TILDE + MASK_ALTGR, KEY_BACKSLASH + MASK_SHIFT, KEY_SEMICOLON + MASK_SHIFT,
0, 0, 0, 0,
0, 0, 0,
0, 0, 0, 0, 0,
0, 0
0, 0, 0, 0,
0, 0, 0, 0
};
const byte special_action_target_types[22] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0
const int special_action_targets_function[23] = {
0, 0, 0, 0,
0, 0, 0, 0,
KEY_MEDIA_VOLUME_INC, KEY_MEDIA_VOLUME_DEC, 0, 0,
0, 0, 0,
0, 0, 0, KEY_PRINTSCREEN,
0, 0, 0, 0
};
const byte special_action_target_types[23] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0
};
byte key_pressed = 0;
@ -135,6 +157,8 @@ bool mod_symbol_lock = false;
bool mod_control = false;
bool mod_alt = false;
bool mod_altgr = false;
bool mod_gui = false;
bool mod_function = false;
IntervalTimer trackball_timer;
volatile bool trackball_update = false;
@ -318,10 +342,12 @@ void key_released(byte key) {
return;
target = special_action_targets[special];
if (mod_shift || mod_shift_lock || mod_symbol || mod_symbol_lock) {
if (special_action_targets_symbol[special] != 0)
if ((mod_shift || mod_shift_lock || mod_symbol || mod_symbol_lock) &&
special_action_targets_symbol[special] != 0)
target = special_action_targets_symbol[special];
}
if (mod_function &&
special_action_targets_function[special] != 0)
target = special_action_targets_function[special];
switch (special_action_target_types[special]) {
case ActionType::PressKey:
@ -354,6 +380,12 @@ void key_released(byte key) {
case Modifier::Alt:
mod_alt = !mod_alt;
return;
case Modifier::Gui:
mod_gui = !mod_gui;
return;
case Modifier::Function:
mod_function = !mod_function;
return;
}
}
return;
@ -378,8 +410,12 @@ void key_released(byte key) {
if (!chorded_pressed && key_pressed == 0 &&
key_pressed_total == chords[chord]) {
target = chord_targets[chord * 4];
if (mod_symbol || mod_symbol_lock)
if ((mod_symbol || mod_symbol_lock) &&
chord_targets_symbol[chord * 4] != 0)
target = chord_targets_symbol[chord * 4];
if (mod_function &&
chord_targets_function[chord * 4] != 0)
target = chord_targets_function[chord * 4];
press_key(target);
return;
@ -388,8 +424,12 @@ void key_released(byte key) {
for (byte b = 0; b < 3; b++) {
if (key == chord_buttons[chord * 3 + b]) {
target = chord_targets[chord * 4 + 1 + b];
if (mod_symbol || mod_symbol_lock)
if ((mod_symbol || mod_symbol_lock) &&
chord_targets_symbol[chord * 4 + 1 + b] != 0)
target = chord_targets_symbol[chord * 4 + 1 + b];
if (mod_function &&
chord_targets_function[chord * 4 + 1 + b] != 0)
target = chord_targets_function[chord * 4 + 1 + b];
// erase key from total so you can hold the chord down for
// multiple chorded keypresses
@ -406,7 +446,9 @@ void key_released(byte key) {
REGULAR KEYS
*/
// keypress
if (mod_symbol || mod_symbol_lock)
if (mod_function && button_characters_function[key] != 0)
press_key(button_characters_function[key]);
else if (mod_symbol || mod_symbol_lock)
press_key(button_characters_symbol[key]);
else
press_key(button_characters[key]);
@ -414,6 +456,9 @@ void key_released(byte key) {
}
void press_key(int key) {
Serial.print("press key ");
Serial.println(key);
// check if modifiers need to be forced
if (key & MASK_SHIFT) {
mod_shift = true;
@ -423,6 +468,10 @@ void press_key(int key) {
mod_altgr = true;
key &= ~(MASK_ALTGR);
}
if (key & MASK_CTRL) {
mod_control = true;
key &= ~(MASK_CTRL);
}
// modifiers
if (mod_shift || mod_shift_lock)
@ -433,6 +482,8 @@ void press_key(int key) {
Keyboard.press(KEY_LEFT_ALT);
if (mod_altgr)
Keyboard.press(KEY_RIGHT_ALT);
if (mod_gui)
Keyboard.press(KEY_LEFT_GUI);
// keypress
Keyboard.press(key);
@ -447,15 +498,18 @@ void press_key(int key) {
Keyboard.release(KEY_LEFT_ALT);
if (mod_altgr)
Keyboard.release(KEY_RIGHT_ALT);
if (mod_gui)
Keyboard.release(KEY_LEFT_GUI);
// clear temporary modifiers
mod_shift = mod_symbol = mod_control = mod_alt = mod_altgr = false;
mod_shift = mod_symbol = mod_control = mod_alt = mod_altgr =
mod_gui = mod_function = false;
}
void update_leds() {
digitalWrite(PIN_LED1, mod_shift || mod_shift_lock);
digitalWrite(PIN_LED2, mod_symbol || mod_symbol_lock);
digitalWrite(PIN_LED3, mod_control || mod_alt);
digitalWrite(PIN_LED3, mod_control || mod_alt || mod_gui || mod_function);
}
int sign(int num) {