Skip to content

Commit

Permalink
Caps in not always shift
Browse files Browse the repository at this point in the history
Caps behaves like shift only for latin characters.
In case we're typing - for example with caps enabled, SLOF picks _ char
from shifted table.

Threat caps as shift only for letters.

Signed-off-by: Dinar Valeev <[email protected]>
  • Loading branch information
Dinar Valeev committed May 20, 2015
1 parent 7d766a3 commit 4e0a6fa
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/libusb/usb-hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ uint8_t set_leds;
const uint8_t *key_std = NULL;
const uint8_t *key_std_shift = NULL;

uint8_t ctrl; /* modifiers */

/**
* read character from Keyboard-Buffer
*
Expand Down Expand Up @@ -120,22 +122,27 @@ static void write_key(uint8_t key)
static void get_char(uint8_t ctrl, uint8_t keypos)
{
uint8_t ch;
int caps = 0;
//key position for latin letters
#define KEYP_LATIN_A 4
#define KEYP_LATIN_Z 29

#ifdef KEY_DEBUG
printf("pos %02X\n", keypos);
#endif

if (set_leds & LED_CAPS_LOCK) /* is CAPS Lock set ? */
ctrl |= MODIFIER_SHIFT; /* simulate shift */
caps = 1;

if (ctrl == 0) {
/* caps is a shift only for latin chars */
if ((caps == 0 && ctrl == 0) || (caps == 1 && (keypos < KEYP_LATIN_A || keypos > KEYP_LATIN_Z))) {
ch = key_std[keypos];
if (ch != 0)
write_key(ch);
return;
}

if (ctrl & MODIFIER_SHIFT) {
if ((ctrl & MODIFIER_SHIFT) || caps == 1) {
ch = key_std_shift[keypos];
if (ch != 0)
write_key(ch);
Expand Down Expand Up @@ -187,6 +194,12 @@ static void check_key_code(uint8_t *buf)
set_leds ^= LED_CAPS_LOCK;
break;

case 0x36: /*Shift pressed*/
ctrl |= MODIFIER_SHIFT;
break;
case 0xb6: /*Shift unpressed*/
ctrl &= ~MODIFIER_SHIFT;
break;
case 0x3a: /* F1 */
write_key(0x1b);
write_key(0x5b);
Expand Down

0 comments on commit 4e0a6fa

Please sign in to comment.