Skip to content

Commit eec7c75

Browse files
author
Dinar Valeev
committed
Caps in not always shift
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]>
1 parent 7d766a3 commit eec7c75

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

lib/libusb/usb-hid.c

+16-3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ uint8_t set_leds;
8383
const uint8_t *key_std = NULL;
8484
const uint8_t *key_std_shift = NULL;
8585

86+
uint8_t ctrl; /* modifiers */
87+
8688
/**
8789
* read character from Keyboard-Buffer
8890
*
@@ -120,22 +122,27 @@ static void write_key(uint8_t key)
120122
static void get_char(uint8_t ctrl, uint8_t keypos)
121123
{
122124
uint8_t ch;
125+
int caps = 0;
126+
//key position for latin letters
127+
#define A 4
128+
#define Z 29
123129

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

128134
if (set_leds & LED_CAPS_LOCK) /* is CAPS Lock set ? */
129-
ctrl |= MODIFIER_SHIFT; /* simulate shift */
135+
caps = 1;
130136

131-
if (ctrl == 0) {
137+
/* caps is a shift only for latin chars */
138+
if ((caps == 0 && ctrl == 0) || (caps == 1 && (keypos < A || keypos > Z))) {
132139
ch = key_std[keypos];
133140
if (ch != 0)
134141
write_key(ch);
135142
return;
136143
}
137144

138-
if (ctrl & MODIFIER_SHIFT) {
145+
if ((ctrl & MODIFIER_SHIFT) || caps == 1) {
139146
ch = key_std_shift[keypos];
140147
if (ch != 0)
141148
write_key(ch);
@@ -187,6 +194,12 @@ static void check_key_code(uint8_t *buf)
187194
set_leds ^= LED_CAPS_LOCK;
188195
break;
189196

197+
case 0x36: /*Shift pressed*/
198+
ctrl |= MODIFIER_SHIFT;
199+
break;
200+
case 0xb6: /*Shift unpressed*/
201+
ctrl &= ~MODIFIER_SHIFT;
202+
break;
190203
case 0x3a: /* F1 */
191204
write_key(0x1b);
192205
write_key(0x5b);

0 commit comments

Comments
 (0)