Beispiel #1
0
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;
        }
    }
}
Beispiel #3
0
void tetris_send_newline(void) {
  send_keycode(KC_ENT);
}
Beispiel #4
0
void tetris_send_delete(void) {
  send_keycode(KC_DEL);
}
Beispiel #5
0
void tetris_send_backspace(void) {
  send_keycode(KC_BSPC);
}
Beispiel #6
0
void tetris_send_right(void) {
  send_keycode(KC_RGHT);
}
Beispiel #7
0
void tetris_send_down(void) {
  send_keycode(KC_DOWN);
}
Beispiel #8
0
void tetris_send_left(void) {
  send_keycode(KC_LEFT);
}
Beispiel #9
0
void tetris_send_up(void) {
  send_keycode(KC_UP);
}