Skip to content
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

Treating modifier keys in a Macro combination as ghostkey #154

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Macro/PartialMap/kll.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Macro/PartialMap/result.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down
39 changes: 37 additions & 2 deletions Output/pjrcUSB/output_com.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
// KLL
#include <kll_defs.h>

#include <kll.h>

// Local Includes
#include "output_com.h"

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -412,19 +417,49 @@ 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)
{
if ( keyPress )
if ( keyPress)
{
USBKeys_Modifiers |= 1 << (key ^ 0xE0); // Left shift 1 by key XOR 0xE0
}
else // Release
{
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);
printHex(USBKeys_Modifiers);
print("/");
printHex(USBKeys_ModifiersManual);
print(NL);
}
if ( USBKeys_Modifiers >= USBKeys_ModifiersManual){
USBKeys_Changed |= USBKeyChangeState_Modifiers;
}else{
USBKeys_Modifiers = USBKeys_ModifiersManual;
}
}

USBKeys_Changed |= USBKeyChangeState_Modifiers;
break;
}
// First 6 bytes
Expand Down