Browse Source

Fixed capitalization

master
dirkson 6 months ago
parent
commit
8a68b1fa70
2 changed files with 44 additions and 10 deletions
  1. +0
    -1
      README.md
  2. +44
    -9
      kbd.c

+ 0
- 1
README.md View File

@@ -6,7 +6,6 @@ kbd aims to be a middle road, exposing a suite of chorded keyboard shortcuts on

## todo

* Improve capitalization
* Add some method of suffix affixation - ing, 's, etc
* Free chord tree before close
* Make loading detect duplicate chords in dictionary


+ 44
- 9
kbd.c View File

@@ -22,6 +22,8 @@ typedef struct kbd_state_t
int pressed;
int totalpressed;
char chord;
char lshift;
char rshift;
} kbd_state_t;

typedef struct kbd_chord_tree_t
@@ -44,10 +46,20 @@ void kbd_presskey(int fdo, int key)
{
kbd_emit(fdo, EV_KEY, key, 1);
kbd_emit(fdo, EV_SYN, SYN_REPORT, 0);
}

void kbd_releasekey(int fdo, int key)
{
kbd_emit(fdo, EV_KEY, key, 0);
kbd_emit(fdo, EV_SYN, SYN_REPORT, 0);
}

void kbd_tapkey(int fdo, int key)
{
kbd_presskey(fdo, key);
kbd_releasekey(fdo, key);
}

void kbd_add_chord(kbd_chord_tree_t *node, int depth, char *chord, int chordlen, char *result, int resultlen)
{
if (depth == chordlen)
@@ -268,21 +280,34 @@ void kbd_event(int *letters, struct input_event ev, int fdo, int ftty, kbd_state
{
for (i = kbd_state->pressed-1; i > -1; i--)
{
kbd_presskey(fdo, KEY_BACKSPACE);
kbd_tapkey(fdo, KEY_BACKSPACE);
//Release any keys pressed before switching to meta mode
kbd_emit(fdo, EV_KEY, kbd_state->key[i], 0);
kbd_emit(fdo, EV_SYN, SYN_REPORT, 0);
kbd_releasekey(fdo, kbd_state->key[i]);
}
}
}
else if (ev.value == 0 && kbd_state->pressed == 0)
kbd_state->chord = 0;
break;
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);
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);
break;
case KEY_LEFTMETA:
case KEY_LEFTCTRL:
case KEY_LEFTSHIFT:
case KEY_RIGHTCTRL:
case KEY_RIGHTSHIFT:
//printf("Caught right meta\n");
if(write(fdo, &ev, sizeof(struct input_event)) < 0) kbd_err("cannot write to fake keyboard");
kbd_emit(fdo, EV_SYN, SYN_REPORT, 0);
@@ -321,9 +346,18 @@ 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)
{
for (j = 0; j < resultlen; j++)
kbd_presskey(fdo, letters[(int)(tolower(result[j])-97)]);
kbd_presskey(fdo, KEY_SPACE);
kbd_tapkey(fdo, letters[(int)(tolower(result[0])-97)]);
if (kbd_state->lshift)
kbd_releasekey(fdo, KEY_LEFTSHIFT);
if (kbd_state->rshift)
kbd_releasekey(fdo, KEY_RIGHTSHIFT);
for (j = 1; j < resultlen; j++)
kbd_tapkey(fdo, letters[(int)(tolower(result[j])-97)]);
kbd_tapkey(fdo, KEY_SPACE);
if (kbd_state->lshift)
kbd_presskey(fdo, KEY_LEFTSHIFT);
if (kbd_state->rshift)
kbd_presskey(fdo, KEY_RIGHTSHIFT);
resultlen = 0;
}

@@ -332,7 +366,6 @@ void kbd_event(int *letters, struct input_event ev, int fdo, int ftty, kbd_state
kbd_state->num=0;
}
//printf("Forwarding keypress: %i %i %i \n", ev.type, ev.code, ev.value);
//kbd_presskey(fdo, ev.code);
}
//enqueue
break;
@@ -383,6 +416,8 @@ int main(int argc, char* argv[])
int fdo, fdi, ftty;
kbd_chord_tree_t root;



if(argc != 2) kbd_err("please specify input device");

kbd_init(letters, &fdo, &fdi, &ftty, argv[1], &root);


Loading…
Cancel
Save