Created
October 25, 2012 13:20
-
-
Save Crenshinibon/3952501 to your computer and use it in GitHub Desktop.
On the fly key mapping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//discover correct keyCodes | |
static void calcKeyCodes(){ | |
//a special case for caps lock | |
//switch caps lock and submit | |
if((modifiers[0] & M2L->keyCode) && (modifiers[0] & M2R->keyCode)){ | |
modifiers[0] = 0x00; | |
keyCodes[0] = KC_CAPSLOCK; | |
keyCodeIndex = 1; | |
if(!capslock){ | |
capslock = true; | |
} | |
else{ | |
capslock = false; | |
} | |
} | |
else { | |
//iterate over all pressed keys | |
for(int i = 0; i < pressedKeyIndex; i++){ | |
if(keyCodeIndex < MAX_KEYS_PRESSED){ | |
Key * key = pressedKeys[i]; | |
//no modifiers, special case for acute sign | |
if(noModifiers()){ | |
if(key == ACUTE2){ | |
enableShift(); | |
keyCodes[keyCodeIndex] = key->keyCode; | |
keyCodeIndex++; | |
} | |
else { | |
keyCodes[keyCodeIndex] = key->keyCode; | |
keyCodeIndex++; | |
} | |
} | |
else { | |
//shift pressed and number keys | |
if(m2Pressed() && key == N6){ | |
keyCodes[keyCodeIndex] = N4->keyCode; | |
keyCodeIndex++; | |
} | |
else if(m2Pressed() && key == N7){ | |
enableAlt(); disableShift(); | |
keyCodes[keyCodeIndex] = E->keyCode; | |
keyCodeIndex++; | |
} | |
//... | |
//m3 e.g. alt pressed | |
//... | |
else if(m3Pressed() && key == H){ | |
keyCodes[keyCodeIndex] = 0x64; | |
keyCodeIndex++; | |
} | |
else if(m3Pressed() && key == G){ | |
keyCodes[keyCodeIndex] = 0x64; | |
enableShift(); | |
keyCodeIndex++; | |
} | |
//... | |
//m4 neo2 keys for programming | |
//... | |
else if(m4Pressed() && key == N6){ | |
keyCodes[keyCodeIndex] = N4->keyCode; | |
enableShift(); enableAlt(); | |
keyCodeIndex++; | |
} | |
else if(m4Pressed() && key == N9){ | |
keyCodes[keyCodeIndex] = KC_7; | |
enableShift(); | |
keyCodeIndex++; | |
} | |
//... | |
else if(m4Pressed() && key == Z){ | |
keyCodes[keyCodeIndex] = KC_UNDO; | |
keyCodeIndex++; | |
} | |
//no modification necessary | |
else { | |
keyCodes[keyCodeIndex] = key->keyCode; | |
keyCodeIndex++; | |
} | |
} | |
} | |
} | |
} | |
} | |
//some helpers | |
static boolean m2Pressed(){ | |
return (modifiers[0] & M2L->keyCode) || (modifiers[0] & M2R->keyCode); | |
} | |
static boolean m3Pressed(){ | |
return modifiers[1] & M3->keyCode; | |
} | |
static boolean m4Pressed(){ | |
return modifiers[1] & M4->keyCode; | |
} | |
static boolean noModifiers(){ | |
return !m2Pressed() && !m3Pressed() && !m4Pressed(); | |
//return modifiers[1] == 0 && (modifiers[0] & 0x22) == 0 | |
} | |
static void enableAlt(){ | |
modifiers[0] = modifiers[0] | ALTL->keyCode; | |
} | |
static void disableAlt(){ | |
modifiers[0] = modifiers[0] & ~ ALTL->keyCode; | |
modifiers[0] = modifiers[0] & ~ ALTR->keyCode; | |
} | |
static void enableShift(){ | |
modifiers[0] = modifiers[0] | M2L->keyCode; | |
} | |
static void disableShift(){ | |
modifiers[0] = modifiers[0] & ~ M2L->keyCode; | |
modifiers[0] = modifiers[0] & ~ M2R->keyCode; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment