Browse Source

Improved shift-handling

master
dirkson 6 months ago
parent
commit
0a94b1c45d
1 changed files with 29 additions and 9 deletions
  1. +29
    -9
      kbd.c

+ 29
- 9
kbd.c View File

@@ -209,8 +209,8 @@ void kbd_init(int *letters, int *fdo, int *fdi, int *ftty, char *str, kbd_chord_

if(ioctl(*fdo, UI_SET_EVBIT, EV_SYN) < 0) kbd_err("ev_syn bit failed");
if(ioctl(*fdo, UI_SET_EVBIT, EV_KEY) < 0) kbd_err("ev_key bit failed - Are you sure that was a keyboard?");
//if(ioctl(*fdo, UI_SET_EVBIT, EV_REP) < 0) kbd_err("error: ioctl");
//if(ioctl(fdo, UI_SET_EVBIT, EV_MSC) < 0) kbd_err("error: ioctl"); //Doesn't do anything useful on my keyboard
//if(ioctl(fdo, UI_SET_EVBIT, EV_REP) < 0) kbd_err("error: ioctl"); //We don't care about repetitions - Kernel can manage them

kbd_load_tty(ftty);

@@ -277,6 +277,16 @@ void kbd_event(int *letters, struct input_event ev, int fdo, int ftty, kbd_state
{
//printf("caught meta press\n");
kbd_state->chord = 1;
if (kbd_state->lshift)
{
kbd_state->lshift = 1;
kbd_releasekey(fdo, KEY_LEFTSHIFT);
}
if (kbd_state->rshift)
{
kbd_state->rshift = 1;
kbd_releasekey(fdo, KEY_RIGHTSHIFT);
}
if (kbd_state->pressed != 0)
{
for (i = kbd_state->pressed-1; i > -1; i--)
@@ -293,18 +303,24 @@ void kbd_event(int *letters, struct input_event ev, int fdo, int ftty, kbd_state
case KEY_RIGHTSHIFT:
if (ev.value == 1)
kbd_state->rshift = 1;
else
kbd_state->rshift = 0;
if(write(fdo, &ev, sizeof(struct input_event)) < 0) kbd_err("cannot write to fake keyboard");
kbd_emit(fdo, EV_SYN, SYN_REPORT, 0);
if (!kbd_state->chord)
{
if (ev.value == 0)
kbd_state->rshift = 0;
if(write(fdo, &ev, sizeof(struct input_event)) < 0) kbd_err("cannot write to fake keyboard");
kbd_emit(fdo, EV_SYN, SYN_REPORT, 0);
}
break;
case KEY_LEFTSHIFT:
if (ev.value == 1)
kbd_state->lshift = 1;
else
kbd_state->lshift = 0;
if(write(fdo, &ev, sizeof(struct input_event)) < 0) kbd_err("cannot write to fake keyboard");
kbd_emit(fdo, EV_SYN, SYN_REPORT, 0);
if (!kbd_state->chord)
{
if (ev.value == 0)
kbd_state->lshift = 0;
if(write(fdo, &ev, sizeof(struct input_event)) < 0) kbd_err("cannot write to fake keyboard");
kbd_emit(fdo, EV_SYN, SYN_REPORT, 0);
}
break;
case KEY_LEFTMETA:
case KEY_LEFTCTRL:
@@ -347,6 +363,10 @@ void kbd_event(int *letters, struct input_event ev, int fdo, int ftty, kbd_state
result = kbd_find_result(root, ftty, 0, kbd_state->key, kbd_state->num, &resultlen);
if (result != NULL && resultlen > 1)
{
if (kbd_state->lshift)
kbd_presskey(fdo, KEY_LEFTSHIFT);
if (kbd_state->rshift)
kbd_presskey(fdo, KEY_RIGHTSHIFT);
kbd_tapkey(fdo, letters[(int)(tolower(result[0])-97)]);
if (kbd_state->lshift)
kbd_releasekey(fdo, KEY_LEFTSHIFT);


Loading…
Cancel
Save