€•ZJŒsphinx.addnodes”Œdocument”“”)”}”(Œ rawsource”Œ”Œchildren”]”(Œ translations”Œ LanguagesNode”“”)”}”(hhh]”(hŒ pending_xref”“”)”}”(hhh]”Œdocutils.nodes”ŒText”“”ŒChinese (Simplified)”…””}”Œparent”hsbaŒ attributes”}”(Œids”]”Œclasses”]”Œnames”]”Œdupnames”]”Œbackrefs”]”Œ refdomain”Œstd”Œreftype”Œdoc”Œ reftarget”Œ /translations/zh_CN/input/uinput”Œmodname”NŒ classname”NŒ refexplicit”ˆuŒtagname”hhh ubh)”}”(hhh]”hŒChinese (Traditional)”…””}”hh2sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ /translations/zh_TW/input/uinput”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒItalian”…””}”hhFsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ /translations/it_IT/input/uinput”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒJapanese”…””}”hhZsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ /translations/ja_JP/input/uinput”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒKorean”…””}”hhnsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ /translations/ko_KR/input/uinput”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒSpanish”…””}”hh‚sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ /translations/sp_SP/input/uinput”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubeh}”(h]”h ]”h"]”h$]”h&]”Œcurrent_language”ŒEnglish”uh1h hhŒ _document”hŒsource”NŒline”NubhŒsection”“”)”}”(hhh]”(hŒtitle”“”)”}”(hŒ uinput module”h]”hŒ uinput module”…””}”(hh¨hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hh£hžhhŸŒ:/var/lib/git/docbuild/linux/Documentation/input/uinput.rst”h Kubh¢)”}”(hhh]”(h§)”}”(hŒ Introduction”h]”hŒ Introduction”…””}”(hhºhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hh·hžhhŸh¶h KubhŒ paragraph”“”)”}”(hXduinput is a kernel module that makes it possible to emulate input devices from userspace. By writing to /dev/uinput (or /dev/input/uinput) device, a process can create a virtual input device with specific capabilities. Once this virtual device is created, the process can send events through it, that will be delivered to userspace and in-kernel consumers.”h]”hXduinput is a kernel module that makes it possible to emulate input devices from userspace. By writing to /dev/uinput (or /dev/input/uinput) device, a process can create a virtual input device with specific capabilities. Once this virtual device is created, the process can send events through it, that will be delivered to userspace and in-kernel consumers.”…””}”(hhÊhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÈhŸh¶h Khh·hžhubeh}”(h]”Œ introduction”ah ]”h"]”Œ introduction”ah$]”h&]”uh1h¡hh£hžhhŸh¶h Kubh¢)”}”(hhh]”(h§)”}”(hŒ Interface”h]”hŒ Interface”…””}”(hhãhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hhàhžhhŸh¶h KubhŒ literal_block”“”)”}”(hŒlinux/uinput.h”h]”hŒlinux/uinput.h”…””}”hhósbah}”(h]”h ]”h"]”h$]”h&]”Œ xml:space”Œpreserve”uh1hñhŸh¶h KhhàhžhubhÉ)”}”(hŒPThe uinput header defines ioctls to create, set up, and destroy virtual devices.”h]”hŒPThe uinput header defines ioctls to create, set up, and destroy virtual devices.”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÈhŸh¶h Khhàhžhubeh}”(h]”Œ interface”ah ]”h"]”Œ interface”ah$]”h&]”uh1h¡hh£hžhhŸh¶h Kubh¢)”}”(hhh]”(h§)”}”(hŒlibevdev”h]”hŒlibevdev”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hjhžhhŸh¶h KubhÉ)”}”(hŒÚlibevdev is a wrapper library for evdev devices that provides interfaces to create uinput devices and send events. libevdev is less error-prone than accessing uinput directly, and should be considered for new software.”h]”hŒÚlibevdev is a wrapper library for evdev devices that provides interfaces to create uinput devices and send events. libevdev is less error-prone than accessing uinput directly, and should be considered for new software.”…””}”(hj*hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÈhŸh¶h KhjhžhubhÉ)”}”(hŒkFor examples and more information about libevdev: https://www.freedesktop.org/software/libevdev/doc/latest/”h]”(hŒ2For examples and more information about libevdev: ”…””}”(hj8hžhhŸNh NubhŒ reference”“”)”}”(hŒ9https://www.freedesktop.org/software/libevdev/doc/latest/”h]”hŒ9https://www.freedesktop.org/software/libevdev/doc/latest/”…””}”(hjBhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”jDuh1j@hj8ubeh}”(h]”h ]”h"]”h$]”h&]”uh1hÈhŸh¶h Khjhžhubeh}”(h]”Œlibevdev”ah ]”h"]”Œlibevdev”ah$]”h&]”uh1h¡hh£hžhhŸh¶h Kubh¢)”}”(hhh]”(h§)”}”(hŒExamples”h]”hŒExamples”…””}”(hjbhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hj_hžhhŸh¶h K#ubh¢)”}”(hhh]”(h§)”}”(hŒKeyboard events”h]”hŒKeyboard events”…””}”(hjshžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hjphžhhŸh¶h K&ubhÉ)”}”(hŒ©This first example shows how to create a new virtual device, and how to send a key event. All default imports and error handlers were removed for the sake of simplicity.”h]”hŒ©This first example shows how to create a new virtual device, and how to send a key event. All default imports and error handlers were removed for the sake of simplicity.”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÈhŸh¶h K(hjphžhubhò)”}”(hXŠ#include void emit(int fd, int type, int code, int val) { struct input_event ie; ie.type = type; ie.code = code; ie.value = val; /* timestamp values below are ignored */ ie.time.tv_sec = 0; ie.time.tv_usec = 0; write(fd, &ie, sizeof(ie)); } int main(void) { struct uinput_setup usetup; int fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK); /* * The ioctls below will enable the device that is about to be * created, to pass key events, in this case the space key. */ ioctl(fd, UI_SET_EVBIT, EV_KEY); ioctl(fd, UI_SET_KEYBIT, KEY_SPACE); memset(&usetup, 0, sizeof(usetup)); usetup.id.bustype = BUS_USB; usetup.id.vendor = 0x1234; /* sample vendor */ usetup.id.product = 0x5678; /* sample product */ strcpy(usetup.name, "Example device"); ioctl(fd, UI_DEV_SETUP, &usetup); ioctl(fd, UI_DEV_CREATE); /* * On UI_DEV_CREATE the kernel will create the device node for this * device. We are inserting a pause here so that userspace has time * to detect, initialize the new device, and can start listening to * the event, otherwise it will not notice the event we are about * to send. This pause is only needed in our example code! */ sleep(1); /* Key press, report the event, send key release, and report again */ emit(fd, EV_KEY, KEY_SPACE, 1); emit(fd, EV_SYN, SYN_REPORT, 0); emit(fd, EV_KEY, KEY_SPACE, 0); emit(fd, EV_SYN, SYN_REPORT, 0); /* * Give userspace some time to read the events before we destroy the * device with UI_DEV_DESTROY. */ sleep(1); ioctl(fd, UI_DEV_DESTROY); close(fd); return 0; }”h]”hXŠ#include void emit(int fd, int type, int code, int val) { struct input_event ie; ie.type = type; ie.code = code; ie.value = val; /* timestamp values below are ignored */ ie.time.tv_sec = 0; ie.time.tv_usec = 0; write(fd, &ie, sizeof(ie)); } int main(void) { struct uinput_setup usetup; int fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK); /* * The ioctls below will enable the device that is about to be * created, to pass key events, in this case the space key. */ ioctl(fd, UI_SET_EVBIT, EV_KEY); ioctl(fd, UI_SET_KEYBIT, KEY_SPACE); memset(&usetup, 0, sizeof(usetup)); usetup.id.bustype = BUS_USB; usetup.id.vendor = 0x1234; /* sample vendor */ usetup.id.product = 0x5678; /* sample product */ strcpy(usetup.name, "Example device"); ioctl(fd, UI_DEV_SETUP, &usetup); ioctl(fd, UI_DEV_CREATE); /* * On UI_DEV_CREATE the kernel will create the device node for this * device. We are inserting a pause here so that userspace has time * to detect, initialize the new device, and can start listening to * the event, otherwise it will not notice the event we are about * to send. This pause is only needed in our example code! */ sleep(1); /* Key press, report the event, send key release, and report again */ emit(fd, EV_KEY, KEY_SPACE, 1); emit(fd, EV_SYN, SYN_REPORT, 0); emit(fd, EV_KEY, KEY_SPACE, 0); emit(fd, EV_SYN, SYN_REPORT, 0); /* * Give userspace some time to read the events before we destroy the * device with UI_DEV_DESTROY. */ sleep(1); ioctl(fd, UI_DEV_DESTROY); close(fd); return 0; }”…””}”hjsbah}”(h]”h ]”h"]”h$]”h&]”jjŒforce”‰Œlanguage”Œc”Œhighlight_args”}”uh1hñhŸh¶h K,hjphžhubeh}”(h]”Œkeyboard-events”ah ]”h"]”Œkeyboard events”ah$]”h&]”uh1h¡hj_hžhhŸh¶h K&ubh¢)”}”(hhh]”(h§)”}”(hŒMouse movements”h]”hŒMouse movements”…””}”(hj­hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hjªhžhhŸh¶h KqubhÉ)”}”(hŒUThis example shows how to create a virtual device that behaves like a physical mouse.”h]”hŒUThis example shows how to create a virtual device that behaves like a physical mouse.”…””}”(hj»hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÈhŸh¶h Kshjªhžhubhò)”}”(hX×#include /* emit function is identical to of the first example */ int main(void) { struct uinput_setup usetup; int i = 50; int fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK); /* enable mouse button left and relative events */ ioctl(fd, UI_SET_EVBIT, EV_KEY); ioctl(fd, UI_SET_KEYBIT, BTN_LEFT); ioctl(fd, UI_SET_EVBIT, EV_REL); ioctl(fd, UI_SET_RELBIT, REL_X); ioctl(fd, UI_SET_RELBIT, REL_Y); memset(&usetup, 0, sizeof(usetup)); usetup.id.bustype = BUS_USB; usetup.id.vendor = 0x1234; /* sample vendor */ usetup.id.product = 0x5678; /* sample product */ strcpy(usetup.name, "Example device"); ioctl(fd, UI_DEV_SETUP, &usetup); ioctl(fd, UI_DEV_CREATE); /* * On UI_DEV_CREATE the kernel will create the device node for this * device. We are inserting a pause here so that userspace has time * to detect, initialize the new device, and can start listening to * the event, otherwise it will not notice the event we are about * to send. This pause is only needed in our example code! */ sleep(1); /* Move the mouse diagonally, 5 units per axis */ while (i--) { emit(fd, EV_REL, REL_X, 5); emit(fd, EV_REL, REL_Y, 5); emit(fd, EV_SYN, SYN_REPORT, 0); usleep(15000); } /* * Give userspace some time to read the events before we destroy the * device with UI_DEV_DESTROY. */ sleep(1); ioctl(fd, UI_DEV_DESTROY); close(fd); return 0; }”h]”hX×#include /* emit function is identical to of the first example */ int main(void) { struct uinput_setup usetup; int i = 50; int fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK); /* enable mouse button left and relative events */ ioctl(fd, UI_SET_EVBIT, EV_KEY); ioctl(fd, UI_SET_KEYBIT, BTN_LEFT); ioctl(fd, UI_SET_EVBIT, EV_REL); ioctl(fd, UI_SET_RELBIT, REL_X); ioctl(fd, UI_SET_RELBIT, REL_Y); memset(&usetup, 0, sizeof(usetup)); usetup.id.bustype = BUS_USB; usetup.id.vendor = 0x1234; /* sample vendor */ usetup.id.product = 0x5678; /* sample product */ strcpy(usetup.name, "Example device"); ioctl(fd, UI_DEV_SETUP, &usetup); ioctl(fd, UI_DEV_CREATE); /* * On UI_DEV_CREATE the kernel will create the device node for this * device. We are inserting a pause here so that userspace has time * to detect, initialize the new device, and can start listening to * the event, otherwise it will not notice the event we are about * to send. This pause is only needed in our example code! */ sleep(1); /* Move the mouse diagonally, 5 units per axis */ while (i--) { emit(fd, EV_REL, REL_X, 5); emit(fd, EV_REL, REL_Y, 5); emit(fd, EV_SYN, SYN_REPORT, 0); usleep(15000); } /* * Give userspace some time to read the events before we destroy the * device with UI_DEV_DESTROY. */ sleep(1); ioctl(fd, UI_DEV_DESTROY); close(fd); return 0; }”…””}”hjÉsbah}”(h]”h ]”h"]”h$]”h&]”jjj‰jžjŸj }”uh1hñhŸh¶h Kvhjªhžhubeh}”(h]”Œmouse-movements”ah ]”h"]”Œmouse movements”ah$]”h&]”uh1h¡hj_hžhhŸh¶h Kqubh¢)”}”(hhh]”(h§)”}”(hŒuinput old interface”h]”hŒuinput old interface”…””}”(hjãhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hjàhžhhŸh¶h K³ubhÉ)”}”(hXgBefore uinput version 5, there wasn't a dedicated ioctl to set up a virtual device. Programs supporting older versions of uinput interface need to fill a uinput_user_dev structure and write it to the uinput file descriptor to configure the new uinput device. New code should not use the old interface but interact with uinput via ioctl calls, or use libevdev.”h]”hXiBefore uinput version 5, there wasn’t a dedicated ioctl to set up a virtual device. Programs supporting older versions of uinput interface need to fill a uinput_user_dev structure and write it to the uinput file descriptor to configure the new uinput device. New code should not use the old interface but interact with uinput via ioctl calls, or use libevdev.”…””}”(hjñhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÈhŸh¶h Kµhjàhžhubhò)”}”(hXá#include /* emit function is identical to of the first example */ int main(void) { struct uinput_user_dev uud; int version, rc, fd; fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK); rc = ioctl(fd, UI_GET_VERSION, &version); if (rc == 0 && version >= 5) { /* use UI_DEV_SETUP */ return 0; } /* * The ioctls below will enable the device that is about to be * created, to pass key events, in this case the space key. */ ioctl(fd, UI_SET_EVBIT, EV_KEY); ioctl(fd, UI_SET_KEYBIT, KEY_SPACE); memset(&uud, 0, sizeof(uud)); snprintf(uud.name, UINPUT_MAX_NAME_SIZE, "uinput old interface"); write(fd, &uud, sizeof(uud)); ioctl(fd, UI_DEV_CREATE); /* * On UI_DEV_CREATE the kernel will create the device node for this * device. We are inserting a pause here so that userspace has time * to detect, initialize the new device, and can start listening to * the event, otherwise it will not notice the event we are about * to send. This pause is only needed in our example code! */ sleep(1); /* Key press, report the event, send key release, and report again */ emit(fd, EV_KEY, KEY_SPACE, 1); emit(fd, EV_SYN, SYN_REPORT, 0); emit(fd, EV_KEY, KEY_SPACE, 0); emit(fd, EV_SYN, SYN_REPORT, 0); /* * Give userspace some time to read the events before we destroy the * device with UI_DEV_DESTROY. */ sleep(1); ioctl(fd, UI_DEV_DESTROY); close(fd); return 0; }”h]”hXá#include /* emit function is identical to of the first example */ int main(void) { struct uinput_user_dev uud; int version, rc, fd; fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK); rc = ioctl(fd, UI_GET_VERSION, &version); if (rc == 0 && version >= 5) { /* use UI_DEV_SETUP */ return 0; } /* * The ioctls below will enable the device that is about to be * created, to pass key events, in this case the space key. */ ioctl(fd, UI_SET_EVBIT, EV_KEY); ioctl(fd, UI_SET_KEYBIT, KEY_SPACE); memset(&uud, 0, sizeof(uud)); snprintf(uud.name, UINPUT_MAX_NAME_SIZE, "uinput old interface"); write(fd, &uud, sizeof(uud)); ioctl(fd, UI_DEV_CREATE); /* * On UI_DEV_CREATE the kernel will create the device node for this * device. We are inserting a pause here so that userspace has time * to detect, initialize the new device, and can start listening to * the event, otherwise it will not notice the event we are about * to send. This pause is only needed in our example code! */ sleep(1); /* Key press, report the event, send key release, and report again */ emit(fd, EV_KEY, KEY_SPACE, 1); emit(fd, EV_SYN, SYN_REPORT, 0); emit(fd, EV_KEY, KEY_SPACE, 0); emit(fd, EV_SYN, SYN_REPORT, 0); /* * Give userspace some time to read the events before we destroy the * device with UI_DEV_DESTROY. */ sleep(1); ioctl(fd, UI_DEV_DESTROY); close(fd); return 0; }”…””}”hjÿsbah}”(h]”h ]”h"]”h$]”h&]”jjj‰jžjŸj }”uh1hñhŸh¶h K»hjàhžhubeh}”(h]”Œuinput-old-interface”ah ]”h"]”Œuinput old interface”ah$]”h&]”uh1h¡hj_hžhhŸh¶h K³ubeh}”(h]”Œexamples”ah ]”h"]”Œexamples”ah$]”h&]”uh1h¡hh£hžhhŸh¶h K#ubeh}”(h]”Œ uinput-module”ah ]”h"]”Œ uinput module”ah$]”h&]”uh1h¡hhhžhhŸh¶h Kubeh}”(h]”h ]”h"]”h$]”h&]”Œsource”h¶uh1hŒcurrent_source”NŒ current_line”NŒsettings”Œdocutils.frontend”ŒValues”“”)”}”(h¦NŒ generator”NŒ datestamp”NŒ source_link”NŒ source_url”NŒ toc_backlinks”Œentry”Œfootnote_backlinks”KŒ sectnum_xform”KŒstrip_comments”NŒstrip_elements_with_classes”NŒ strip_classes”NŒ report_level”KŒ halt_level”KŒexit_status_level”KŒdebug”NŒwarning_stream”NŒ traceback”ˆŒinput_encoding”Œ utf-8-sig”Œinput_encoding_error_handler”Œstrict”Œoutput_encoding”Œutf-8”Œoutput_encoding_error_handler”jIŒerror_encoding”Œutf-8”Œerror_encoding_error_handler”Œbackslashreplace”Œ language_code”Œen”Œrecord_dependencies”NŒconfig”NŒ id_prefix”hŒauto_id_prefix”Œid”Œ dump_settings”NŒdump_internals”NŒdump_transforms”NŒdump_pseudo_xml”NŒexpose_internals”NŒstrict_visitor”NŒ_disable_config”NŒ_source”h¶Œ _destination”NŒ _config_files”]”Œ7/var/lib/git/docbuild/linux/Documentation/docutils.conf”aŒfile_insertion_enabled”ˆŒ raw_enabled”KŒline_length_limit”M'Œpep_references”NŒ pep_base_url”Œhttps://peps.python.org/”Œpep_file_url_template”Œpep-%04d”Œrfc_references”NŒ rfc_base_url”Œ&https://datatracker.ietf.org/doc/html/”Œ tab_width”KŒtrim_footnote_reference_space”‰Œsyntax_highlight”Œlong”Œ smart_quotes”ˆŒsmartquotes_locales”]”Œcharacter_level_inline_markup”‰Œdoctitle_xform”‰Œ docinfo_xform”KŒsectsubtitle_xform”‰Œ image_loading”Œlink”Œembed_stylesheet”‰Œcloak_email_addresses”ˆŒsection_self_link”‰Œenv”NubŒreporter”NŒindirect_targets”]”Œsubstitution_defs”}”Œsubstitution_names”}”Œrefnames”}”Œrefids”}”Œnameids”}”(j#j hÝhÚjjj\jYjjj§j¤jÝjÚjjuŒ nametypes”}”(j#‰h݉j‰j\‰j‰j§‰j݉j‰uh}”(j h£hÚh·jhàjYjjj_j¤jpjÚjªjjàuŒ footnote_refs”}”Œ citation_refs”}”Œ autofootnotes”]”Œautofootnote_refs”]”Œsymbol_footnotes”]”Œsymbol_footnote_refs”]”Œ footnotes”]”Œ citations”]”Œautofootnote_start”KŒsymbol_footnote_start”KŒ id_counter”Œ collections”ŒCounter”“”}”…”R”Œparse_messages”]”Œtransform_messages”]”Œ transformer”NŒ include_log”]”Œ decoration”Nhžhub.