From 2f4c9df1416456b8f8cba9752e10460a68f9ad52 Mon Sep 17 00:00:00 2001 From: compiler Date: Thu, 29 Sep 2016 23:07:33 +0800 Subject: [PATCH 1/2] treating modifier key triggered by macro combo as ghost key, prevent them from interrupting current activating modifier keys pressed manually --- Macro/PartialMap/kll.h | 9 +++++++++ Macro/PartialMap/result.c | 2 +- Output/pjrcUSB/output_com.c | 25 +++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/Macro/PartialMap/kll.h b/Macro/PartialMap/kll.h index c7016a335..d3f0c26bc 100644 --- a/Macro/PartialMap/kll.h +++ b/Macro/PartialMap/kll.h @@ -109,6 +109,11 @@ typedef struct ResultGuide { uint8_t args; // This is used as an array pointer (but for packing purposes, must be 8 bit) } ResultGuide; +#define KEY_TYPE_GHOST 0xC0 + +#define KEY_TYPE_NORMAL 0x00 +#define KEY_TYPE_LED 0x01 +#define KEY_TYPE_ANALOG 0x02 // -- Trigger Macro @@ -119,6 +124,10 @@ typedef struct ResultGuide { // * 0x01 LED State (On/Off) // * 0x02 Analog (Threshold) // * 0x03-0xFE Reserved +// * 0xCX Ghost Key +// * -- 0xC0 Normal +// * -- 0xC1 LED State +// * -- 0xC2 Analog // * 0xFF Debug State // // Key State: diff --git a/Macro/PartialMap/result.c b/Macro/PartialMap/result.c index 6cf2343af..9f21280c5 100644 --- a/Macro/PartialMap/result.c +++ b/Macro/PartialMap/result.c @@ -88,7 +88,7 @@ inline ResultMacroEval Macro_evalResultMacro( var_uint_t resultMacroIndex ) void (*capability)(uint8_t, uint8_t, uint8_t*) = (void(*)(uint8_t, uint8_t, uint8_t*))(CapabilitiesList[ guide->index ].func); // Call capability - capability( record->state, record->stateType, &guide->args ); + capability( record->state, record->stateType | (comboLength > 1?KEY_TYPE_GHOST:0x00), &guide->args ); // Increment counters funcCount++; diff --git a/Output/pjrcUSB/output_com.c b/Output/pjrcUSB/output_com.c index 6f53c2c83..2ed95728d 100644 --- a/Output/pjrcUSB/output_com.c +++ b/Output/pjrcUSB/output_com.c @@ -43,6 +43,8 @@ // KLL #include +#include + // Local Includes #include "output_com.h" @@ -103,6 +105,7 @@ CLIDict_Def( outputCLIDict, "USB Module Commands" ) = { // 16=right ctrl, 32=right shift, 64=right alt, 128=right gui uint8_t USBKeys_Modifiers = 0; uint8_t USBKeys_ModifiersCLI = 0; // Separate CLI send buffer +uint8_t USBKeys_ModifiersManual= 0; // Currently pressed keys, max is defined by USB_MAX_KEY_SEND uint8_t USBKeys_Keys [USB_NKRO_BITFIELD_SIZE_KEYS]; @@ -334,6 +337,8 @@ void Output_sysCtrlSend_capability( uint8_t state, uint8_t stateType, uint8_t *a void Output_usbCodeSend_capability( uint8_t state, uint8_t stateType, uint8_t *args ) { #if enableKeyboard_define == 1 + uint8_t is_ghost_key = stateType & KEY_TYPE_GHOST; + stateType &= ~0xC0; // Display capability name if ( stateType == 0xFF && state == 0xFF ) { @@ -415,7 +420,7 @@ void Output_usbCodeSend_capability( uint8_t state, uint8_t stateType, uint8_t *a // Set the modifier bit if this key is a modifier if ( (key & 0xE0) == 0xE0 ) // AND with 0xE0 (Left Ctrl, first modifier) { - if ( keyPress ) + if ( keyPress) { USBKeys_Modifiers |= 1 << (key ^ 0xE0); // Left shift 1 by key XOR 0xE0 } @@ -423,8 +428,24 @@ void Output_usbCodeSend_capability( uint8_t state, uint8_t stateType, uint8_t *a { USBKeys_Modifiers &= ~(1 << (key ^ 0xE0)); // Left shift 1 by key XOR 0xE0 } + if(! is_ghost_key ){ + USBKeys_Changed |= USBKeyChangeState_Modifiers; + USBKeys_ModifiersManual = USBKeys_Modifiers; + }else{ + if( Output_DebugMode ){ + dbug_msg("ghost modifier key "); + printHex(key); + print(" state="); + printHex(state); + print(NL); + } + if ( (USBKeys_ModifiersManual & USBKeys_Modifiers) == USBKeys_ModifiersManual){ + USBKeys_Changed |= USBKeyChangeState_Modifiers; + }else{ + USBKeys_Modifiers = USBKeys_ModifiersManual; + } + } - USBKeys_Changed |= USBKeyChangeState_Modifiers; break; } // First 6 bytes From 3ded21fcdf9761b87be3e49acb7f5ea2d37e9657 Mon Sep 17 00:00:00 2001 From: compiler Date: Fri, 30 Sep 2016 10:40:19 +0800 Subject: [PATCH 2/2] blocking ghosting modifier key when other key pressed --- Output/pjrcUSB/output_com.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Output/pjrcUSB/output_com.c b/Output/pjrcUSB/output_com.c index 2ed95728d..f4e4326f2 100644 --- a/Output/pjrcUSB/output_com.c +++ b/Output/pjrcUSB/output_com.c @@ -417,6 +417,17 @@ void Output_usbCodeSend_capability( uint8_t state, uint8_t stateType, uint8_t *a break; case 1: // NKRO Mode + if ( keyPress && ! is_ghost_key && USBKeys_Modifiers ^ USBKeys_ModifiersManual){ + if( Output_DebugMode){ + dbug_msg("plain key pressed, modifiers="); + printHex(USBKeys_Modifiers); + print(" ,modifiers_manual="); + printHex(USBKeys_ModifiersManual); + print(NL); + } + USBKeys_Modifiers = USBKeys_ModifiersManual; + USBKeys_Changed |= USBKeyChangeState_Modifiers; + } // Set the modifier bit if this key is a modifier if ( (key & 0xE0) == 0xE0 ) // AND with 0xE0 (Left Ctrl, first modifier) { @@ -437,9 +448,12 @@ void Output_usbCodeSend_capability( uint8_t state, uint8_t stateType, uint8_t *a printHex(key); print(" state="); printHex(state); + printHex(USBKeys_Modifiers); + print("/"); + printHex(USBKeys_ModifiersManual); print(NL); } - if ( (USBKeys_ModifiersManual & USBKeys_Modifiers) == USBKeys_ModifiersManual){ + if ( USBKeys_Modifiers >= USBKeys_ModifiersManual){ USBKeys_Changed |= USBKeyChangeState_Modifiers; }else{ USBKeys_Modifiers = USBKeys_ModifiersManual;