shift as modifier

This commit is contained in:
pesceWanda 2016-07-07 23:24:45 -04:00
parent 1f87adf03f
commit f7903197b8

View file

@ -1,6 +1,6 @@
/* Arduino Keyboard HID driver and USB host shield pass through */ /* Arduino Keyboard HID driver and USB host shield pass through */
/*- /*
* Copyright (c) 2011 Darran Hunt (darran [at] hunt dot net dot nz) * Copyright (c) 2011 Darran Hunt (darran [at] hunt dot net dot nz)
* All rights reserved. * All rights reserved.
* *
@ -56,8 +56,8 @@ bool numLock = false;
bool capsLock = false; bool capsLock = false;
bool scrollLock = false; bool scrollLock = false;
uint8_t dvorak_changer (uint8_t ch, uint8_t mod);
void setup(); void setup();
uint8_t dvorak_changer (uint8_t ch, uint8_t mod);
void loop(); void loop();
bool key_is_new(byte key, byte *report); bool key_is_new(byte key, byte *report);
@ -69,9 +69,9 @@ void setup()
Serial.begin(9600); Serial.begin(9600);
Max.powerOn(); Max.powerOn();
delay(200); delay(200);
digitalWrite(13, HIGH); digitalWrite(13, HIGH);
delay (1000); delay (1000);
digitalWrite (13, LOW); digitalWrite (13, LOW);
} }
void loop() void loop()
@ -125,81 +125,82 @@ void kbd_poll(void)
/* poll keyboard */ /* poll keyboard */
rcode = Usb.inTransfer(KBD_ADDR, KBD_EP, 8, (char *)buf); rcode = Usb.inTransfer(KBD_ADDR, KBD_EP, 8, (char *)buf);
if (rcode != 0) { if (rcode != 0) {
return; return;
} }
for (i = 2; i < 8; ++i) {
buf[i] = dvorak_changer (buf[i], buf[0]);
}
// Serial.print ("Modifier = "); // Serial.print ("Modifier = ");
// Serial.println (buf[0]); // Serial.println (buf[0]);
/* Check for change */ /* Check for change */
for (i=0; i<8; i++) { for (i=0; i<8; i++) {
if (buf[i] != old_buf[i]) { if (buf[i] != old_buf[i]) {
/* Send the new key presses to the host */ for (i = 2; i < 8; ++i) {
Serial.write(buf, 8); buf[i] = dvorak_changer (buf[i], buf[0]);
}
/* Get led report */ /* Send the new key presses to the host */
ledReport = Serial.read(); Serial.write(buf, 8);
break;
}
}
/* Check for status keys and adjust led status */ /* Get led report */
for (i=2; i<8; i++) { ledReport = Serial.read();
if (buf[i] == 0) { break;
/* 0 marks end of keys in the report */ }
break; }
}
/* Check new keys for status change keys */ /* Check for status keys and adjust led status */
/*if (key_is_new(buf[i], old_buf)) {*/ for (i=2; i<8; i++) {
/*switch (buf[i]) {*/ if (buf[i] == 0) {
/*case CAPSLOCK:*/ /* 0 marks end of keys in the report */
/*capsLock =! capsLock;*/ break;
/*leds = capsLock ? leds |= REP_CAPSLOCK : leds &= ~REP_CAPSLOCK;*/ }
/*break;*/ /* Check new keys for status change keys */
/*case NUMLOCK:*/ /*if (key_is_new(buf[i], old_buf)) {*/
/*numLock =! numLock;*/ /*switch (buf[i]) {*/
/*leds = numLock ? leds |= REP_NUMLOCK : leds &= ~REP_NUMLOCK;*/ /*case CAPSLOCK:*/
/*break;*/ /*capsLock =! capsLock;*/
/*case SCROLLLOCK:*/ /*leds = capsLock ? leds |= REP_CAPSLOCK : leds &= ~REP_CAPSLOCK;*/
/*scrollLock =! scrollLock;*/ /*break;*/
/*leds = scrollLock ? leds |= REP_SCROLLLOCK : leds &= ~REP_SCROLLLOCK;*/ /*case NUMLOCK:*/
/*break;*/ /*numLock =! numLock;*/
/*default:*/ /*leds = numLock ? leds |= REP_NUMLOCK : leds &= ~REP_NUMLOCK;*/
/*break;*/ /*break;*/
/*}*/ /*case SCROLLLOCK:*/
/*//}*/ /*scrollLock =! scrollLock;*/
} /*leds = scrollLock ? leds |= REP_SCROLLLOCK : leds &= ~REP_SCROLLLOCK;*/
/*break;*/
/*default:*/
/*break;*/
/*}*/
/*//}*/
}
/* Got a change in LED status? */ /* Got a change in LED status? */
if (lastLeds != leds) { if (lastLeds != leds) {
Usb.setReport( KBD_ADDR, 0, 1, KBD_IF, 0x02, 0, (char *)&leds ); Usb.setReport( KBD_ADDR, 0, 1, KBD_IF, 0x02, 0, (char *)&leds );
lastLeds = leds; lastLeds = leds;
} }
/* update the old buffer */ /* update the old buffer */
for (i=0; i<8; i++) { for (i=0; i<8; i++) {
old_buf[i] = buf[i]; old_buf[i] = buf[i];
} }
} }
/* /*
* Function: key_is_new(key, report) * Function: key_is_new(key, report)
* Description: see if key is new or is already in report * Description: see if key is new or is already in report
* Returns: false if found, true if not * Returns: false if found, true if not
*/ */
bool key_is_new(uint8_t key, uint8_t *report) bool key_is_new(uint8_t key, uint8_t *report)
{ {
uint8_t ind; uint8_t ind;
for (ind=2; ind<8; ind++) { for (ind=2; ind<8; ind++) {
if (report[ind] == key) { if (report[ind] == key) {
return false; return false;
} }
} }
return true; return true;
} }
@ -212,143 +213,159 @@ bool key_is_new(uint8_t key, uint8_t *report)
* *
* Modifier keys: * Modifier keys:
* LEFT: * LEFT:
CTRL = 1 CTRL = 1
ALT = 4 ALT = 4
SHIFT = 2 SHIFT = 2
WINKEY = 8 WINKEY = 8
* RIGHT: * RIGHT:
CTRL = 16 CTRL = 16
ALT = 64 ALT = 64
SHIFT = 32 SHIFT = 32
* *
*/ */
uint8_t dvorak_changer (uint8_t ch, uint8_t mod) uint8_t dvorak_changer (uint8_t ch, uint8_t mod)
{ {
if (mod != 8) { // WINKEY as layer key if (mod != 32) { // RIGHTSHIFT as layer key
switch (ch){ switch (ch){
/* begin mid row*/ /* begin mid row*/
case 0x39: // CAPSLOCK --> ESC case 0x39: // CAPSLOCK --> ESC
return 0x29; return 0x29;
/*case 0x04: // A --> A*/ /*case 0x04: // A --> A*/
/*return 0x04;*/ /*return 0x04;*/
case 0x16: // S --> A case 0x16: // S --> A
return 0x12; return 0x12;
case 0x07: // D --> E case 0x07: // D --> E
return 0x08; return 0x08;
case 0x09: // F --> U case 0x09: // F --> U
return 0x18; return 0x18;
case 0x0A: // G --> I case 0x0A: // G --> I
return 0x0C; return 0x0C;
case 0x0B: // H --> D case 0x0B: // H --> D
return 0x07; return 0x07;
case 0x0D: // J --> H case 0x0D: // J --> H
return 0x0B; return 0x0B;
case 0x0E: // K --> T case 0x0E: // K --> T
return 0x17; return 0x17;
case 0x0F: // L --> N case 0x0F: // L --> N
return 0x11; return 0x11;
case 0x033: // : --> S case 0x033: // : --> S
return 0x016; return 0x016;
case 0x34: // " --> - case 0x34: // " --> -
return 0x2D; return 0x2D;
/* end of mid row */ /* end of mid row */
/* begin of upper row */ /* begin of upper row */
case 0x14: // Q --> '@ case 0x14: // Q --> '@
if (mod == 2){ if (mod == 2){
return 0x1F; // Upper case Q to @ return 0x1F; // Upper case Q to @
} else { } else {
return 0x34; // lowercase q to ' return 0x34; // lowercase q to '
} }
case 0x1A: // W --> ,< case 0x1A: // W --> ,<
return 0x36; return 0x36;
case 0x08: // E --> .> case 0x08: // E --> .>
return 0x37; return 0x37;
case 0x15: // R --> P case 0x15: // R --> P
return 0x13; return 0x13;
case 0x17: // T --> Y case 0x17: // T --> Y
return 0x1C; return 0x1C;
case 0x1C: // Y --> F case 0x1C: // Y --> F
return 0x09; return 0x09;
case 0x18: // U --> G case 0x18: // U --> G
return 0x0A; return 0x0A;
case 0x0C: // I --> C case 0x0C: // I --> C
return 0x06; return 0x06;
case 0x12: // O --> R case 0x12: // O --> R
return 0x15; return 0x15;
case 0x13: // P --> L case 0x13: // P --> L
return 0x0F; return 0x0F;
case 0x2F: // [{ --> /? case 0x2F: // [{ --> /?
return 0x38; return 0x38;
case 0x30: // ]} --> =+ case 0x30: // ]} --> =+
return 0x2E; return 0x2E;
/* end upper row */ /* end upper row */
/* begin lower row */ /* begin lower row */
case 0x2E: // += --> ]} case 0x2E: // += --> ]}
return 0x30; return 0x30;
case 0x2D: // -_ --> [{ case 0x2D: // -_ --> [{
return 0x2F; return 0x2F;
case 0x1D: // Z --> :; case 0x1D: // Z --> :;
return 0x33; return 0x33;
case 0x1B: // X --> Q case 0x1B: // X --> Q
return 0x14; return 0x14;
case 0x06: // C --> J case 0x06: // C --> J
return 0x0D; return 0x0D;
case 0x19: // V --> K case 0x19: // V --> K
return 0x0E; return 0x0E;
case 0x05: // B --> X case 0x05: // B --> X
return 0x1B; return 0x1B;
case 0x11: // N --> B case 0x11: // N --> B
return 0x05; return 0x05;
/*case 0x10: // M --> M*/ /*case 0x10: // M --> M*/
/*return 0x10;*/ /*return 0x10;*/
case 0x36: // <, --> W case 0x36: // <, --> W
return 0x1A; return 0x1A;
case 0x37: // >. --> V case 0x37: // >. --> V
return 0x19; return 0x19;
case 0x38: // ?/ --> Z case 0x38: // ?/ --> Z
return 0x1D; return 0x1D;
/* end lower row */ /* end lower row */
/* specials */ /* specials */
case 0x1F: // 2@ --> 2" case 0x1F: // 2@ --> 2"
if (mod == 2) { if (mod == 2) {
return 0x34; return 0x34;
} else { } else {
return 0x1F; return 0x1F;
} }
case 0x31: // \| --> DEL case 0x31: // \| --> DEL
return 0x4C; return 0x4C;
case 0x29: // ESC --> `¬ case 0x29: // ESC --> `¬
return 0x35; return 0x35;
case 0x4C: // DEL --> / case 0x4C: // DEL --> /
return 0x31; return 0x31;
case 0x49: // INS --> BEGIN END case 0x49: // INS --> HOME END
if (mod == 2) { buf[0] = 0;
return 0x5D ; if (mod == 2) {
} else { return 0x4D ;
return 0x4D; } else {
} return 0x4A;
} }
} else { }
switch (ch){ } else {
case 0x0C: // WINKEY + I --> UpArrow buf[0] = 0;
return 0x52; switch (ch){
case 0x0E: // WINKEY + K --> DownArrow case 0x1A: // SHIFTRIGHT + , --> UpArrow
return 0x51; return 0x52;
case 0x0D: // WINKEY + J --> LeftArrow case 0x16: // SHIFTRIGHT + o --> DownArrow
return 0x50; return 0x51;
case 0x0F: // WINKEY + L --> RightArrow case 0x04: // SHIFTRIGHT + a --> LeftArrow
return 0x4F; return 0x50;
} case 0x07: // SHIFTRIGHT + e --> RightArrow
} return 0x4F;
case 0x2E: // += --> ]}
buf[0] = 2;
return 0x32;
case 0x2D: // -_ --> [{
buf[0] = 2;
return 0x2F;
case 0x36: // <, --> W
buf[0] = 2;
return 0x1A;
case 0x37: // >. --> V
buf[0] = 2;
return 0x19;
case 0x38: // ?/ --> Z
buf[0] = 2;
return 0x1D;
}
}
} }