void tetris_send_string(const char *s) { for (int i = 0; s[i] != 0; i++) { if (s[i] >= 'a' && s[i] <= 'z') { send_keycode(KC_A + (s[i] - 'a')); } else if (s[i] >= 'A' && s[i] <= 'Z') { send_keycode_shift(KC_A + (s[i] - 'A')); } else if (s[i] >= '1' && s[i] <= '9') { send_keycode(KC_1 + (s[i] - '1')); } else { switch (s[i]) { case ' ': send_keycode(KC_SPACE); break; case '.': send_keycode(KC_DOT); break; case '0': send_keycode(KC_0); break; } } } }
int main (int argc, char ** argv ) { int fd_hidraw; int fd_uinput; int res = 0; char buf[8]; unsigned char lastkeycode = KEY_1 ; struct input_event ev; memset(buf, 0, sizeof(buf)); memset(&ev, 0, sizeof(ev)); //find and open hidraw device fd_hidraw = find_and_open_p6s(); if (fd_hidraw < 0) { printf("Unable to find or open Skypemate P6S device.\n"); return 1; } fd_uinput = prepare_uinput_device(); if (fd_uinput < 0) { return 1; } printf("Translating events started. Press ^C to stop.\n"); while(1) { res = read(fd_hidraw, buf, 8); // read a HID report from the device if (res>=0) { char c = buf[1];//code from hidraw if (c == (char)0xff) { //send key release send_keycode(ev,fd_uinput,lastkeycode,0); } else { //send key press lastkeycode = mapping[(int)c]; // mapped KEY_* send_keycode(ev,fd_uinput,lastkeycode,1); } } else { perror("read"); return 1; } } }
void tetris_send_newline(void) { send_keycode(KC_ENT); }
void tetris_send_delete(void) { send_keycode(KC_DEL); }
void tetris_send_backspace(void) { send_keycode(KC_BSPC); }
void tetris_send_right(void) { send_keycode(KC_RGHT); }
void tetris_send_down(void) { send_keycode(KC_DOWN); }
void tetris_send_left(void) { send_keycode(KC_LEFT); }
void tetris_send_up(void) { send_keycode(KC_UP); }