Fixes the bug of additional characters when mod key is released before the other key
This commit is contained in:
3
right/src/keyboard_layout.c
Normal file
3
right/src/keyboard_layout.c
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#include "keyboard_layout.h"
|
||||||
|
|
||||||
|
uint8_t keyMasks[LAYOUT_KEY_COUNT];
|
||||||
@@ -35,11 +35,20 @@
|
|||||||
#define MODIFIER_MOD_PRESSED 1
|
#define MODIFIER_MOD_PRESSED 1
|
||||||
#define MODIFIER_FN_PRESSED 2
|
#define MODIFIER_FN_PRESSED 2
|
||||||
|
|
||||||
|
extern uint8_t keyMasks[LAYOUT_KEY_COUNT];
|
||||||
|
|
||||||
|
|
||||||
static inline __attribute__((always_inline)) uint8_t getKeycode(KEYBOARD_LAYOUT(layout), uint8_t keyId, uint8_t modifierState)
|
static inline __attribute__((always_inline)) uint8_t getKeycode(KEYBOARD_LAYOUT(layout), uint8_t keyId, uint8_t modifierState)
|
||||||
{
|
{
|
||||||
if (keyId<LAYOUT_KEY_COUNT) {
|
if (keyId<LAYOUT_KEY_COUNT) {
|
||||||
|
if (keyMasks[keyId]!=0 && keyMasks[keyId]!=modifierState){
|
||||||
|
//Mask out key presses after releasing modifier keys
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t k = layout[keyId][modifierState];
|
uint8_t k = layout[keyId][modifierState];
|
||||||
|
keyMasks[keyId] = modifierState;
|
||||||
|
|
||||||
if (k==0) {
|
if (k==0) {
|
||||||
k = layout[keyId][0];
|
k = layout[keyId][0];
|
||||||
}
|
}
|
||||||
@@ -62,4 +71,17 @@ static inline __attribute__((always_inline)) uint8_t getModifierState(const uint
|
|||||||
return mod;
|
return mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline __attribute__((always_inline)) void clearKeymasks(const uint8_t *leftKeyStates, const uint8_t *rightKeyStates){
|
||||||
|
int i;
|
||||||
|
for (i=0; i<KEY_STATE_COUNT; ++i){
|
||||||
|
if (rightKeyStates[i]==0){
|
||||||
|
keyMasks[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (leftKeyStates[i]==0){
|
||||||
|
keyMasks[LAYOUT_LEFT_OFFSET+i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -101,6 +101,7 @@ void usbKeyboadTask(){
|
|||||||
readLeftKeys(leftKeyStates);
|
readLeftKeys(leftKeyStates);
|
||||||
|
|
||||||
uint8_t modifierState = getModifierState(leftKeyStates, keyMatrix.keyStates);
|
uint8_t modifierState = getModifierState(leftKeyStates, keyMatrix.keyStates);
|
||||||
|
clearKeymasks(leftKeyStates, keyMatrix.keyStates);
|
||||||
|
|
||||||
int scancodeIdx = 0;
|
int scancodeIdx = 0;
|
||||||
for (uint8_t keyId=0; keyId<KEYBOARD_MATRIX_COLS_NUM*KEYBOARD_MATRIX_ROWS_NUM; keyId++) {
|
for (uint8_t keyId=0; keyId<KEYBOARD_MATRIX_COLS_NUM*KEYBOARD_MATRIX_ROWS_NUM; keyId++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user