/* if no input is waiting, the value ERR (-1) is returned */ int console_getkey(struct Console* con) { int ret = wgetch(stdscr); int res = translate_event(con, ret); if(res == CK_RESIZE_EVENT) deal_with_resize_signal(); PDEBUG("getkey res: %d\n", res); return res; }
/* * Input thread reading from device. * Generates events on incoming data. */ static void* linux_input_EventThread( CoreThread *thread, void *driver_data ) { LinuxInputData *data = (LinuxInputData*) driver_data; int readlen; struct input_event levt; DFBInputEvent devt; while ((readlen = read( data->fd, &levt, sizeof(levt) )) == sizeof(levt) || (readlen < 0 && errno == EINTR)) { dfb_thread_testcancel( thread ); if (readlen <= 0) continue; if (translate_event( &levt, &devt)) dfb_input_dispatch( data->device, &devt ); } if (readlen <= 0) PERRORMSG ("linux_input thread died\n"); return NULL; }
int console_getkey_nb(struct Console* con) { int ret; timeout(0); // set NCURSES getch to nonblocking ret = wgetch(stdscr); timeout(-1); // set NCURSES getch to blocking int res = translate_event(con, ret); if(res == CK_RESIZE_EVENT) deal_with_resize_signal(); return res; }
int main(int argc, char **argv) { init_interesting_keys(); if (argc >= 2 && strcmp(argv[1], "-v") == 0) { argv++; argc--; verbose = 1; } source_evdev_fd = open(argv[1], O_RDONLY); if (source_evdev_fd < 0) { perror("evdev open"); exit(1); } while (argc > 2) { pthread_t thread; pthread_create(&thread, 0, events_eater, argv[--argc]); } create_uinput(); if (ioctl(source_evdev_fd, EVIOCGRAB, 1) < 0) { perror("EVIOCGRAB"); exit(1); } struct uinput_user_dev devinfo = { .name = "repeater", .id = { .bustype = BUS_VIRTUAL, .vendor = 0xffff, .product = 0xffff, .version = 1 } }; write(uinput_fd, &devinfo, sizeof(devinfo)); xioctl(uinput_fd, UI_DEV_CREATE, 0); struct input_event ev; while (1) { read_all(source_evdev_fd, &ev, sizeof(ev)); if (!translate_event(&ev)) continue; write_event(&ev); if (verbose) putchar('\n'); } }
void level_event::translate_test(void) { assert(!strcmp(translate_event(AN_RUN), "AN_RUN")); assert(!strcmp(translate_event(GC_MENU_SETTINGS), "GC_MENU_SETTINGS")); assert(!strcmp(translate_event(GC_MENU_QUIT), "GC_MENU_QUIT")); assert(!strcmp(translate_event(ED_LEVEL_RUN), "ED_LEVEL_RUN")); assert(!strcmp(translate_event(ED_QUIT), "ED_QUIT")); assert(!strcmp(translate_event(EV_LAST), "EV_LAST")); int size = (sizeof(level_event::translation_table)/sizeof(level_event::translation_table[0])); assert(size == EV_LAST+1); }