static uSynergyBool uSynergyConnectDevice(uSynergyCookie cookie) { struct input_id device_id; device_id.bustype = BUS_VIRTUAL; device_id.vendor = 1; device_id.product = 1; device_id.version = 0x0100; cookie->uinput_keyboard = suinput_open("usynergy-keyboard", &(cookie->device_id), keyboard); cookie->uinput_mouse = suinput_open("usynergy-mouse", &(cookie->device_id), mouse); if (cookie->uinput_mouse < 0 || cookie->uinput_keyboard < 0) return USYNERGY_FALSE; return USYNERGY_TRUE; }
bool openInputWithoutPermission(int scrWidth, int scrHeight){ LOGD(LOGTAG, "Opening input device..."); struct input_id id = { BUS_VIRTUAL, /* Bus type. */ 1, /* Vendor id. */ 1, /* Product id. */ 1 /* Version id. */ }; if((inputFd = suinput_open("qwerty", &id, scrWidth, scrHeight)) == -1){ LOGD(LOGTAG, "Cannot open device - 'qwerty'"); return false; } LOGI(LOGTAG, "Opened device 'qwerty'"); return true; }
void initInput() { L("---Initializing uinput...---\n"); struct input_id id = { BUS_VIRTUAL, /* Bus type. */ 1, /* Vendor id. */ 1, /* Product id. */ 1 /* Version id. */ }; if((inputfd = suinput_open("Generic", &id)) == -1) { L("cannot create virtual kbd device.\n"); sendMsgToGui("~SHOW|Cannot create virtual input device!\n"); // exit(EXIT_FAILURE); do not exit, so we still can see the framebuffer } }
int main(void) { int uinput_fd; int btns[] = {BTN_LEFT, BTN_RIGHT, BTN_MIDDLE}; int rel_axes[] = {REL_X, REL_Y, REL_WHEEL}; struct uinput_user_dev user_dev; int i; memset(&user_dev, 0, sizeof(struct uinput_user_dev)); strcpy(user_dev.name, "libsuinput-example-mouse"); uinput_fd = suinput_open(); if (uinput_fd == -1) err(1, "suinput_open"); /* Error handling is omitted to keep code as readible as possible. */ for (i = 0; i < 3; ++i) { suinput_enable_event(uinput_fd, EV_KEY, btns[i]); } for (i = 0; i < 3; ++i) { suinput_enable_event(uinput_fd, EV_REL, rel_axes[i]); } suinput_create(uinput_fd, &user_dev); /* Move pointer 20 * 5 units towards bottom-right. */ for (i = 0; i < 20; ++i) { struct timespec sleeptime = {0, 50000000}; suinput_emit(uinput_fd, EV_REL, REL_X, 5); suinput_emit(uinput_fd, EV_REL, REL_Y, 5); suinput_syn(uinput_fd); nanosleep(&sleeptime, NULL); } suinput_emit_click(uinput_fd, BTN_LEFT); suinput_destroy(uinput_fd); return 0; }