├── .gitignore ├── AUTHORS ├── COPYING ├── LICENSE ├── MANIFEST.in ├── NEWS.md ├── README ├── README.rst ├── examples ├── drop_privileges.py ├── joystick.py ├── keyboard.py └── mouse.py ├── libsuinput ├── AUTHORS ├── COPYING ├── INSTALL ├── Makefile.am ├── NEWS ├── README ├── autogen.sh ├── configure.ac ├── examples │ ├── Makefile │ ├── keyboard.c │ └── mouse.c └── src │ ├── Makefile.am │ ├── libsuinput.pc.in │ ├── libudev.h │ ├── suinput.c │ └── suinput.h ├── pyproject.toml ├── scripts └── parse-event-codes ├── setup.py ├── src ├── __init__.py └── ev.py ├── tests └── test_uinput.py └── udev-rules └── 40-uinput.rules /.gitignore: -------------------------------------------------------------------------------- 1 | **/*.pyc 2 | **/*.swp 3 | **/*.egg-info/ 4 | build/ 5 | dist/ 6 | _libsuinput.so 7 | 8 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Eric Mikula 2 | Esa-Matti Suuronen 3 | Fabian Deutsch 4 | Kevin Ward 5 | Pascal Garber 6 | Tuomas Räsänen 7 | Vincent Bernat 8 | pablo a maurin 9 | timlyo 10 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | 2 | GNU GENERAL PUBLIC LICENSE 3 | Version 3, 29 June 2007 4 | 5 | Copyright (C) 2007 Free Software Foundation, Inc. 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The GNU General Public License is a free, copyleft license for 12 | software and other kinds of works. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | the GNU General Public License is intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. We, the Free Software Foundation, use the 19 | GNU General Public License for most of our software; it applies also to 20 | any other work released this way by its authors. You can apply it to 21 | your programs, too. 22 | 23 | When we speak of free software, we are referring to freedom, not 24 | price. Our General Public Licenses are designed to make sure that you 25 | have the freedom to distribute copies of free software (and charge for 26 | them if you wish), that you receive source code or can get it if you 27 | want it, that you can change the software or use pieces of it in new 28 | free programs, and that you know you can do these things. 29 | 30 | To protect your rights, we need to prevent others from denying you 31 | these rights or asking you to surrender the rights. Therefore, you have 32 | certain responsibilities if you distribute copies of the software, or if 33 | you modify it: responsibilities to respect the freedom of others. 34 | 35 | For example, if you distribute copies of such a program, whether 36 | gratis or for a fee, you must pass on to the recipients the same 37 | freedoms that you received. You must make sure that they, too, receive 38 | or can get the source code. And you must show them these terms so they 39 | know their rights. 40 | 41 | Developers that use the GNU GPL protect your rights with two steps: 42 | (1) assert copyright on the software, and (2) offer you this License 43 | giving you legal permission to copy, distribute and/or modify it. 44 | 45 | For the developers' and authors' protection, the GPL clearly explains 46 | that there is no warranty for this free software. For both users' and 47 | authors' sake, the GPL requires that modified versions be marked as 48 | changed, so that their problems will not be attributed erroneously to 49 | authors of previous versions. 50 | 51 | Some devices are designed to deny users access to install or run 52 | modified versions of the software inside them, although the manufacturer 53 | can do so. This is fundamentally incompatible with the aim of 54 | protecting users' freedom to change the software. The systematic 55 | pattern of such abuse occurs in the area of products for individuals to 56 | use, which is precisely where it is most unacceptable. Therefore, we 57 | have designed this version of the GPL to prohibit the practice for those 58 | products. If such problems arise substantially in other domains, we 59 | stand ready to extend this provision to those domains in future versions 60 | of the GPL, as needed to protect the freedom of users. 61 | 62 | Finally, every program is threatened constantly by software patents. 63 | States should not allow patents to restrict development and use of 64 | software on general-purpose computers, but in those that do, we wish to 65 | avoid the special danger that patents applied to a free program could 66 | make it effectively proprietary. To prevent this, the GPL assures that 67 | patents cannot be used to render the program non-free. 68 | 69 | The precise terms and conditions for copying, distribution and 70 | modification follow. 71 | 72 | TERMS AND CONDITIONS 73 | 74 | 0. Definitions. 75 | 76 | "This License" refers to version 3 of the GNU General Public License. 77 | 78 | "Copyright" also means copyright-like laws that apply to other kinds of 79 | works, such as semiconductor masks. 80 | 81 | "The Program" refers to any copyrightable work licensed under this 82 | License. Each licensee is addressed as "you". "Licensees" and 83 | "recipients" may be individuals or organizations. 84 | 85 | To "modify" a work means to copy from or adapt all or part of the work 86 | in a fashion requiring copyright permission, other than the making of an 87 | exact copy. The resulting work is called a "modified version" of the 88 | earlier work or a work "based on" the earlier work. 89 | 90 | A "covered work" means either the unmodified Program or a work based 91 | on the Program. 92 | 93 | To "propagate" a work means to do anything with it that, without 94 | permission, would make you directly or secondarily liable for 95 | infringement under applicable copyright law, except executing it on a 96 | computer or modifying a private copy. Propagation includes copying, 97 | distribution (with or without modification), making available to the 98 | public, and in some countries other activities as well. 99 | 100 | To "convey" a work means any kind of propagation that enables other 101 | parties to make or receive copies. Mere interaction with a user through 102 | a computer network, with no transfer of a copy, is not conveying. 103 | 104 | An interactive user interface displays "Appropriate Legal Notices" 105 | to the extent that it includes a convenient and prominently visible 106 | feature that (1) displays an appropriate copyright notice, and (2) 107 | tells the user that there is no warranty for the work (except to the 108 | extent that warranties are provided), that licensees may convey the 109 | work under this License, and how to view a copy of this License. If 110 | the interface presents a list of user commands or options, such as a 111 | menu, a prominent item in the list meets this criterion. 112 | 113 | 1. Source Code. 114 | 115 | The "source code" for a work means the preferred form of the work 116 | for making modifications to it. "Object code" means any non-source 117 | form of a work. 118 | 119 | A "Standard Interface" means an interface that either is an official 120 | standard defined by a recognized standards body, or, in the case of 121 | interfaces specified for a particular programming language, one that 122 | is widely used among developers working in that language. 123 | 124 | The "System Libraries" of an executable work include anything, other 125 | than the work as a whole, that (a) is included in the normal form of 126 | packaging a Major Component, but which is not part of that Major 127 | Component, and (b) serves only to enable use of the work with that 128 | Major Component, or to implement a Standard Interface for which an 129 | implementation is available to the public in source code form. A 130 | "Major Component", in this context, means a major essential component 131 | (kernel, window system, and so on) of the specific operating system 132 | (if any) on which the executable work runs, or a compiler used to 133 | produce the work, or an object code interpreter used to run it. 134 | 135 | The "Corresponding Source" for a work in object code form means all 136 | the source code needed to generate, install, and (for an executable 137 | work) run the object code and to modify the work, including scripts to 138 | control those activities. However, it does not include the work's 139 | System Libraries, or general-purpose tools or generally available free 140 | programs which are used unmodified in performing those activities but 141 | which are not part of the work. For example, Corresponding Source 142 | includes interface definition files associated with source files for 143 | the work, and the source code for shared libraries and dynamically 144 | linked subprograms that the work is specifically designed to require, 145 | such as by intimate data communication or control flow between those 146 | subprograms and other parts of the work. 147 | 148 | The Corresponding Source need not include anything that users 149 | can regenerate automatically from other parts of the Corresponding 150 | Source. 151 | 152 | The Corresponding Source for a work in source code form is that 153 | same work. 154 | 155 | 2. Basic Permissions. 156 | 157 | All rights granted under this License are granted for the term of 158 | copyright on the Program, and are irrevocable provided the stated 159 | conditions are met. This License explicitly affirms your unlimited 160 | permission to run the unmodified Program. The output from running a 161 | covered work is covered by this License only if the output, given its 162 | content, constitutes a covered work. This License acknowledges your 163 | rights of fair use or other equivalent, as provided by copyright law. 164 | 165 | You may make, run and propagate covered works that you do not 166 | convey, without conditions so long as your license otherwise remains 167 | in force. You may convey covered works to others for the sole purpose 168 | of having them make modifications exclusively for you, or provide you 169 | with facilities for running those works, provided that you comply with 170 | the terms of this License in conveying all material for which you do 171 | not control copyright. Those thus making or running the covered works 172 | for you must do so exclusively on your behalf, under your direction 173 | and control, on terms that prohibit them from making any copies of 174 | your copyrighted material outside their relationship with you. 175 | 176 | Conveying under any other circumstances is permitted solely under 177 | the conditions stated below. Sublicensing is not allowed; section 10 178 | makes it unnecessary. 179 | 180 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 181 | 182 | No covered work shall be deemed part of an effective technological 183 | measure under any applicable law fulfilling obligations under article 184 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 185 | similar laws prohibiting or restricting circumvention of such 186 | measures. 187 | 188 | When you convey a covered work, you waive any legal power to forbid 189 | circumvention of technological measures to the extent such circumvention 190 | is effected by exercising rights under this License with respect to 191 | the covered work, and you disclaim any intention to limit operation or 192 | modification of the work as a means of enforcing, against the work's 193 | users, your or third parties' legal rights to forbid circumvention of 194 | technological measures. 195 | 196 | 4. Conveying Verbatim Copies. 197 | 198 | You may convey verbatim copies of the Program's source code as you 199 | receive it, in any medium, provided that you conspicuously and 200 | appropriately publish on each copy an appropriate copyright notice; 201 | keep intact all notices stating that this License and any 202 | non-permissive terms added in accord with section 7 apply to the code; 203 | keep intact all notices of the absence of any warranty; and give all 204 | recipients a copy of this License along with the Program. 205 | 206 | You may charge any price or no price for each copy that you convey, 207 | and you may offer support or warranty protection for a fee. 208 | 209 | 5. Conveying Modified Source Versions. 210 | 211 | You may convey a work based on the Program, or the modifications to 212 | produce it from the Program, in the form of source code under the 213 | terms of section 4, provided that you also meet all of these conditions: 214 | 215 | a) The work must carry prominent notices stating that you modified 216 | it, and giving a relevant date. 217 | 218 | b) The work must carry prominent notices stating that it is 219 | released under this License and any conditions added under section 220 | 7. This requirement modifies the requirement in section 4 to 221 | "keep intact all notices". 222 | 223 | c) You must license the entire work, as a whole, under this 224 | License to anyone who comes into possession of a copy. This 225 | License will therefore apply, along with any applicable section 7 226 | additional terms, to the whole of the work, and all its parts, 227 | regardless of how they are packaged. This License gives no 228 | permission to license the work in any other way, but it does not 229 | invalidate such permission if you have separately received it. 230 | 231 | d) If the work has interactive user interfaces, each must display 232 | Appropriate Legal Notices; however, if the Program has interactive 233 | interfaces that do not display Appropriate Legal Notices, your 234 | work need not make them do so. 235 | 236 | A compilation of a covered work with other separate and independent 237 | works, which are not by their nature extensions of the covered work, 238 | and which are not combined with it such as to form a larger program, 239 | in or on a volume of a storage or distribution medium, is called an 240 | "aggregate" if the compilation and its resulting copyright are not 241 | used to limit the access or legal rights of the compilation's users 242 | beyond what the individual works permit. Inclusion of a covered work 243 | in an aggregate does not cause this License to apply to the other 244 | parts of the aggregate. 245 | 246 | 6. Conveying Non-Source Forms. 247 | 248 | You may convey a covered work in object code form under the terms 249 | of sections 4 and 5, provided that you also convey the 250 | machine-readable Corresponding Source under the terms of this License, 251 | in one of these ways: 252 | 253 | a) Convey the object code in, or embodied in, a physical product 254 | (including a physical distribution medium), accompanied by the 255 | Corresponding Source fixed on a durable physical medium 256 | customarily used for software interchange. 257 | 258 | b) Convey the object code in, or embodied in, a physical product 259 | (including a physical distribution medium), accompanied by a 260 | written offer, valid for at least three years and valid for as 261 | long as you offer spare parts or customer support for that product 262 | model, to give anyone who possesses the object code either (1) a 263 | copy of the Corresponding Source for all the software in the 264 | product that is covered by this License, on a durable physical 265 | medium customarily used for software interchange, for a price no 266 | more than your reasonable cost of physically performing this 267 | conveying of source, or (2) access to copy the 268 | Corresponding Source from a network server at no charge. 269 | 270 | c) Convey individual copies of the object code with a copy of the 271 | written offer to provide the Corresponding Source. This 272 | alternative is allowed only occasionally and noncommercially, and 273 | only if you received the object code with such an offer, in accord 274 | with subsection 6b. 275 | 276 | d) Convey the object code by offering access from a designated 277 | place (gratis or for a charge), and offer equivalent access to the 278 | Corresponding Source in the same way through the same place at no 279 | further charge. You need not require recipients to copy the 280 | Corresponding Source along with the object code. If the place to 281 | copy the object code is a network server, the Corresponding Source 282 | may be on a different server (operated by you or a third party) 283 | that supports equivalent copying facilities, provided you maintain 284 | clear directions next to the object code saying where to find the 285 | Corresponding Source. Regardless of what server hosts the 286 | Corresponding Source, you remain obligated to ensure that it is 287 | available for as long as needed to satisfy these requirements. 288 | 289 | e) Convey the object code using peer-to-peer transmission, provided 290 | you inform other peers where the object code and Corresponding 291 | Source of the work are being offered to the general public at no 292 | charge under subsection 6d. 293 | 294 | A separable portion of the object code, whose source code is excluded 295 | from the Corresponding Source as a System Library, need not be 296 | included in conveying the object code work. 297 | 298 | A "User Product" is either (1) a "consumer product", which means any 299 | tangible personal property which is normally used for personal, family, 300 | or household purposes, or (2) anything designed or sold for incorporation 301 | into a dwelling. In determining whether a product is a consumer product, 302 | doubtful cases shall be resolved in favor of coverage. For a particular 303 | product received by a particular user, "normally used" refers to a 304 | typical or common use of that class of product, regardless of the status 305 | of the particular user or of the way in which the particular user 306 | actually uses, or expects or is expected to use, the product. A product 307 | is a consumer product regardless of whether the product has substantial 308 | commercial, industrial or non-consumer uses, unless such uses represent 309 | the only significant mode of use of the product. 310 | 311 | "Installation Information" for a User Product means any methods, 312 | procedures, authorization keys, or other information required to install 313 | and execute modified versions of a covered work in that User Product from 314 | a modified version of its Corresponding Source. The information must 315 | suffice to ensure that the continued functioning of the modified object 316 | code is in no case prevented or interfered with solely because 317 | modification has been made. 318 | 319 | If you convey an object code work under this section in, or with, or 320 | specifically for use in, a User Product, and the conveying occurs as 321 | part of a transaction in which the right of possession and use of the 322 | User Product is transferred to the recipient in perpetuity or for a 323 | fixed term (regardless of how the transaction is characterized), the 324 | Corresponding Source conveyed under this section must be accompanied 325 | by the Installation Information. But this requirement does not apply 326 | if neither you nor any third party retains the ability to install 327 | modified object code on the User Product (for example, the work has 328 | been installed in ROM). 329 | 330 | The requirement to provide Installation Information does not include a 331 | requirement to continue to provide support service, warranty, or updates 332 | for a work that has been modified or installed by the recipient, or for 333 | the User Product in which it has been modified or installed. Access to a 334 | network may be denied when the modification itself materially and 335 | adversely affects the operation of the network or violates the rules and 336 | protocols for communication across the network. 337 | 338 | Corresponding Source conveyed, and Installation Information provided, 339 | in accord with this section must be in a format that is publicly 340 | documented (and with an implementation available to the public in 341 | source code form), and must require no special password or key for 342 | unpacking, reading or copying. 343 | 344 | 7. Additional Terms. 345 | 346 | "Additional permissions" are terms that supplement the terms of this 347 | License by making exceptions from one or more of its conditions. 348 | Additional permissions that are applicable to the entire Program shall 349 | be treated as though they were included in this License, to the extent 350 | that they are valid under applicable law. If additional permissions 351 | apply only to part of the Program, that part may be used separately 352 | under those permissions, but the entire Program remains governed by 353 | this License without regard to the additional permissions. 354 | 355 | When you convey a copy of a covered work, you may at your option 356 | remove any additional permissions from that copy, or from any part of 357 | it. (Additional permissions may be written to require their own 358 | removal in certain cases when you modify the work.) You may place 359 | additional permissions on material, added by you to a covered work, 360 | for which you have or can give appropriate copyright permission. 361 | 362 | Notwithstanding any other provision of this License, for material you 363 | add to a covered work, you may (if authorized by the copyright holders of 364 | that material) supplement the terms of this License with terms: 365 | 366 | a) Disclaiming warranty or limiting liability differently from the 367 | terms of sections 15 and 16 of this License; or 368 | 369 | b) Requiring preservation of specified reasonable legal notices or 370 | author attributions in that material or in the Appropriate Legal 371 | Notices displayed by works containing it; or 372 | 373 | c) Prohibiting misrepresentation of the origin of that material, or 374 | requiring that modified versions of such material be marked in 375 | reasonable ways as different from the original version; or 376 | 377 | d) Limiting the use for publicity purposes of names of licensors or 378 | authors of the material; or 379 | 380 | e) Declining to grant rights under trademark law for use of some 381 | trade names, trademarks, or service marks; or 382 | 383 | f) Requiring indemnification of licensors and authors of that 384 | material by anyone who conveys the material (or modified versions of 385 | it) with contractual assumptions of liability to the recipient, for 386 | any liability that these contractual assumptions directly impose on 387 | those licensors and authors. 388 | 389 | All other non-permissive additional terms are considered "further 390 | restrictions" within the meaning of section 10. If the Program as you 391 | received it, or any part of it, contains a notice stating that it is 392 | governed by this License along with a term that is a further 393 | restriction, you may remove that term. If a license document contains 394 | a further restriction but permits relicensing or conveying under this 395 | License, you may add to a covered work material governed by the terms 396 | of that license document, provided that the further restriction does 397 | not survive such relicensing or conveying. 398 | 399 | If you add terms to a covered work in accord with this section, you 400 | must place, in the relevant source files, a statement of the 401 | additional terms that apply to those files, or a notice indicating 402 | where to find the applicable terms. 403 | 404 | Additional terms, permissive or non-permissive, may be stated in the 405 | form of a separately written license, or stated as exceptions; 406 | the above requirements apply either way. 407 | 408 | 8. Termination. 409 | 410 | You may not propagate or modify a covered work except as expressly 411 | provided under this License. Any attempt otherwise to propagate or 412 | modify it is void, and will automatically terminate your rights under 413 | this License (including any patent licenses granted under the third 414 | paragraph of section 11). 415 | 416 | However, if you cease all violation of this License, then your 417 | license from a particular copyright holder is reinstated (a) 418 | provisionally, unless and until the copyright holder explicitly and 419 | finally terminates your license, and (b) permanently, if the copyright 420 | holder fails to notify you of the violation by some reasonable means 421 | prior to 60 days after the cessation. 422 | 423 | Moreover, your license from a particular copyright holder is 424 | reinstated permanently if the copyright holder notifies you of the 425 | violation by some reasonable means, this is the first time you have 426 | received notice of violation of this License (for any work) from that 427 | copyright holder, and you cure the violation prior to 30 days after 428 | your receipt of the notice. 429 | 430 | Termination of your rights under this section does not terminate the 431 | licenses of parties who have received copies or rights from you under 432 | this License. If your rights have been terminated and not permanently 433 | reinstated, you do not qualify to receive new licenses for the same 434 | material under section 10. 435 | 436 | 9. Acceptance Not Required for Having Copies. 437 | 438 | You are not required to accept this License in order to receive or 439 | run a copy of the Program. Ancillary propagation of a covered work 440 | occurring solely as a consequence of using peer-to-peer transmission 441 | to receive a copy likewise does not require acceptance. However, 442 | nothing other than this License grants you permission to propagate or 443 | modify any covered work. These actions infringe copyright if you do 444 | not accept this License. Therefore, by modifying or propagating a 445 | covered work, you indicate your acceptance of this License to do so. 446 | 447 | 10. Automatic Licensing of Downstream Recipients. 448 | 449 | Each time you convey a covered work, the recipient automatically 450 | receives a license from the original licensors, to run, modify and 451 | propagate that work, subject to this License. You are not responsible 452 | for enforcing compliance by third parties with this License. 453 | 454 | An "entity transaction" is a transaction transferring control of an 455 | organization, or substantially all assets of one, or subdividing an 456 | organization, or merging organizations. If propagation of a covered 457 | work results from an entity transaction, each party to that 458 | transaction who receives a copy of the work also receives whatever 459 | licenses to the work the party's predecessor in interest had or could 460 | give under the previous paragraph, plus a right to possession of the 461 | Corresponding Source of the work from the predecessor in interest, if 462 | the predecessor has it or can get it with reasonable efforts. 463 | 464 | You may not impose any further restrictions on the exercise of the 465 | rights granted or affirmed under this License. For example, you may 466 | not impose a license fee, royalty, or other charge for exercise of 467 | rights granted under this License, and you may not initiate litigation 468 | (including a cross-claim or counterclaim in a lawsuit) alleging that 469 | any patent claim is infringed by making, using, selling, offering for 470 | sale, or importing the Program or any portion of it. 471 | 472 | 11. Patents. 473 | 474 | A "contributor" is a copyright holder who authorizes use under this 475 | License of the Program or a work on which the Program is based. The 476 | work thus licensed is called the contributor's "contributor version". 477 | 478 | A contributor's "essential patent claims" are all patent claims 479 | owned or controlled by the contributor, whether already acquired or 480 | hereafter acquired, that would be infringed by some manner, permitted 481 | by this License, of making, using, or selling its contributor version, 482 | but do not include claims that would be infringed only as a 483 | consequence of further modification of the contributor version. For 484 | purposes of this definition, "control" includes the right to grant 485 | patent sublicenses in a manner consistent with the requirements of 486 | this License. 487 | 488 | Each contributor grants you a non-exclusive, worldwide, royalty-free 489 | patent license under the contributor's essential patent claims, to 490 | make, use, sell, offer for sale, import and otherwise run, modify and 491 | propagate the contents of its contributor version. 492 | 493 | In the following three paragraphs, a "patent license" is any express 494 | agreement or commitment, however denominated, not to enforce a patent 495 | (such as an express permission to practice a patent or covenant not to 496 | sue for patent infringement). To "grant" such a patent license to a 497 | party means to make such an agreement or commitment not to enforce a 498 | patent against the party. 499 | 500 | If you convey a covered work, knowingly relying on a patent license, 501 | and the Corresponding Source of the work is not available for anyone 502 | to copy, free of charge and under the terms of this License, through a 503 | publicly available network server or other readily accessible means, 504 | then you must either (1) cause the Corresponding Source to be so 505 | available, or (2) arrange to deprive yourself of the benefit of the 506 | patent license for this particular work, or (3) arrange, in a manner 507 | consistent with the requirements of this License, to extend the patent 508 | license to downstream recipients. "Knowingly relying" means you have 509 | actual knowledge that, but for the patent license, your conveying the 510 | covered work in a country, or your recipient's use of the covered work 511 | in a country, would infringe one or more identifiable patents in that 512 | country that you have reason to believe are valid. 513 | 514 | If, pursuant to or in connection with a single transaction or 515 | arrangement, you convey, or propagate by procuring conveyance of, a 516 | covered work, and grant a patent license to some of the parties 517 | receiving the covered work authorizing them to use, propagate, modify 518 | or convey a specific copy of the covered work, then the patent license 519 | you grant is automatically extended to all recipients of the covered 520 | work and works based on it. 521 | 522 | A patent license is "discriminatory" if it does not include within 523 | the scope of its coverage, prohibits the exercise of, or is 524 | conditioned on the non-exercise of one or more of the rights that are 525 | specifically granted under this License. You may not convey a covered 526 | work if you are a party to an arrangement with a third party that is 527 | in the business of distributing software, under which you make payment 528 | to the third party based on the extent of your activity of conveying 529 | the work, and under which the third party grants, to any of the 530 | parties who would receive the covered work from you, a discriminatory 531 | patent license (a) in connection with copies of the covered work 532 | conveyed by you (or copies made from those copies), or (b) primarily 533 | for and in connection with specific products or compilations that 534 | contain the covered work, unless you entered into that arrangement, 535 | or that patent license was granted, prior to 28 March 2007. 536 | 537 | Nothing in this License shall be construed as excluding or limiting 538 | any implied license or other defenses to infringement that may 539 | otherwise be available to you under applicable patent law. 540 | 541 | 12. No Surrender of Others' Freedom. 542 | 543 | If conditions are imposed on you (whether by court order, agreement or 544 | otherwise) that contradict the conditions of this License, they do not 545 | excuse you from the conditions of this License. If you cannot convey a 546 | covered work so as to satisfy simultaneously your obligations under this 547 | License and any other pertinent obligations, then as a consequence you may 548 | not convey it at all. For example, if you agree to terms that obligate you 549 | to collect a royalty for further conveying from those to whom you convey 550 | the Program, the only way you could satisfy both those terms and this 551 | License would be to refrain entirely from conveying the Program. 552 | 553 | 13. Use with the GNU Affero General Public License. 554 | 555 | Notwithstanding any other provision of this License, you have 556 | permission to link or combine any covered work with a work licensed 557 | under version 3 of the GNU Affero General Public License into a single 558 | combined work, and to convey the resulting work. The terms of this 559 | License will continue to apply to the part which is the covered work, 560 | but the special requirements of the GNU Affero General Public License, 561 | section 13, concerning interaction through a network will apply to the 562 | combination as such. 563 | 564 | 14. Revised Versions of this License. 565 | 566 | The Free Software Foundation may publish revised and/or new versions of 567 | the GNU General Public License from time to time. Such new versions will 568 | be similar in spirit to the present version, but may differ in detail to 569 | address new problems or concerns. 570 | 571 | Each version is given a distinguishing version number. If the 572 | Program specifies that a certain numbered version of the GNU General 573 | Public License "or any later version" applies to it, you have the 574 | option of following the terms and conditions either of that numbered 575 | version or of any later version published by the Free Software 576 | Foundation. If the Program does not specify a version number of the 577 | GNU General Public License, you may choose any version ever published 578 | by the Free Software Foundation. 579 | 580 | If the Program specifies that a proxy can decide which future 581 | versions of the GNU General Public License can be used, that proxy's 582 | public statement of acceptance of a version permanently authorizes you 583 | to choose that version for the Program. 584 | 585 | Later license versions may give you additional or different 586 | permissions. However, no additional obligations are imposed on any 587 | author or copyright holder as a result of your choosing to follow a 588 | later version. 589 | 590 | 15. Disclaimer of Warranty. 591 | 592 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 593 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 594 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 595 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 596 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 597 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 598 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 599 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 600 | 601 | 16. Limitation of Liability. 602 | 603 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 604 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 605 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 606 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 607 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 608 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 609 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 610 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 611 | SUCH DAMAGES. 612 | 613 | 17. Interpretation of Sections 15 and 16. 614 | 615 | If the disclaimer of warranty and limitation of liability provided 616 | above cannot be given local legal effect according to their terms, 617 | reviewing courts shall apply local law that most closely approximates 618 | an absolute waiver of all civil liability in connection with the 619 | Program, unless a warranty or assumption of liability accompanies a 620 | copy of the Program in return for a fee. 621 | 622 | END OF TERMS AND CONDITIONS 623 | 624 | How to Apply These Terms to Your New Programs 625 | 626 | If you develop a new program, and you want it to be of the greatest 627 | possible use to the public, the best way to achieve this is to make it 628 | free software which everyone can redistribute and change under these terms. 629 | 630 | To do so, attach the following notices to the program. It is safest 631 | to attach them to the start of each source file to most effectively 632 | state the exclusion of warranty; and each file should have at least 633 | the "copyright" line and a pointer to where the full notice is found. 634 | 635 | 636 | Copyright (C) 637 | 638 | This program is free software: you can redistribute it and/or modify 639 | it under the terms of the GNU General Public License as published by 640 | the Free Software Foundation, either version 3 of the License, or 641 | (at your option) any later version. 642 | 643 | This program is distributed in the hope that it will be useful, 644 | but WITHOUT ANY WARRANTY; without even the implied warranty of 645 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 646 | GNU General Public License for more details. 647 | 648 | You should have received a copy of the GNU General Public License 649 | along with this program. If not, see . 650 | 651 | Also add information on how to contact you by electronic and paper mail. 652 | 653 | If the program does terminal interaction, make it output a short 654 | notice like this when it starts in an interactive mode: 655 | 656 | Copyright (C) 657 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 658 | This is free software, and you are welcome to redistribute it 659 | under certain conditions; type `show c' for details. 660 | 661 | The hypothetical commands `show w' and `show c' should show the appropriate 662 | parts of the General Public License. Of course, your program's commands 663 | might be different; for a GUI interface, you would use an "about box". 664 | 665 | You should also get your employer (if you work as a programmer) or school, 666 | if any, to sign a "copyright disclaimer" for the program, if necessary. 667 | For more information on this, and how to apply and follow the GNU GPL, see 668 | . 669 | 670 | The GNU General Public License does not permit incorporating your program 671 | into proprietary programs. If your program is a subroutine library, you 672 | may consider it more useful to permit linking proprietary applications with 673 | the library. If this is what you want to do, use the GNU Lesser General 674 | Public License instead of this License. But first, please read 675 | . 676 | 677 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | COPYING -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include AUTHORS 2 | include NEWS 3 | include NEWS.md 4 | include README 5 | include REAMDE.rst 6 | include COPYING 7 | include examples/* 8 | include libsuinput/src/suinput.h 9 | include libsuinput/src/libudev.h 10 | include udev-rules/* 11 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | 2 | Python-uinput NEWS -- history of user-visible changes 3 | ----------------------------------------------------- 4 | 5 | ## 1.0 6 | 7 | - Project repository moved to pyinput/python-uinput 8 | - Development Status: Stable 9 | - Modern packaging (pyproject.toml) 10 | - Python 3.12 support 11 | 12 | ## 0.11.2 13 | 14 | 15 | - Fix accidentally dropped support for `libudev.so.0` by using ldconfig to find the available library version. 16 | 17 | ## 0.11.1 18 | 19 | - Fix compilation to link against `libudev.so.1` instead of `libudev.so`. 20 | 21 | ## 0.11.0 22 | 23 | 24 | - New device method to close the device: `Device.destroy()` 25 | 26 | - `Device()` is now a context manager suitable to be used with `with`-statement. 27 | 28 | - Improved device initialization error handling. 29 | 30 | - Updated README to include a recommendation to modprobe uinput kernel before usage. 31 | 32 | - Launchpad is deprecated in favor of GitHub. 33 | 34 | - New module function to open a file descriptor to uinput device: `uinput.fdopen()` 35 | 36 | - `Device` constructor accepts an open file descriptor to uinput device as a keyword argument. If not given, uinput file descriptor is opened via `uinput.fdopen()`. 37 | 38 | - Both `README` and ``NEWS`` are renamed and converted to 39 | reStructuredText markup. 40 | 41 | - Input event codes included in ``uinput.ev`` module. 42 | 43 | - Add example of how to drop privileges after device initialization. 44 | 45 | ## 0.10.2 46 | 47 | - Fix `libudev1` compatibility issue. 48 | - Fix mouse example. 49 | 50 | ## 0.10.1 51 | 52 | - Fix Python3 compatibility issue. 53 | 54 | ## 0.10.0 55 | 56 | - New device methods: `Device.emit_click()` and `Device.emit_combo()` 57 | 58 | - Does not depend on `libudev-dev` anymore, because of newer `libsuinput` which re-distributes `libudev.h`. 59 | 60 | ## 0.9 61 | 62 | - Python3 compatibility 63 | - Python2.6 compatibility 64 | 65 | ## 0.8 66 | 67 | - Device id fields can be given in the constructor: bustype, vendor, product and version 68 | 69 | - an example of udev rule 70 | 71 | ## 0.7 72 | 73 | - `libsuinput` is included as a subtree 74 | 75 | ## 0.6.1 76 | 77 | - `README` and `setup.py` updated 78 | 79 | ## 0.6 80 | 81 | - Simplified API. 82 | 83 | - Uses `ctypes` instead of extension modules. 84 | 85 | - libsuinput is included as submodule in git repository 86 | 87 | - source distributions include `suinput.c` 88 | 89 | ## 0.5 90 | 91 | - Documented uinput-module. 92 | 93 | - A minimal joystick (abs-axis) example: `examples/joystick.py`. 94 | 95 | - Reasonable defaults for `abs_parameters`. 96 | 97 | ## 0.4 98 | 99 | - Updated project details, such as homepage, download url, etc. 100 | 101 | ## 0.3.3 102 | 103 | - Explicit dependence on `libsuinput`. 104 | 105 | ## 0.3.2 106 | 107 | - Mention Ubuntu-package in `README`. 108 | 109 | ## 0.3.1 110 | 111 | - New license: GPLv3+ 112 | 113 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | README.rst -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | ============== 2 | Python-uinput 3 | ============== 4 | 5 | Python-uinput is Python interface to Linux uinput kernel module which 6 | allows attaching userspace device drivers into kernel. In practice, 7 | Python-uinput makes it dead simple to create virtual joysticks, 8 | keyboards and mice for generating arbitrary input events 9 | programmatically. 10 | 11 | :Homepage: https://github.com/pyinput/python-uinput 12 | :License: GPLv3+ 13 | 14 | Usage examples 15 | ============== 16 | 17 | Generate keyboard clicks 18 | ------------------------ 19 | 20 | :: 21 | 22 | import uinput 23 | 24 | with uinput.Device([uinput.KEY_E, uinput.KEY_H, 25 | uinput.KEY_L, uinput.KEY_O]) as device: 26 | device.emit_click(uinput.KEY_H) 27 | device.emit_click(uinput.KEY_E) 28 | device.emit_click(uinput.KEY_L) 29 | device.emit_click(uinput.KEY_L) 30 | device.emit_click(uinput.KEY_O) 31 | 32 | Move mouse cursor 33 | ----------------- 34 | 35 | :: 36 | 37 | import uinput 38 | 39 | with uinput.Device([uinput.REL_X, uinput.REL_Y, 40 | uinput.BTN_LEFT, uinput.BTN_RIGHT]) as device: 41 | for i in range(20): 42 | device.emit(uinput.REL_X, 5) 43 | device.emit(uinput.REL_Y, 5) 44 | 45 | Generate keyboard combinations 46 | ------------------------------ 47 | 48 | :: 49 | 50 | import uinput 51 | 52 | with uinput.Device([uinput.KEY_LEFTALT, uinput.KEY_TAB]) as device: 53 | device.emit_combo([uinput.KEY_LEFTALT, uinput.KEY_TAB]) 54 | 55 | See ``examples/`` for other kind of example devices (keyboard, joystick). 56 | 57 | Note that you must have the uinput kernel module loaded to use 58 | python-uinput. To load the module, run:: 59 | 60 | modprobe -i uinput 61 | 62 | If you would like to have uinput to be loaded on every system boot, add 63 | uinput to ``/etc/modules``. 64 | 65 | How to install 66 | ============== 67 | 68 | Just run the following commands:: 69 | 70 | python setup.py build 71 | python setup.py install 72 | 73 | How to report bugs 74 | ================== 75 | 76 | The bug database is hosted in GitHub. If you have found a bug or have an 77 | improvement idea you want to share, please report it at 78 | . However, to avoid 79 | duplicate bug reports, before reporting, please check if similar or identical 80 | bug has already been reported. If so, you can still subscribe to the existing 81 | bug to track its progress. 82 | 83 | How to contribute 84 | ================= 85 | 86 | In addition to reporting bugs and improvement suggestions, you are encouraged to 87 | contribute bug-fixes or features. The source code is maintained in Git and the 88 | main repository is hosted at GitHub, 89 | . The preferred way to 90 | contribute code is to clone the main Git repository and send a pull-request. Good 91 | old patches via email are also accepted. 92 | 93 | How to copy 94 | =========== 95 | 96 | Python-uinput is free (libre) software and licensed under the terms of GNU 97 | Public License version 3 or later. In short, it means that you are free to copy, 98 | modify and redistribute this software as long as you place the derivative work 99 | under a compatible license. See ``COPYING`` for details. 100 | -------------------------------------------------------------------------------- /examples/drop_privileges.py: -------------------------------------------------------------------------------- 1 | import grp 2 | import os 3 | import pwd 4 | 5 | import uinput 6 | 7 | def drop_privileges(uid_name='nobody', gid_name='nogroup'): 8 | # https://stackoverflow.com/questions/2699907/dropping-root-permissions-in-python 9 | 10 | if os.getuid() != 0: 11 | return 12 | 13 | running_uid = pwd.getpwnam(uid_name).pw_uid 14 | running_gid = grp.getgrnam(gid_name).gr_gid 15 | 16 | os.setgroups([]) 17 | os.setgid(running_gid) 18 | os.setuid(running_uid) 19 | old_umask = os.umask(0o77) 20 | 21 | def main(): 22 | uinput_fd = uinput.fdopen() 23 | drop_privileges() # No need to be root beyond this line. 24 | 25 | events = (uinput.KEY_A,) 26 | with uinput.Device(events, fd=uinput_fd) as device: 27 | device.emit_click(uinput.KEY_A) 28 | 29 | if __name__ == "__main__": 30 | main() 31 | -------------------------------------------------------------------------------- /examples/joystick.py: -------------------------------------------------------------------------------- 1 | import uinput 2 | 3 | def main(): 4 | events = ( 5 | uinput.BTN_JOYSTICK, 6 | uinput.ABS_X + (0, 255, 0, 0), 7 | uinput.ABS_Y + (0, 255, 0, 0), 8 | ) 9 | 10 | with uinput.Device(events) as device: 11 | for i in range(20): 12 | # syn=False to emit an "atomic" (5, 5) event. 13 | device.emit(uinput.ABS_X, 5, syn=False) 14 | device.emit(uinput.ABS_Y, 5) 15 | device.emit_click(uinput.BTN_JOYSTICK) 16 | 17 | if __name__ == "__main__": 18 | main() 19 | -------------------------------------------------------------------------------- /examples/keyboard.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | import uinput 4 | 5 | def main(): 6 | events = ( 7 | uinput.KEY_E, 8 | uinput.KEY_H, 9 | uinput.KEY_L, 10 | uinput.KEY_O, 11 | ) 12 | 13 | with uinput.Device(events) as device: 14 | time.sleep(1) # This is required here only for demonstration 15 | # purposes. Without this, the underlying machinery might 16 | # not have time to assign a proper handler for our device 17 | # before the execution of this script reaches the end and 18 | # the device is destroyed. At least this seems to be the 19 | # case with X11 and its generic event device 20 | # handlers. Without this magical sleep, "hello" might not 21 | # get printed because this example exits before X11 gets 22 | # its handlers ready for processing events from this 23 | # device. 24 | device.emit_click(uinput.KEY_H) 25 | device.emit_click(uinput.KEY_E) 26 | device.emit_click(uinput.KEY_L) 27 | device.emit_click(uinput.KEY_L) 28 | device.emit_click(uinput.KEY_O) 29 | 30 | if __name__ == "__main__": 31 | main() 32 | -------------------------------------------------------------------------------- /examples/mouse.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | import uinput 4 | 5 | def main(): 6 | events = ( 7 | uinput.REL_X, 8 | uinput.REL_Y, 9 | uinput.BTN_LEFT, 10 | uinput.BTN_RIGHT, 11 | ) 12 | 13 | with uinput.Device(events) as device: 14 | for i in range(20): 15 | # syn=False to emit an "atomic" (5, 5) event. 16 | device.emit(uinput.REL_X, 5, syn=False) 17 | device.emit(uinput.REL_Y, 5) 18 | 19 | # Just for demonstration purposes: shows the motion. In real 20 | # application, this is of course unnecessary. 21 | time.sleep(0.01) 22 | 23 | if __name__ == "__main__": 24 | main() 25 | -------------------------------------------------------------------------------- /libsuinput/AUTHORS: -------------------------------------------------------------------------------- 1 | Eric Mikula 2 | Esa-Matti Suuronen 3 | Pascal Garber 4 | Tuomas Räsänen 5 | Vincent Bernat 6 | -------------------------------------------------------------------------------- /libsuinput/COPYING: -------------------------------------------------------------------------------- 1 | 2 | GNU GENERAL PUBLIC LICENSE 3 | Version 3, 29 June 2007 4 | 5 | Copyright (C) 2007 Free Software Foundation, Inc. 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The GNU General Public License is a free, copyleft license for 12 | software and other kinds of works. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | the GNU General Public License is intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. We, the Free Software Foundation, use the 19 | GNU General Public License for most of our software; it applies also to 20 | any other work released this way by its authors. You can apply it to 21 | your programs, too. 22 | 23 | When we speak of free software, we are referring to freedom, not 24 | price. Our General Public Licenses are designed to make sure that you 25 | have the freedom to distribute copies of free software (and charge for 26 | them if you wish), that you receive source code or can get it if you 27 | want it, that you can change the software or use pieces of it in new 28 | free programs, and that you know you can do these things. 29 | 30 | To protect your rights, we need to prevent others from denying you 31 | these rights or asking you to surrender the rights. Therefore, you have 32 | certain responsibilities if you distribute copies of the software, or if 33 | you modify it: responsibilities to respect the freedom of others. 34 | 35 | For example, if you distribute copies of such a program, whether 36 | gratis or for a fee, you must pass on to the recipients the same 37 | freedoms that you received. You must make sure that they, too, receive 38 | or can get the source code. And you must show them these terms so they 39 | know their rights. 40 | 41 | Developers that use the GNU GPL protect your rights with two steps: 42 | (1) assert copyright on the software, and (2) offer you this License 43 | giving you legal permission to copy, distribute and/or modify it. 44 | 45 | For the developers' and authors' protection, the GPL clearly explains 46 | that there is no warranty for this free software. For both users' and 47 | authors' sake, the GPL requires that modified versions be marked as 48 | changed, so that their problems will not be attributed erroneously to 49 | authors of previous versions. 50 | 51 | Some devices are designed to deny users access to install or run 52 | modified versions of the software inside them, although the manufacturer 53 | can do so. This is fundamentally incompatible with the aim of 54 | protecting users' freedom to change the software. The systematic 55 | pattern of such abuse occurs in the area of products for individuals to 56 | use, which is precisely where it is most unacceptable. Therefore, we 57 | have designed this version of the GPL to prohibit the practice for those 58 | products. If such problems arise substantially in other domains, we 59 | stand ready to extend this provision to those domains in future versions 60 | of the GPL, as needed to protect the freedom of users. 61 | 62 | Finally, every program is threatened constantly by software patents. 63 | States should not allow patents to restrict development and use of 64 | software on general-purpose computers, but in those that do, we wish to 65 | avoid the special danger that patents applied to a free program could 66 | make it effectively proprietary. To prevent this, the GPL assures that 67 | patents cannot be used to render the program non-free. 68 | 69 | The precise terms and conditions for copying, distribution and 70 | modification follow. 71 | 72 | TERMS AND CONDITIONS 73 | 74 | 0. Definitions. 75 | 76 | "This License" refers to version 3 of the GNU General Public License. 77 | 78 | "Copyright" also means copyright-like laws that apply to other kinds of 79 | works, such as semiconductor masks. 80 | 81 | "The Program" refers to any copyrightable work licensed under this 82 | License. Each licensee is addressed as "you". "Licensees" and 83 | "recipients" may be individuals or organizations. 84 | 85 | To "modify" a work means to copy from or adapt all or part of the work 86 | in a fashion requiring copyright permission, other than the making of an 87 | exact copy. The resulting work is called a "modified version" of the 88 | earlier work or a work "based on" the earlier work. 89 | 90 | A "covered work" means either the unmodified Program or a work based 91 | on the Program. 92 | 93 | To "propagate" a work means to do anything with it that, without 94 | permission, would make you directly or secondarily liable for 95 | infringement under applicable copyright law, except executing it on a 96 | computer or modifying a private copy. Propagation includes copying, 97 | distribution (with or without modification), making available to the 98 | public, and in some countries other activities as well. 99 | 100 | To "convey" a work means any kind of propagation that enables other 101 | parties to make or receive copies. Mere interaction with a user through 102 | a computer network, with no transfer of a copy, is not conveying. 103 | 104 | An interactive user interface displays "Appropriate Legal Notices" 105 | to the extent that it includes a convenient and prominently visible 106 | feature that (1) displays an appropriate copyright notice, and (2) 107 | tells the user that there is no warranty for the work (except to the 108 | extent that warranties are provided), that licensees may convey the 109 | work under this License, and how to view a copy of this License. If 110 | the interface presents a list of user commands or options, such as a 111 | menu, a prominent item in the list meets this criterion. 112 | 113 | 1. Source Code. 114 | 115 | The "source code" for a work means the preferred form of the work 116 | for making modifications to it. "Object code" means any non-source 117 | form of a work. 118 | 119 | A "Standard Interface" means an interface that either is an official 120 | standard defined by a recognized standards body, or, in the case of 121 | interfaces specified for a particular programming language, one that 122 | is widely used among developers working in that language. 123 | 124 | The "System Libraries" of an executable work include anything, other 125 | than the work as a whole, that (a) is included in the normal form of 126 | packaging a Major Component, but which is not part of that Major 127 | Component, and (b) serves only to enable use of the work with that 128 | Major Component, or to implement a Standard Interface for which an 129 | implementation is available to the public in source code form. A 130 | "Major Component", in this context, means a major essential component 131 | (kernel, window system, and so on) of the specific operating system 132 | (if any) on which the executable work runs, or a compiler used to 133 | produce the work, or an object code interpreter used to run it. 134 | 135 | The "Corresponding Source" for a work in object code form means all 136 | the source code needed to generate, install, and (for an executable 137 | work) run the object code and to modify the work, including scripts to 138 | control those activities. However, it does not include the work's 139 | System Libraries, or general-purpose tools or generally available free 140 | programs which are used unmodified in performing those activities but 141 | which are not part of the work. For example, Corresponding Source 142 | includes interface definition files associated with source files for 143 | the work, and the source code for shared libraries and dynamically 144 | linked subprograms that the work is specifically designed to require, 145 | such as by intimate data communication or control flow between those 146 | subprograms and other parts of the work. 147 | 148 | The Corresponding Source need not include anything that users 149 | can regenerate automatically from other parts of the Corresponding 150 | Source. 151 | 152 | The Corresponding Source for a work in source code form is that 153 | same work. 154 | 155 | 2. Basic Permissions. 156 | 157 | All rights granted under this License are granted for the term of 158 | copyright on the Program, and are irrevocable provided the stated 159 | conditions are met. This License explicitly affirms your unlimited 160 | permission to run the unmodified Program. The output from running a 161 | covered work is covered by this License only if the output, given its 162 | content, constitutes a covered work. This License acknowledges your 163 | rights of fair use or other equivalent, as provided by copyright law. 164 | 165 | You may make, run and propagate covered works that you do not 166 | convey, without conditions so long as your license otherwise remains 167 | in force. You may convey covered works to others for the sole purpose 168 | of having them make modifications exclusively for you, or provide you 169 | with facilities for running those works, provided that you comply with 170 | the terms of this License in conveying all material for which you do 171 | not control copyright. Those thus making or running the covered works 172 | for you must do so exclusively on your behalf, under your direction 173 | and control, on terms that prohibit them from making any copies of 174 | your copyrighted material outside their relationship with you. 175 | 176 | Conveying under any other circumstances is permitted solely under 177 | the conditions stated below. Sublicensing is not allowed; section 10 178 | makes it unnecessary. 179 | 180 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 181 | 182 | No covered work shall be deemed part of an effective technological 183 | measure under any applicable law fulfilling obligations under article 184 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 185 | similar laws prohibiting or restricting circumvention of such 186 | measures. 187 | 188 | When you convey a covered work, you waive any legal power to forbid 189 | circumvention of technological measures to the extent such circumvention 190 | is effected by exercising rights under this License with respect to 191 | the covered work, and you disclaim any intention to limit operation or 192 | modification of the work as a means of enforcing, against the work's 193 | users, your or third parties' legal rights to forbid circumvention of 194 | technological measures. 195 | 196 | 4. Conveying Verbatim Copies. 197 | 198 | You may convey verbatim copies of the Program's source code as you 199 | receive it, in any medium, provided that you conspicuously and 200 | appropriately publish on each copy an appropriate copyright notice; 201 | keep intact all notices stating that this License and any 202 | non-permissive terms added in accord with section 7 apply to the code; 203 | keep intact all notices of the absence of any warranty; and give all 204 | recipients a copy of this License along with the Program. 205 | 206 | You may charge any price or no price for each copy that you convey, 207 | and you may offer support or warranty protection for a fee. 208 | 209 | 5. Conveying Modified Source Versions. 210 | 211 | You may convey a work based on the Program, or the modifications to 212 | produce it from the Program, in the form of source code under the 213 | terms of section 4, provided that you also meet all of these conditions: 214 | 215 | a) The work must carry prominent notices stating that you modified 216 | it, and giving a relevant date. 217 | 218 | b) The work must carry prominent notices stating that it is 219 | released under this License and any conditions added under section 220 | 7. This requirement modifies the requirement in section 4 to 221 | "keep intact all notices". 222 | 223 | c) You must license the entire work, as a whole, under this 224 | License to anyone who comes into possession of a copy. This 225 | License will therefore apply, along with any applicable section 7 226 | additional terms, to the whole of the work, and all its parts, 227 | regardless of how they are packaged. This License gives no 228 | permission to license the work in any other way, but it does not 229 | invalidate such permission if you have separately received it. 230 | 231 | d) If the work has interactive user interfaces, each must display 232 | Appropriate Legal Notices; however, if the Program has interactive 233 | interfaces that do not display Appropriate Legal Notices, your 234 | work need not make them do so. 235 | 236 | A compilation of a covered work with other separate and independent 237 | works, which are not by their nature extensions of the covered work, 238 | and which are not combined with it such as to form a larger program, 239 | in or on a volume of a storage or distribution medium, is called an 240 | "aggregate" if the compilation and its resulting copyright are not 241 | used to limit the access or legal rights of the compilation's users 242 | beyond what the individual works permit. Inclusion of a covered work 243 | in an aggregate does not cause this License to apply to the other 244 | parts of the aggregate. 245 | 246 | 6. Conveying Non-Source Forms. 247 | 248 | You may convey a covered work in object code form under the terms 249 | of sections 4 and 5, provided that you also convey the 250 | machine-readable Corresponding Source under the terms of this License, 251 | in one of these ways: 252 | 253 | a) Convey the object code in, or embodied in, a physical product 254 | (including a physical distribution medium), accompanied by the 255 | Corresponding Source fixed on a durable physical medium 256 | customarily used for software interchange. 257 | 258 | b) Convey the object code in, or embodied in, a physical product 259 | (including a physical distribution medium), accompanied by a 260 | written offer, valid for at least three years and valid for as 261 | long as you offer spare parts or customer support for that product 262 | model, to give anyone who possesses the object code either (1) a 263 | copy of the Corresponding Source for all the software in the 264 | product that is covered by this License, on a durable physical 265 | medium customarily used for software interchange, for a price no 266 | more than your reasonable cost of physically performing this 267 | conveying of source, or (2) access to copy the 268 | Corresponding Source from a network server at no charge. 269 | 270 | c) Convey individual copies of the object code with a copy of the 271 | written offer to provide the Corresponding Source. This 272 | alternative is allowed only occasionally and noncommercially, and 273 | only if you received the object code with such an offer, in accord 274 | with subsection 6b. 275 | 276 | d) Convey the object code by offering access from a designated 277 | place (gratis or for a charge), and offer equivalent access to the 278 | Corresponding Source in the same way through the same place at no 279 | further charge. You need not require recipients to copy the 280 | Corresponding Source along with the object code. If the place to 281 | copy the object code is a network server, the Corresponding Source 282 | may be on a different server (operated by you or a third party) 283 | that supports equivalent copying facilities, provided you maintain 284 | clear directions next to the object code saying where to find the 285 | Corresponding Source. Regardless of what server hosts the 286 | Corresponding Source, you remain obligated to ensure that it is 287 | available for as long as needed to satisfy these requirements. 288 | 289 | e) Convey the object code using peer-to-peer transmission, provided 290 | you inform other peers where the object code and Corresponding 291 | Source of the work are being offered to the general public at no 292 | charge under subsection 6d. 293 | 294 | A separable portion of the object code, whose source code is excluded 295 | from the Corresponding Source as a System Library, need not be 296 | included in conveying the object code work. 297 | 298 | A "User Product" is either (1) a "consumer product", which means any 299 | tangible personal property which is normally used for personal, family, 300 | or household purposes, or (2) anything designed or sold for incorporation 301 | into a dwelling. In determining whether a product is a consumer product, 302 | doubtful cases shall be resolved in favor of coverage. For a particular 303 | product received by a particular user, "normally used" refers to a 304 | typical or common use of that class of product, regardless of the status 305 | of the particular user or of the way in which the particular user 306 | actually uses, or expects or is expected to use, the product. A product 307 | is a consumer product regardless of whether the product has substantial 308 | commercial, industrial or non-consumer uses, unless such uses represent 309 | the only significant mode of use of the product. 310 | 311 | "Installation Information" for a User Product means any methods, 312 | procedures, authorization keys, or other information required to install 313 | and execute modified versions of a covered work in that User Product from 314 | a modified version of its Corresponding Source. The information must 315 | suffice to ensure that the continued functioning of the modified object 316 | code is in no case prevented or interfered with solely because 317 | modification has been made. 318 | 319 | If you convey an object code work under this section in, or with, or 320 | specifically for use in, a User Product, and the conveying occurs as 321 | part of a transaction in which the right of possession and use of the 322 | User Product is transferred to the recipient in perpetuity or for a 323 | fixed term (regardless of how the transaction is characterized), the 324 | Corresponding Source conveyed under this section must be accompanied 325 | by the Installation Information. But this requirement does not apply 326 | if neither you nor any third party retains the ability to install 327 | modified object code on the User Product (for example, the work has 328 | been installed in ROM). 329 | 330 | The requirement to provide Installation Information does not include a 331 | requirement to continue to provide support service, warranty, or updates 332 | for a work that has been modified or installed by the recipient, or for 333 | the User Product in which it has been modified or installed. Access to a 334 | network may be denied when the modification itself materially and 335 | adversely affects the operation of the network or violates the rules and 336 | protocols for communication across the network. 337 | 338 | Corresponding Source conveyed, and Installation Information provided, 339 | in accord with this section must be in a format that is publicly 340 | documented (and with an implementation available to the public in 341 | source code form), and must require no special password or key for 342 | unpacking, reading or copying. 343 | 344 | 7. Additional Terms. 345 | 346 | "Additional permissions" are terms that supplement the terms of this 347 | License by making exceptions from one or more of its conditions. 348 | Additional permissions that are applicable to the entire Program shall 349 | be treated as though they were included in this License, to the extent 350 | that they are valid under applicable law. If additional permissions 351 | apply only to part of the Program, that part may be used separately 352 | under those permissions, but the entire Program remains governed by 353 | this License without regard to the additional permissions. 354 | 355 | When you convey a copy of a covered work, you may at your option 356 | remove any additional permissions from that copy, or from any part of 357 | it. (Additional permissions may be written to require their own 358 | removal in certain cases when you modify the work.) You may place 359 | additional permissions on material, added by you to a covered work, 360 | for which you have or can give appropriate copyright permission. 361 | 362 | Notwithstanding any other provision of this License, for material you 363 | add to a covered work, you may (if authorized by the copyright holders of 364 | that material) supplement the terms of this License with terms: 365 | 366 | a) Disclaiming warranty or limiting liability differently from the 367 | terms of sections 15 and 16 of this License; or 368 | 369 | b) Requiring preservation of specified reasonable legal notices or 370 | author attributions in that material or in the Appropriate Legal 371 | Notices displayed by works containing it; or 372 | 373 | c) Prohibiting misrepresentation of the origin of that material, or 374 | requiring that modified versions of such material be marked in 375 | reasonable ways as different from the original version; or 376 | 377 | d) Limiting the use for publicity purposes of names of licensors or 378 | authors of the material; or 379 | 380 | e) Declining to grant rights under trademark law for use of some 381 | trade names, trademarks, or service marks; or 382 | 383 | f) Requiring indemnification of licensors and authors of that 384 | material by anyone who conveys the material (or modified versions of 385 | it) with contractual assumptions of liability to the recipient, for 386 | any liability that these contractual assumptions directly impose on 387 | those licensors and authors. 388 | 389 | All other non-permissive additional terms are considered "further 390 | restrictions" within the meaning of section 10. If the Program as you 391 | received it, or any part of it, contains a notice stating that it is 392 | governed by this License along with a term that is a further 393 | restriction, you may remove that term. If a license document contains 394 | a further restriction but permits relicensing or conveying under this 395 | License, you may add to a covered work material governed by the terms 396 | of that license document, provided that the further restriction does 397 | not survive such relicensing or conveying. 398 | 399 | If you add terms to a covered work in accord with this section, you 400 | must place, in the relevant source files, a statement of the 401 | additional terms that apply to those files, or a notice indicating 402 | where to find the applicable terms. 403 | 404 | Additional terms, permissive or non-permissive, may be stated in the 405 | form of a separately written license, or stated as exceptions; 406 | the above requirements apply either way. 407 | 408 | 8. Termination. 409 | 410 | You may not propagate or modify a covered work except as expressly 411 | provided under this License. Any attempt otherwise to propagate or 412 | modify it is void, and will automatically terminate your rights under 413 | this License (including any patent licenses granted under the third 414 | paragraph of section 11). 415 | 416 | However, if you cease all violation of this License, then your 417 | license from a particular copyright holder is reinstated (a) 418 | provisionally, unless and until the copyright holder explicitly and 419 | finally terminates your license, and (b) permanently, if the copyright 420 | holder fails to notify you of the violation by some reasonable means 421 | prior to 60 days after the cessation. 422 | 423 | Moreover, your license from a particular copyright holder is 424 | reinstated permanently if the copyright holder notifies you of the 425 | violation by some reasonable means, this is the first time you have 426 | received notice of violation of this License (for any work) from that 427 | copyright holder, and you cure the violation prior to 30 days after 428 | your receipt of the notice. 429 | 430 | Termination of your rights under this section does not terminate the 431 | licenses of parties who have received copies or rights from you under 432 | this License. If your rights have been terminated and not permanently 433 | reinstated, you do not qualify to receive new licenses for the same 434 | material under section 10. 435 | 436 | 9. Acceptance Not Required for Having Copies. 437 | 438 | You are not required to accept this License in order to receive or 439 | run a copy of the Program. Ancillary propagation of a covered work 440 | occurring solely as a consequence of using peer-to-peer transmission 441 | to receive a copy likewise does not require acceptance. However, 442 | nothing other than this License grants you permission to propagate or 443 | modify any covered work. These actions infringe copyright if you do 444 | not accept this License. Therefore, by modifying or propagating a 445 | covered work, you indicate your acceptance of this License to do so. 446 | 447 | 10. Automatic Licensing of Downstream Recipients. 448 | 449 | Each time you convey a covered work, the recipient automatically 450 | receives a license from the original licensors, to run, modify and 451 | propagate that work, subject to this License. You are not responsible 452 | for enforcing compliance by third parties with this License. 453 | 454 | An "entity transaction" is a transaction transferring control of an 455 | organization, or substantially all assets of one, or subdividing an 456 | organization, or merging organizations. If propagation of a covered 457 | work results from an entity transaction, each party to that 458 | transaction who receives a copy of the work also receives whatever 459 | licenses to the work the party's predecessor in interest had or could 460 | give under the previous paragraph, plus a right to possession of the 461 | Corresponding Source of the work from the predecessor in interest, if 462 | the predecessor has it or can get it with reasonable efforts. 463 | 464 | You may not impose any further restrictions on the exercise of the 465 | rights granted or affirmed under this License. For example, you may 466 | not impose a license fee, royalty, or other charge for exercise of 467 | rights granted under this License, and you may not initiate litigation 468 | (including a cross-claim or counterclaim in a lawsuit) alleging that 469 | any patent claim is infringed by making, using, selling, offering for 470 | sale, or importing the Program or any portion of it. 471 | 472 | 11. Patents. 473 | 474 | A "contributor" is a copyright holder who authorizes use under this 475 | License of the Program or a work on which the Program is based. The 476 | work thus licensed is called the contributor's "contributor version". 477 | 478 | A contributor's "essential patent claims" are all patent claims 479 | owned or controlled by the contributor, whether already acquired or 480 | hereafter acquired, that would be infringed by some manner, permitted 481 | by this License, of making, using, or selling its contributor version, 482 | but do not include claims that would be infringed only as a 483 | consequence of further modification of the contributor version. For 484 | purposes of this definition, "control" includes the right to grant 485 | patent sublicenses in a manner consistent with the requirements of 486 | this License. 487 | 488 | Each contributor grants you a non-exclusive, worldwide, royalty-free 489 | patent license under the contributor's essential patent claims, to 490 | make, use, sell, offer for sale, import and otherwise run, modify and 491 | propagate the contents of its contributor version. 492 | 493 | In the following three paragraphs, a "patent license" is any express 494 | agreement or commitment, however denominated, not to enforce a patent 495 | (such as an express permission to practice a patent or covenant not to 496 | sue for patent infringement). To "grant" such a patent license to a 497 | party means to make such an agreement or commitment not to enforce a 498 | patent against the party. 499 | 500 | If you convey a covered work, knowingly relying on a patent license, 501 | and the Corresponding Source of the work is not available for anyone 502 | to copy, free of charge and under the terms of this License, through a 503 | publicly available network server or other readily accessible means, 504 | then you must either (1) cause the Corresponding Source to be so 505 | available, or (2) arrange to deprive yourself of the benefit of the 506 | patent license for this particular work, or (3) arrange, in a manner 507 | consistent with the requirements of this License, to extend the patent 508 | license to downstream recipients. "Knowingly relying" means you have 509 | actual knowledge that, but for the patent license, your conveying the 510 | covered work in a country, or your recipient's use of the covered work 511 | in a country, would infringe one or more identifiable patents in that 512 | country that you have reason to believe are valid. 513 | 514 | If, pursuant to or in connection with a single transaction or 515 | arrangement, you convey, or propagate by procuring conveyance of, a 516 | covered work, and grant a patent license to some of the parties 517 | receiving the covered work authorizing them to use, propagate, modify 518 | or convey a specific copy of the covered work, then the patent license 519 | you grant is automatically extended to all recipients of the covered 520 | work and works based on it. 521 | 522 | A patent license is "discriminatory" if it does not include within 523 | the scope of its coverage, prohibits the exercise of, or is 524 | conditioned on the non-exercise of one or more of the rights that are 525 | specifically granted under this License. You may not convey a covered 526 | work if you are a party to an arrangement with a third party that is 527 | in the business of distributing software, under which you make payment 528 | to the third party based on the extent of your activity of conveying 529 | the work, and under which the third party grants, to any of the 530 | parties who would receive the covered work from you, a discriminatory 531 | patent license (a) in connection with copies of the covered work 532 | conveyed by you (or copies made from those copies), or (b) primarily 533 | for and in connection with specific products or compilations that 534 | contain the covered work, unless you entered into that arrangement, 535 | or that patent license was granted, prior to 28 March 2007. 536 | 537 | Nothing in this License shall be construed as excluding or limiting 538 | any implied license or other defenses to infringement that may 539 | otherwise be available to you under applicable patent law. 540 | 541 | 12. No Surrender of Others' Freedom. 542 | 543 | If conditions are imposed on you (whether by court order, agreement or 544 | otherwise) that contradict the conditions of this License, they do not 545 | excuse you from the conditions of this License. If you cannot convey a 546 | covered work so as to satisfy simultaneously your obligations under this 547 | License and any other pertinent obligations, then as a consequence you may 548 | not convey it at all. For example, if you agree to terms that obligate you 549 | to collect a royalty for further conveying from those to whom you convey 550 | the Program, the only way you could satisfy both those terms and this 551 | License would be to refrain entirely from conveying the Program. 552 | 553 | 13. Use with the GNU Affero General Public License. 554 | 555 | Notwithstanding any other provision of this License, you have 556 | permission to link or combine any covered work with a work licensed 557 | under version 3 of the GNU Affero General Public License into a single 558 | combined work, and to convey the resulting work. The terms of this 559 | License will continue to apply to the part which is the covered work, 560 | but the special requirements of the GNU Affero General Public License, 561 | section 13, concerning interaction through a network will apply to the 562 | combination as such. 563 | 564 | 14. Revised Versions of this License. 565 | 566 | The Free Software Foundation may publish revised and/or new versions of 567 | the GNU General Public License from time to time. Such new versions will 568 | be similar in spirit to the present version, but may differ in detail to 569 | address new problems or concerns. 570 | 571 | Each version is given a distinguishing version number. If the 572 | Program specifies that a certain numbered version of the GNU General 573 | Public License "or any later version" applies to it, you have the 574 | option of following the terms and conditions either of that numbered 575 | version or of any later version published by the Free Software 576 | Foundation. If the Program does not specify a version number of the 577 | GNU General Public License, you may choose any version ever published 578 | by the Free Software Foundation. 579 | 580 | If the Program specifies that a proxy can decide which future 581 | versions of the GNU General Public License can be used, that proxy's 582 | public statement of acceptance of a version permanently authorizes you 583 | to choose that version for the Program. 584 | 585 | Later license versions may give you additional or different 586 | permissions. However, no additional obligations are imposed on any 587 | author or copyright holder as a result of your choosing to follow a 588 | later version. 589 | 590 | 15. Disclaimer of Warranty. 591 | 592 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 593 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 594 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 595 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 596 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 597 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 598 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 599 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 600 | 601 | 16. Limitation of Liability. 602 | 603 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 604 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 605 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 606 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 607 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 608 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 609 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 610 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 611 | SUCH DAMAGES. 612 | 613 | 17. Interpretation of Sections 15 and 16. 614 | 615 | If the disclaimer of warranty and limitation of liability provided 616 | above cannot be given local legal effect according to their terms, 617 | reviewing courts shall apply local law that most closely approximates 618 | an absolute waiver of all civil liability in connection with the 619 | Program, unless a warranty or assumption of liability accompanies a 620 | copy of the Program in return for a fee. 621 | 622 | END OF TERMS AND CONDITIONS 623 | 624 | How to Apply These Terms to Your New Programs 625 | 626 | If you develop a new program, and you want it to be of the greatest 627 | possible use to the public, the best way to achieve this is to make it 628 | free software which everyone can redistribute and change under these terms. 629 | 630 | To do so, attach the following notices to the program. It is safest 631 | to attach them to the start of each source file to most effectively 632 | state the exclusion of warranty; and each file should have at least 633 | the "copyright" line and a pointer to where the full notice is found. 634 | 635 | 636 | Copyright (C) 637 | 638 | This program is free software: you can redistribute it and/or modify 639 | it under the terms of the GNU General Public License as published by 640 | the Free Software Foundation, either version 3 of the License, or 641 | (at your option) any later version. 642 | 643 | This program is distributed in the hope that it will be useful, 644 | but WITHOUT ANY WARRANTY; without even the implied warranty of 645 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 646 | GNU General Public License for more details. 647 | 648 | You should have received a copy of the GNU General Public License 649 | along with this program. If not, see . 650 | 651 | Also add information on how to contact you by electronic and paper mail. 652 | 653 | If the program does terminal interaction, make it output a short 654 | notice like this when it starts in an interactive mode: 655 | 656 | Copyright (C) 657 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 658 | This is free software, and you are welcome to redistribute it 659 | under certain conditions; type `show c' for details. 660 | 661 | The hypothetical commands `show w' and `show c' should show the appropriate 662 | parts of the General Public License. Of course, your program's commands 663 | might be different; for a GUI interface, you would use an "about box". 664 | 665 | You should also get your employer (if you work as a programmer) or school, 666 | if any, to sign a "copyright disclaimer" for the program, if necessary. 667 | For more information on this, and how to apply and follow the GNU GPL, see 668 | . 669 | 670 | The GNU General Public License does not permit incorporating your program 671 | into proprietary programs. If your program is a subroutine library, you 672 | may consider it more useful to permit linking proprietary applications with 673 | the library. If this is what you want to do, use the GNU Lesser General 674 | Public License instead of this License. But first, please read 675 | . 676 | 677 | -------------------------------------------------------------------------------- /libsuinput/INSTALL: -------------------------------------------------------------------------------- 1 | Installation Instructions 2 | ************************* 3 | 4 | Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, 5 | 2006, 2007, 2008, 2009 Free Software Foundation, Inc. 6 | 7 | This file is free documentation; the Free Software Foundation gives 8 | unlimited permission to copy, distribute and modify it. 9 | 10 | Basic Installation 11 | ================== 12 | 13 | Briefly, the shell commands `./configure; make; make install' should 14 | configure, build, and install this package. The following 15 | more-detailed instructions are generic; see the `README' file for 16 | instructions specific to this package. 17 | 18 | The `configure' shell script attempts to guess correct values for 19 | various system-dependent variables used during compilation. It uses 20 | those values to create a `Makefile' in each directory of the package. 21 | It may also create one or more `.h' files containing system-dependent 22 | definitions. Finally, it creates a shell script `config.status' that 23 | you can run in the future to recreate the current configuration, and a 24 | file `config.log' containing compiler output (useful mainly for 25 | debugging `configure'). 26 | 27 | It can also use an optional file (typically called `config.cache' 28 | and enabled with `--cache-file=config.cache' or simply `-C') that saves 29 | the results of its tests to speed up reconfiguring. Caching is 30 | disabled by default to prevent problems with accidental use of stale 31 | cache files. 32 | 33 | If you need to do unusual things to compile the package, please try 34 | to figure out how `configure' could check whether to do them, and mail 35 | diffs or instructions to the address given in the `README' so they can 36 | be considered for the next release. If you are using the cache, and at 37 | some point `config.cache' contains results you don't want to keep, you 38 | may remove or edit it. 39 | 40 | The file `configure.ac' (or `configure.in') is used to create 41 | `configure' by a program called `autoconf'. You need `configure.ac' if 42 | you want to change it or regenerate `configure' using a newer version 43 | of `autoconf'. 44 | 45 | The simplest way to compile this package is: 46 | 47 | 1. `cd' to the directory containing the package's source code and type 48 | `./configure' to configure the package for your system. 49 | 50 | Running `configure' might take a while. While running, it prints 51 | some messages telling which features it is checking for. 52 | 53 | 2. Type `make' to compile the package. 54 | 55 | 3. Optionally, type `make check' to run any self-tests that come with 56 | the package. 57 | 58 | 4. Type `make install' to install the programs and any data files and 59 | documentation. 60 | 61 | 5. You can remove the program binaries and object files from the 62 | source code directory by typing `make clean'. To also remove the 63 | files that `configure' created (so you can compile the package for 64 | a different kind of computer), type `make distclean'. There is 65 | also a `make maintainer-clean' target, but that is intended mainly 66 | for the package's developers. If you use it, you may have to get 67 | all sorts of other programs in order to regenerate files that came 68 | with the distribution. 69 | 70 | 6. Often, you can also type `make uninstall' to remove the installed 71 | files again. 72 | 73 | Compilers and Options 74 | ===================== 75 | 76 | Some systems require unusual options for compilation or linking that 77 | the `configure' script does not know about. Run `./configure --help' 78 | for details on some of the pertinent environment variables. 79 | 80 | You can give `configure' initial values for configuration parameters 81 | by setting variables in the command line or in the environment. Here 82 | is an example: 83 | 84 | ./configure CC=c99 CFLAGS=-g LIBS=-lposix 85 | 86 | *Note Defining Variables::, for more details. 87 | 88 | Compiling For Multiple Architectures 89 | ==================================== 90 | 91 | You can compile the package for more than one kind of computer at the 92 | same time, by placing the object files for each architecture in their 93 | own directory. To do this, you can use GNU `make'. `cd' to the 94 | directory where you want the object files and executables to go and run 95 | the `configure' script. `configure' automatically checks for the 96 | source code in the directory that `configure' is in and in `..'. 97 | 98 | With a non-GNU `make', it is safer to compile the package for one 99 | architecture at a time in the source code directory. After you have 100 | installed the package for one architecture, use `make distclean' before 101 | reconfiguring for another architecture. 102 | 103 | On MacOS X 10.5 and later systems, you can create libraries and 104 | executables that work on multiple system types--known as "fat" or 105 | "universal" binaries--by specifying multiple `-arch' options to the 106 | compiler but only a single `-arch' option to the preprocessor. Like 107 | this: 108 | 109 | ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ 110 | CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ 111 | CPP="gcc -E" CXXCPP="g++ -E" 112 | 113 | This is not guaranteed to produce working output in all cases, you 114 | may have to build one architecture at a time and combine the results 115 | using the `lipo' tool if you have problems. 116 | 117 | Installation Names 118 | ================== 119 | 120 | By default, `make install' installs the package's commands under 121 | `/usr/local/bin', include files under `/usr/local/include', etc. You 122 | can specify an installation prefix other than `/usr/local' by giving 123 | `configure' the option `--prefix=PREFIX'. 124 | 125 | You can specify separate installation prefixes for 126 | architecture-specific files and architecture-independent files. If you 127 | pass the option `--exec-prefix=PREFIX' to `configure', the package uses 128 | PREFIX as the prefix for installing programs and libraries. 129 | Documentation and other data files still use the regular prefix. 130 | 131 | In addition, if you use an unusual directory layout you can give 132 | options like `--bindir=DIR' to specify different values for particular 133 | kinds of files. Run `configure --help' for a list of the directories 134 | you can set and what kinds of files go in them. 135 | 136 | If the package supports it, you can cause programs to be installed 137 | with an extra prefix or suffix on their names by giving `configure' the 138 | option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. 139 | 140 | Optional Features 141 | ================= 142 | 143 | Some packages pay attention to `--enable-FEATURE' options to 144 | `configure', where FEATURE indicates an optional part of the package. 145 | They may also pay attention to `--with-PACKAGE' options, where PACKAGE 146 | is something like `gnu-as' or `x' (for the X Window System). The 147 | `README' should mention any `--enable-' and `--with-' options that the 148 | package recognizes. 149 | 150 | For packages that use the X Window System, `configure' can usually 151 | find the X include and library files automatically, but if it doesn't, 152 | you can use the `configure' options `--x-includes=DIR' and 153 | `--x-libraries=DIR' to specify their locations. 154 | 155 | Particular systems 156 | ================== 157 | 158 | On HP-UX, the default C compiler is not ANSI C compatible. If GNU 159 | CC is not installed, it is recommended to use the following options in 160 | order to use an ANSI C compiler: 161 | 162 | ./configure CC="cc -Ae -D_XOPEN_SOURCE=500" 163 | 164 | and if that doesn't work, install pre-built binaries of GCC for HP-UX. 165 | 166 | On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot 167 | parse its `' header file. The option `-nodtk' can be used as 168 | a workaround. If GNU CC is not installed, it is therefore recommended 169 | to try 170 | 171 | ./configure CC="cc" 172 | 173 | and if that doesn't work, try 174 | 175 | ./configure CC="cc -nodtk" 176 | 177 | On Solaris, don't put `/usr/ucb' early in your `PATH'. This 178 | directory contains several dysfunctional programs; working variants of 179 | these programs are available in `/usr/bin'. So, if you need `/usr/ucb' 180 | in your `PATH', put it _after_ `/usr/bin'. 181 | 182 | On Haiku, software installed for all users goes in `/boot/common', 183 | not `/usr/local'. It is recommended to use the following options: 184 | 185 | ./configure --prefix=/boot/common 186 | 187 | Specifying the System Type 188 | ========================== 189 | 190 | There may be some features `configure' cannot figure out 191 | automatically, but needs to determine by the type of machine the package 192 | will run on. Usually, assuming the package is built to be run on the 193 | _same_ architectures, `configure' can figure that out, but if it prints 194 | a message saying it cannot guess the machine type, give it the 195 | `--build=TYPE' option. TYPE can either be a short name for the system 196 | type, such as `sun4', or a canonical name which has the form: 197 | 198 | CPU-COMPANY-SYSTEM 199 | 200 | where SYSTEM can have one of these forms: 201 | 202 | OS 203 | KERNEL-OS 204 | 205 | See the file `config.sub' for the possible values of each field. If 206 | `config.sub' isn't included in this package, then this package doesn't 207 | need to know the machine type. 208 | 209 | If you are _building_ compiler tools for cross-compiling, you should 210 | use the option `--target=TYPE' to select the type of system they will 211 | produce code for. 212 | 213 | If you want to _use_ a cross compiler, that generates code for a 214 | platform different from the build platform, you should specify the 215 | "host" platform (i.e., that on which the generated programs will 216 | eventually be run) with `--host=TYPE'. 217 | 218 | Sharing Defaults 219 | ================ 220 | 221 | If you want to set default values for `configure' scripts to share, 222 | you can create a site shell script called `config.site' that gives 223 | default values for variables like `CC', `cache_file', and `prefix'. 224 | `configure' looks for `PREFIX/share/config.site' if it exists, then 225 | `PREFIX/etc/config.site' if it exists. Or, you can set the 226 | `CONFIG_SITE' environment variable to the location of the site script. 227 | A warning: not all `configure' scripts look for a site script. 228 | 229 | Defining Variables 230 | ================== 231 | 232 | Variables not defined in a site shell script can be set in the 233 | environment passed to `configure'. However, some packages may run 234 | configure again during the build, and the customized values of these 235 | variables may be lost. In order to avoid this problem, you should set 236 | them in the `configure' command line, using `VAR=value'. For example: 237 | 238 | ./configure CC=/usr/local2/bin/gcc 239 | 240 | causes the specified `gcc' to be used as the C compiler (unless it is 241 | overridden in the site shell script). 242 | 243 | Unfortunately, this technique does not work for `CONFIG_SHELL' due to 244 | an Autoconf bug. Until the bug is fixed you can use this workaround: 245 | 246 | CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash 247 | 248 | `configure' Invocation 249 | ====================== 250 | 251 | `configure' recognizes the following options to control how it 252 | operates. 253 | 254 | `--help' 255 | `-h' 256 | Print a summary of all of the options to `configure', and exit. 257 | 258 | `--help=short' 259 | `--help=recursive' 260 | Print a summary of the options unique to this package's 261 | `configure', and exit. The `short' variant lists options used 262 | only in the top level, while the `recursive' variant lists options 263 | also present in any nested packages. 264 | 265 | `--version' 266 | `-V' 267 | Print the version of Autoconf used to generate the `configure' 268 | script, and exit. 269 | 270 | `--cache-file=FILE' 271 | Enable the cache: use and save the results of the tests in FILE, 272 | traditionally `config.cache'. FILE defaults to `/dev/null' to 273 | disable caching. 274 | 275 | `--config-cache' 276 | `-C' 277 | Alias for `--cache-file=config.cache'. 278 | 279 | `--quiet' 280 | `--silent' 281 | `-q' 282 | Do not print messages saying which checks are being made. To 283 | suppress all normal output, redirect it to `/dev/null' (any error 284 | messages will still be shown). 285 | 286 | `--srcdir=DIR' 287 | Look for the package's source code in directory DIR. Usually 288 | `configure' can determine that directory automatically. 289 | 290 | `--prefix=DIR' 291 | Use DIR as the installation prefix. *Note Installation Names:: 292 | for more details, including other options available for fine-tuning 293 | the installation locations. 294 | 295 | `--no-create' 296 | `-n' 297 | Run the configure checks, but stop before creating any output 298 | files. 299 | 300 | `configure' also accepts some other, not widely useful, options. Run 301 | `configure --help' for more details. 302 | 303 | -------------------------------------------------------------------------------- /libsuinput/Makefile.am: -------------------------------------------------------------------------------- 1 | # ACLOCAL_AMFLAGS = -I m4 2 | SUBDIRS = src 3 | -------------------------------------------------------------------------------- /libsuinput/NEWS: -------------------------------------------------------------------------------- 1 | ==================================================== 2 | Libsuinput NEWS -- history of user-visible changes 3 | ==================================================== 4 | 5 | Release x.y.z 6 | ============= 7 | 8 | - Link against libudev.so.1 9 | - Update libudev.h to match with libudev.so.1 from systemd-215 10 | 11 | Release 0.6.1 12 | ============= 13 | 14 | - Compilation improvements (thanks to Eric Mikula and Vincent Bernat) 15 | - Give credit to all AUTHORS 16 | 17 | Release 0.6.0 18 | ============= 19 | 20 | - API changes: 21 | 22 | - add new function `suinput_emit_click()`. 23 | - add new function `suinput_emit_combo()`. 24 | 25 | - SO-version: 5.0.1 26 | 27 | - Re-distribute libudev.h 28 | 29 | Release 0.5 30 | =========== 31 | 32 | - Use GNU Autotools as a build system. 33 | 34 | - API change: `suinput_set_capabilites()` is replaced by 35 | `suinput_enable_event()`. 36 | 37 | - API change: `suinput_write()` renamed to `suinput_emit()`. 38 | 39 | - API change: removed `suinput_get_uinput_path()`. 40 | 41 | - SO-version: 4 42 | 43 | Release 0.4 44 | =========== 45 | 46 | - Licensing changed from LGPLv3+ to GPLv3+. 47 | 48 | - Usage examples are now included. 49 | 50 | Release 0.3 51 | =========== 52 | 53 | - More generic interface that is "compatible" with standard uinput. 54 | 55 | - Functions operating on an uinput file descriptor. 56 | -------------------------------------------------------------------------------- /libsuinput/README: -------------------------------------------------------------------------------- 1 | ============ 2 | Libsuinput 3 | ============ 4 | 5 | Uinput is Linux kernel module which allows attaching userspace device 6 | drivers into the Linux kernel. However, its ioctl-interface is pretty 7 | low level from an application developer's perspective. This library 8 | provides a set of helper functions for making the usage of uinput 9 | easier. Libsuinput can be considered thin, because it operates on the 10 | same file descriptors as traditional ioctl commands. 11 | 12 | Author: Tuomas Räsänen 13 | Homepage: 14 | 15 | How to install 16 | ============== 17 | 18 | Just run the following commands: 19 | 20 | ./configure && make && make install 21 | 22 | It installs the library to /usr/local/lib and header files to 23 | /usr/local/include. See INSTALL for details. 24 | 25 | How to report bugs 26 | ================== 27 | 28 | The bug database is hosted in GitHub. If you have found a bug or have an 29 | improvement idea you want to share, please report it at 30 | . However, to avoid 31 | duplicate bug reports, before reporting, please check if similar or identical 32 | bug has already been reported. If so, you can still subscribe to the existing 33 | bug to track its progress. 34 | 35 | How to contribute 36 | ================= 37 | 38 | In addition to reporting bugs and improvement suggestions, you are encouraged to 39 | contribute bug-fixes or features. Source code is maintained in Git and the main 40 | repository is hosted at GitHub, 41 | . The preferred way to contribute 42 | code is to clone the main Git repository and send a pull-request. Good old 43 | patches via email are also accepted. 44 | 45 | How to copy 46 | =========== 47 | 48 | Libsuinput is free (libre) software and licensed under the terms of 49 | GNU Public License version 3 or later. In short, it means that you are 50 | free to copy, modify and redistribute this software as long as you 51 | place the derivative work under a compatible license. See COPYING for 52 | details. 53 | -------------------------------------------------------------------------------- /libsuinput/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | autoreconf --install --force --symlink 4 | -------------------------------------------------------------------------------- /libsuinput/configure.ac: -------------------------------------------------------------------------------- 1 | AC_INIT([libsuinput], 2 | [0.6.1], 3 | [https://github.com/tuomasjjrasanen/libsuinput/issues], 4 | [libsuinput], 5 | [http://tjjr.fi/sw/libsuinput/]) 6 | AC_CONFIG_AUX_DIR([build-aux]) 7 | AM_INIT_AUTOMAKE([-Wall -Werror foreign]) 8 | AM_PROG_AR 9 | AC_PROG_LIBTOOL 10 | AC_PROG_CC 11 | AC_CONFIG_MACRO_DIR([m4]) 12 | AC_CONFIG_FILES([ 13 | Makefile 14 | src/Makefile 15 | src/libsuinput.pc 16 | ]) 17 | AC_OUTPUT 18 | -------------------------------------------------------------------------------- /libsuinput/examples/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -Wextra -Werror -pedantic 2 | CFLAGS_ALL = $(CFLAGS) 3 | 4 | LDFLAGS = 5 | LDFLAGS_ALL = $(LDFLAGS) -lsuinput 6 | 7 | CPPFLAGS = 8 | CPPFLAGS_ALL = $(CPPFLAGS) 9 | 10 | PROGRAMS = keyboard mouse 11 | 12 | .PHONY: all clean 13 | 14 | all: $(PROGRAMS) 15 | 16 | %.o : %.c 17 | $(CC) $(CPPFLAGS_ALL) $(CFLAGS_ALL) -c -o $@ $< 18 | 19 | $(PROGRAMS) : % : %.o 20 | $(CC) $(LDFLAGS_ALL) $(CFLAGS_ALL) -o $@ $< 21 | 22 | clean: 23 | rm -f $(PROGRAMS) 24 | rm -f *.o 25 | -------------------------------------------------------------------------------- /libsuinput/examples/keyboard.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | int main(void) 9 | { 10 | int i; 11 | int uinput_fd; 12 | int keys[] = {KEY_E, KEY_H, KEY_L, KEY_O}; 13 | struct uinput_user_dev user_dev; 14 | 15 | memset(&user_dev, 0, sizeof(struct uinput_user_dev)); 16 | strcpy(user_dev.name, "libsuinput-example-keyboard"); 17 | 18 | uinput_fd = suinput_open(); 19 | 20 | if (uinput_fd == -1) 21 | err(1, "suinput_open"); 22 | 23 | /* Error handling is omitted to keep code as readible as possible. */ 24 | 25 | for (i = 0; i < 4; ++i) { 26 | suinput_enable_event(uinput_fd, EV_KEY, keys[i]); 27 | } 28 | 29 | suinput_create(uinput_fd, &user_dev); 30 | sleep(1); 31 | 32 | suinput_emit_click(uinput_fd, KEY_H); 33 | suinput_syn(uinput_fd); 34 | sleep(1); 35 | 36 | suinput_emit_click(uinput_fd, KEY_E); 37 | suinput_syn(uinput_fd); 38 | sleep(1); 39 | 40 | suinput_emit_click(uinput_fd, KEY_L); 41 | suinput_syn(uinput_fd); 42 | sleep(1); 43 | 44 | suinput_emit_click(uinput_fd, KEY_L); 45 | suinput_syn(uinput_fd); 46 | sleep(1); 47 | 48 | suinput_emit_click(uinput_fd, KEY_O); 49 | suinput_syn(uinput_fd); 50 | sleep(1); 51 | 52 | suinput_destroy(uinput_fd); 53 | 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /libsuinput/examples/mouse.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | int main(void) 10 | { 11 | int uinput_fd; 12 | int btns[] = {BTN_LEFT, BTN_RIGHT, BTN_MIDDLE}; 13 | int rel_axes[] = {REL_X, REL_Y, REL_WHEEL}; 14 | struct uinput_user_dev user_dev; 15 | int i; 16 | 17 | memset(&user_dev, 0, sizeof(struct uinput_user_dev)); 18 | strcpy(user_dev.name, "libsuinput-example-mouse"); 19 | 20 | uinput_fd = suinput_open(); 21 | 22 | if (uinput_fd == -1) 23 | err(1, "suinput_open"); 24 | 25 | /* Error handling is omitted to keep code as readible as possible. */ 26 | 27 | for (i = 0; i < 3; ++i) { 28 | suinput_enable_event(uinput_fd, EV_KEY, btns[i]); 29 | } 30 | 31 | for (i = 0; i < 3; ++i) { 32 | suinput_enable_event(uinput_fd, EV_REL, rel_axes[i]); 33 | } 34 | 35 | suinput_create(uinput_fd, &user_dev); 36 | 37 | /* Move pointer 20 * 5 units towards bottom-right. */ 38 | for (i = 0; i < 20; ++i) { 39 | struct timespec sleeptime = {0, 50000000}; 40 | suinput_emit(uinput_fd, EV_REL, REL_X, 5); 41 | suinput_emit(uinput_fd, EV_REL, REL_Y, 5); 42 | suinput_syn(uinput_fd); 43 | 44 | nanosleep(&sleeptime, NULL); 45 | } 46 | 47 | suinput_emit_click(uinput_fd, BTN_LEFT); 48 | 49 | suinput_destroy(uinput_fd); 50 | 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /libsuinput/src/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -Wall -Werror -Wextra -pedantic -std=gnu99 2 | lib_LTLIBRARIES = libsuinput.la 3 | libsuinput_la_SOURCES = suinput.c 4 | libsuinput_la_LDFLAGS = -l:libudev.so.1 -version-info 5:0:1 5 | include_HEADERS = suinput.h 6 | noinst_HEADERS = libudev.h 7 | pkgconfigdir = $(libdir)/pkgconfig 8 | pkgconfig_DATA = libsuinput.pc 9 | -------------------------------------------------------------------------------- /libsuinput/src/libsuinput.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: @PACKAGE_NAME@ 7 | Description: Thin userspace library on top of Linux uinput kernel module 8 | Version: @VERSION@ 9 | URL: @PACKAGE_URL@ 10 | Libs: -L${libdir} -lsuinput 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /libsuinput/src/libudev.h: -------------------------------------------------------------------------------- 1 | /*** 2 | This file is part of systemd. 3 | 4 | Copyright 2008-2012 Kay Sievers 5 | 6 | systemd is free software; you can redistribute it and/or modify it 7 | under the terms of the GNU Lesser General Public License as published by 8 | the Free Software Foundation; either version 2.1 of the License, or 9 | (at your option) any later version. 10 | 11 | systemd is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | You should have received a copy of the GNU Lesser General Public License 17 | along with systemd; If not, see . 18 | ***/ 19 | 20 | #ifndef _LIBUDEV_H_ 21 | #define _LIBUDEV_H_ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* 32 | * udev - library context 33 | * 34 | * reads the udev config and system environment 35 | * allows custom logging 36 | */ 37 | struct udev; 38 | struct udev *udev_ref(struct udev *udev); 39 | struct udev *udev_unref(struct udev *udev); 40 | struct udev *udev_new(void); 41 | void udev_set_log_fn(struct udev *udev, 42 | void (*log_fn)(struct udev *udev, 43 | int priority, const char *file, int line, const char *fn, 44 | const char *format, va_list args)); 45 | int udev_get_log_priority(struct udev *udev); 46 | void udev_set_log_priority(struct udev *udev, int priority); 47 | void *udev_get_userdata(struct udev *udev); 48 | void udev_set_userdata(struct udev *udev, void *userdata); 49 | 50 | /* 51 | * udev_list 52 | * 53 | * access to libudev generated lists 54 | */ 55 | struct udev_list_entry; 56 | struct udev_list_entry *udev_list_entry_get_next(struct udev_list_entry *list_entry); 57 | struct udev_list_entry *udev_list_entry_get_by_name(struct udev_list_entry *list_entry, const char *name); 58 | const char *udev_list_entry_get_name(struct udev_list_entry *list_entry); 59 | const char *udev_list_entry_get_value(struct udev_list_entry *list_entry); 60 | /** 61 | * udev_list_entry_foreach: 62 | * @list_entry: entry to store the current position 63 | * @first_entry: first entry to start with 64 | * 65 | * Helper to iterate over all entries of a list. 66 | */ 67 | #define udev_list_entry_foreach(list_entry, first_entry) \ 68 | for (list_entry = first_entry; \ 69 | list_entry != NULL; \ 70 | list_entry = udev_list_entry_get_next(list_entry)) 71 | 72 | /* 73 | * udev_device 74 | * 75 | * access to sysfs/kernel devices 76 | */ 77 | struct udev_device; 78 | struct udev_device *udev_device_ref(struct udev_device *udev_device); 79 | struct udev_device *udev_device_unref(struct udev_device *udev_device); 80 | struct udev *udev_device_get_udev(struct udev_device *udev_device); 81 | struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath); 82 | struct udev_device *udev_device_new_from_devnum(struct udev *udev, char type, dev_t devnum); 83 | struct udev_device *udev_device_new_from_subsystem_sysname(struct udev *udev, const char *subsystem, const char *sysname); 84 | struct udev_device *udev_device_new_from_device_id(struct udev *udev, const char *id); 85 | struct udev_device *udev_device_new_from_environment(struct udev *udev); 86 | /* udev_device_get_parent_*() does not take a reference on the returned device, it is automatically unref'd with the parent */ 87 | struct udev_device *udev_device_get_parent(struct udev_device *udev_device); 88 | struct udev_device *udev_device_get_parent_with_subsystem_devtype(struct udev_device *udev_device, 89 | const char *subsystem, const char *devtype); 90 | /* retrieve device properties */ 91 | const char *udev_device_get_devpath(struct udev_device *udev_device); 92 | const char *udev_device_get_subsystem(struct udev_device *udev_device); 93 | const char *udev_device_get_devtype(struct udev_device *udev_device); 94 | const char *udev_device_get_syspath(struct udev_device *udev_device); 95 | const char *udev_device_get_sysname(struct udev_device *udev_device); 96 | const char *udev_device_get_sysnum(struct udev_device *udev_device); 97 | const char *udev_device_get_devnode(struct udev_device *udev_device); 98 | int udev_device_get_is_initialized(struct udev_device *udev_device); 99 | struct udev_list_entry *udev_device_get_devlinks_list_entry(struct udev_device *udev_device); 100 | struct udev_list_entry *udev_device_get_properties_list_entry(struct udev_device *udev_device); 101 | struct udev_list_entry *udev_device_get_tags_list_entry(struct udev_device *udev_device); 102 | struct udev_list_entry *udev_device_get_sysattr_list_entry(struct udev_device *udev_device); 103 | const char *udev_device_get_property_value(struct udev_device *udev_device, const char *key); 104 | const char *udev_device_get_driver(struct udev_device *udev_device); 105 | dev_t udev_device_get_devnum(struct udev_device *udev_device); 106 | const char *udev_device_get_action(struct udev_device *udev_device); 107 | unsigned long long int udev_device_get_seqnum(struct udev_device *udev_device); 108 | unsigned long long int udev_device_get_usec_since_initialized(struct udev_device *udev_device); 109 | const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const char *sysattr); 110 | int udev_device_set_sysattr_value(struct udev_device *udev_device, const char *sysattr, char *value); 111 | int udev_device_has_tag(struct udev_device *udev_device, const char *tag); 112 | 113 | /* 114 | * udev_monitor 115 | * 116 | * access to kernel uevents and udev events 117 | */ 118 | struct udev_monitor; 119 | struct udev_monitor *udev_monitor_ref(struct udev_monitor *udev_monitor); 120 | struct udev_monitor *udev_monitor_unref(struct udev_monitor *udev_monitor); 121 | struct udev *udev_monitor_get_udev(struct udev_monitor *udev_monitor); 122 | /* kernel and udev generated events over netlink */ 123 | struct udev_monitor *udev_monitor_new_from_netlink(struct udev *udev, const char *name); 124 | /* bind socket */ 125 | int udev_monitor_enable_receiving(struct udev_monitor *udev_monitor); 126 | int udev_monitor_set_receive_buffer_size(struct udev_monitor *udev_monitor, int size); 127 | int udev_monitor_get_fd(struct udev_monitor *udev_monitor); 128 | struct udev_device *udev_monitor_receive_device(struct udev_monitor *udev_monitor); 129 | /* in-kernel socket filters to select messages that get delivered to a listener */ 130 | int udev_monitor_filter_add_match_subsystem_devtype(struct udev_monitor *udev_monitor, 131 | const char *subsystem, const char *devtype); 132 | int udev_monitor_filter_add_match_tag(struct udev_monitor *udev_monitor, const char *tag); 133 | int udev_monitor_filter_update(struct udev_monitor *udev_monitor); 134 | int udev_monitor_filter_remove(struct udev_monitor *udev_monitor); 135 | 136 | /* 137 | * udev_enumerate 138 | * 139 | * search sysfs for specific devices and provide a sorted list 140 | */ 141 | struct udev_enumerate; 142 | struct udev_enumerate *udev_enumerate_ref(struct udev_enumerate *udev_enumerate); 143 | struct udev_enumerate *udev_enumerate_unref(struct udev_enumerate *udev_enumerate); 144 | struct udev *udev_enumerate_get_udev(struct udev_enumerate *udev_enumerate); 145 | struct udev_enumerate *udev_enumerate_new(struct udev *udev); 146 | /* device properties filter */ 147 | int udev_enumerate_add_match_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem); 148 | int udev_enumerate_add_nomatch_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem); 149 | int udev_enumerate_add_match_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value); 150 | int udev_enumerate_add_nomatch_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value); 151 | int udev_enumerate_add_match_property(struct udev_enumerate *udev_enumerate, const char *property, const char *value); 152 | int udev_enumerate_add_match_sysname(struct udev_enumerate *udev_enumerate, const char *sysname); 153 | int udev_enumerate_add_match_tag(struct udev_enumerate *udev_enumerate, const char *tag); 154 | int udev_enumerate_add_match_parent(struct udev_enumerate *udev_enumerate, struct udev_device *parent); 155 | int udev_enumerate_add_match_is_initialized(struct udev_enumerate *udev_enumerate); 156 | int udev_enumerate_add_syspath(struct udev_enumerate *udev_enumerate, const char *syspath); 157 | /* run enumeration with active filters */ 158 | int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate); 159 | int udev_enumerate_scan_subsystems(struct udev_enumerate *udev_enumerate); 160 | /* return device list */ 161 | struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enumerate *udev_enumerate); 162 | 163 | /* 164 | * udev_queue 165 | * 166 | * access to the currently running udev events 167 | */ 168 | struct udev_queue; 169 | struct udev_queue *udev_queue_ref(struct udev_queue *udev_queue); 170 | struct udev_queue *udev_queue_unref(struct udev_queue *udev_queue); 171 | struct udev *udev_queue_get_udev(struct udev_queue *udev_queue); 172 | struct udev_queue *udev_queue_new(struct udev *udev); 173 | unsigned long long int udev_queue_get_kernel_seqnum(struct udev_queue *udev_queue) __attribute__ ((deprecated)); 174 | unsigned long long int udev_queue_get_udev_seqnum(struct udev_queue *udev_queue) __attribute__ ((deprecated)); 175 | int udev_queue_get_udev_is_active(struct udev_queue *udev_queue); 176 | int udev_queue_get_queue_is_empty(struct udev_queue *udev_queue); 177 | int udev_queue_get_seqnum_is_finished(struct udev_queue *udev_queue, unsigned long long int seqnum) __attribute__ ((deprecated)); 178 | int udev_queue_get_seqnum_sequence_is_finished(struct udev_queue *udev_queue, 179 | unsigned long long int start, unsigned long long int end) __attribute__ ((deprecated)); 180 | int udev_queue_get_fd(struct udev_queue *udev_queue); 181 | int udev_queue_flush(struct udev_queue *udev_queue); 182 | struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_queue *udev_queue) __attribute__ ((deprecated)); 183 | 184 | /* 185 | * udev_hwdb 186 | * 187 | * access to the static hardware properties database 188 | */ 189 | struct udev_hwdb; 190 | struct udev_hwdb *udev_hwdb_new(struct udev *udev); 191 | struct udev_hwdb *udev_hwdb_ref(struct udev_hwdb *hwdb); 192 | struct udev_hwdb *udev_hwdb_unref(struct udev_hwdb *hwdb); 193 | struct udev_list_entry *udev_hwdb_get_properties_list_entry(struct udev_hwdb *hwdb, const char *modalias, unsigned int flags); 194 | 195 | /* 196 | * udev_util 197 | * 198 | * udev specific utilities 199 | */ 200 | int udev_util_encode_string(const char *str, char *str_enc, size_t len); 201 | 202 | 203 | #ifdef __cplusplus 204 | } /* extern "C" */ 205 | #endif 206 | 207 | #endif 208 | -------------------------------------------------------------------------------- /libsuinput/src/suinput.c: -------------------------------------------------------------------------------- 1 | /* 2 | libsuinput - thin userspace library on top of Linux uinput kernel module 3 | Copyright (C) 2013 Tuomas Räsänen 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | #include "libudev.h" 28 | 29 | #include "suinput.h" 30 | 31 | int suinput_write_event(int uinput_fd, const struct input_event *event_p) 32 | { 33 | ssize_t bytes; 34 | 35 | bytes = write(uinput_fd, event_p, sizeof(struct input_event)); 36 | if (bytes != sizeof(struct input_event)) { 37 | return -1; 38 | } 39 | return 0; 40 | } 41 | 42 | int suinput_emit(int uinput_fd, uint16_t ev_type, uint16_t ev_code, 43 | int32_t ev_value) 44 | { 45 | struct input_event event; 46 | 47 | memset(&event, 0, sizeof(event)); 48 | event.type = ev_type; 49 | event.code = ev_code; 50 | event.value = ev_value; 51 | 52 | /* attempt to deal with 64-bit time keeping on recent 32-bit systems */ 53 | #if (__BITS_PER_LONG != 32 || !defined(__USE_TIME_BITS64)) 54 | gettimeofday(&event.time, 0); 55 | #else 56 | struct timeval now; 57 | memset(&now, 0, sizeof(now)); 58 | gettimeofday(&now, 0); 59 | event.input_event_sec = now.tv_sec; 60 | event.input_event_usec = now.tv_usec; 61 | #endif 62 | return suinput_write_event(uinput_fd, &event); 63 | } 64 | 65 | int suinput_emit_click(const int uinput_fd, const uint16_t key_code) 66 | { 67 | if (suinput_emit(uinput_fd, EV_KEY, key_code, 1) == -1) 68 | return -1; 69 | return suinput_emit(uinput_fd, EV_KEY, key_code, 0); 70 | } 71 | 72 | int suinput_emit_combo(const int uinput_fd, const uint16_t *const key_codes, 73 | const size_t len) 74 | { 75 | int retval = 0; 76 | size_t i; 77 | 78 | for (i = 0; i < len; ++i) { 79 | if (suinput_emit(uinput_fd, EV_KEY, key_codes[i], 1) == -1) { 80 | retval = -1; 81 | break; /* The combination or the device is 82 | somehow broken: there's no sense to 83 | press any of the rest of the 84 | keys. It's like pressing physical keys 85 | one by one and then discovering that 86 | one of the keys required for this 87 | combination is missing or broken. */ 88 | } 89 | } 90 | 91 | /* Try to release every pressed key, no matter what. */ 92 | while (i--) { 93 | if (suinput_emit(uinput_fd, EV_KEY, key_codes[i], 0) == -1) { 94 | retval = -1; 95 | } 96 | } 97 | 98 | return retval; 99 | } 100 | 101 | int suinput_syn(int uinput_fd) 102 | { 103 | return suinput_emit(uinput_fd, EV_SYN, SYN_REPORT, 0); 104 | } 105 | 106 | static char *suinput_get_uinput_path(void) 107 | { 108 | struct udev *udev; 109 | struct udev_device *udev_dev; 110 | const char *devnode; 111 | char *retval = NULL; 112 | int orig_errno; 113 | 114 | if ((udev = udev_new()) == NULL) { 115 | return NULL; 116 | } 117 | 118 | udev_dev = udev_device_new_from_subsystem_sysname(udev, "misc", 119 | "uinput"); 120 | if (udev_dev == NULL) { 121 | goto out; 122 | } 123 | 124 | if ((devnode = udev_device_get_devnode(udev_dev)) == NULL) { 125 | goto out; 126 | } 127 | 128 | if ((retval = malloc(strlen(devnode) + 1)) == NULL) { 129 | goto out; 130 | } 131 | 132 | strcpy(retval, devnode); 133 | out: 134 | orig_errno = errno; 135 | udev_device_unref(udev_dev); 136 | udev_unref(udev); 137 | errno = orig_errno; 138 | return retval; 139 | } 140 | 141 | int suinput_open(void) 142 | { 143 | int uinput_fd; 144 | char *uinput_path; 145 | 146 | if ((uinput_path = suinput_get_uinput_path()) == NULL) { 147 | return -1; 148 | } 149 | 150 | uinput_fd = open(uinput_path, O_WRONLY | O_NONBLOCK); 151 | free(uinput_path); 152 | return uinput_fd; 153 | } 154 | 155 | int suinput_create(int uinput_fd, const struct uinput_user_dev *user_dev_p) 156 | { 157 | ssize_t bytes; 158 | 159 | bytes = write(uinput_fd, user_dev_p, sizeof(struct uinput_user_dev)); 160 | if (bytes != sizeof(struct uinput_user_dev)) { 161 | return -1; 162 | } 163 | 164 | if (ioctl(uinput_fd, UI_DEV_CREATE) == -1) { 165 | return -1; 166 | } 167 | 168 | return 0; 169 | } 170 | 171 | int suinput_destroy(int uinput_fd) 172 | { 173 | if (ioctl(uinput_fd, UI_DEV_DESTROY) == -1) { 174 | int original_errno = errno; 175 | close(uinput_fd); 176 | errno = original_errno; 177 | return -1; 178 | } 179 | 180 | return close(uinput_fd); 181 | } 182 | 183 | int suinput_enable_event(int uinput_fd, uint16_t ev_type, uint16_t ev_code) 184 | { 185 | unsigned long io; 186 | 187 | if (ioctl(uinput_fd, UI_SET_EVBIT, ev_type) == -1) { 188 | return -1; 189 | } 190 | 191 | switch (ev_type) { 192 | case EV_KEY: 193 | io = UI_SET_KEYBIT; 194 | break; 195 | case EV_REL: 196 | io = UI_SET_RELBIT; 197 | break; 198 | case EV_ABS: 199 | io = UI_SET_ABSBIT; 200 | break; 201 | case EV_MSC: 202 | io = UI_SET_MSCBIT; 203 | break; 204 | case EV_SW: 205 | io = UI_SET_SWBIT; 206 | break; 207 | case EV_LED: 208 | io = UI_SET_LEDBIT; 209 | break; 210 | case EV_SND: 211 | io = UI_SET_SNDBIT; 212 | break; 213 | case EV_FF: 214 | io = UI_SET_FFBIT; 215 | break; 216 | default: 217 | errno = EINVAL; 218 | return -1; 219 | } 220 | 221 | return ioctl(uinput_fd, io, ev_code); 222 | } 223 | -------------------------------------------------------------------------------- /libsuinput/src/suinput.h: -------------------------------------------------------------------------------- 1 | /* 2 | libsuinput - thin userspace library on top of Linux uinput kernel module 3 | Copyright (C) 2013 Tuomas Räsänen 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | 19 | #ifndef SUINPUT_H 20 | #define SUINPUT_H 21 | 22 | #include 23 | 24 | #include 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | int suinput_open(void); 32 | 33 | int suinput_enable_event(int uinput_fd, uint16_t ev_type, uint16_t ev_code); 34 | 35 | int suinput_create(int uinput_fd, const struct uinput_user_dev *user_dev_p); 36 | 37 | int suinput_write_event(int uinput_fd, const struct input_event *event_p); 38 | 39 | int suinput_emit(int uinput_fd, uint16_t ev_type, uint16_t ev_code, 40 | int32_t ev_value); 41 | 42 | int suinput_emit_click(int uinput_fd, uint16_t key_code); 43 | 44 | int suinput_emit_combo(int uinput_fd, const uint16_t *key_codes, size_t len); 45 | 46 | int suinput_syn(int uinput_fd); 47 | 48 | int suinput_destroy(int uinput_fd); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | 55 | #endif /* SUINPUT_H */ 56 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | name = "python-uinput" 3 | version = "1.0.1" 4 | description = "Pythonic API to Linux uinput kernel module." 5 | authors = [ 6 | {name = "pyinput"}, 7 | ] 8 | license = {text = "GPLv3+"} 9 | readme = "README" 10 | dependencies = [] 11 | requires-python = ">=2.7" 12 | classifiers = [ 13 | "Development Status :: 5 - Production/Stable", 14 | "Intended Audience :: Developers", 15 | "License :: OSI Approved :: GNU General Public License (GPL)", 16 | "Operating System :: POSIX :: Linux", 17 | "Topic :: System :: Operating System Kernels :: Linux", 18 | "Programming Language :: Python", 19 | "Programming Language :: Python :: 2", 20 | "Programming Language :: Python :: 2.7", 21 | "Programming Language :: Python :: 3", 22 | "Programming Language :: Python :: 3.12", 23 | ] 24 | 25 | 26 | [project.urls] 27 | Homepage = "https://github.com/pyinput/python-uinput" 28 | 29 | [tool.poetry.dependencies] 30 | python = ">=2.7" 31 | 32 | 33 | [build-system] 34 | requires = ["setuptools", "wheel"] 35 | build-backend = "setuptools.build_meta" 36 | 37 | [tool.setuptools] 38 | package-dir = { "uinput" = "src" } 39 | -------------------------------------------------------------------------------- /scripts/parse-event-codes: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from __future__ import print_function 4 | from __future__ import with_statement 5 | 6 | import re 7 | import sys 8 | 9 | def parse_event_codes(filepath, ev_type, ev_name): 10 | with open(filepath) as f: 11 | ev_codes = {} 12 | for line in f: 13 | match = re.match(r"^#define (" + ev_name + r"_.*)\t+((?:0x[0-9a-f]+)|(?:\d+))", line) 14 | if match: 15 | ev_id = match.group(1).strip() 16 | ev_code = match.group(2).strip() 17 | ev_codes[ev_id] = ev_code 18 | print("%s = (%s, %s)" % (ev_id, ev_type, ev_code)) 19 | continue 20 | 21 | match = re.match(r"^#define (" + ev_name + r"_.*)\t+((?:[A-Z_]+))", line) 22 | if match: 23 | ev_id = match.group(2).strip() 24 | ev_code = ev_codes[ev_id] 25 | print("%s = (%s, %s)" % (match.group(1).strip(), ev_type, ev_code)) 26 | 27 | 28 | if __name__ == "__main__": 29 | filepath = sys.argv[1] 30 | 31 | parse_event_codes(filepath, "0x01", "KEY") 32 | parse_event_codes(filepath, "0x01", "BTN") 33 | parse_event_codes(filepath, "0x02", "REL") 34 | parse_event_codes(filepath, "0x03", "ABS") 35 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import errno 4 | import subprocess 5 | 6 | try: 7 | from setuptools import setup, Extension 8 | except ImportError: 9 | from distutils.core import setup, Extension 10 | 11 | libudev_so = "libudev.so.1" 12 | 13 | # Because libsuinput can be linked against both libudev.so.0 and 14 | # libudev.so.1, we try to use ldconfig to find out which one is 15 | # available. Preferably libudev.so.1. 16 | try: 17 | ldconfig_output = subprocess.check_output(["ldconfig", "-p"]) 18 | for line in ldconfig_output.splitlines(): 19 | 20 | try: 21 | lib = line.split()[0] 22 | except IndexError: 23 | # An unexpected line, but let's proceed. 24 | continue 25 | 26 | if lib == "libudev.so.0": 27 | libudev_so = lib 28 | # We are quite happy, but let's look if there's something 29 | # better. 30 | 31 | if lib == "libudev.so.1": 32 | libudev_so = lib 33 | break # We are really happy, no reason to look further. 34 | except: 35 | # We don't care if something goes wrong while we scan through all 36 | # the available libraries. The whole scan operation is just 37 | # best-effort, we can always fall back to the default, hard-coded, 38 | # library. 39 | pass 40 | 41 | setup(name='python-uinput', 42 | version='1.0.1', 43 | description='Pythonic API to Linux uinput kernel module.', 44 | author='pyinput', 45 | url='https://github.com/pyinput/python-uinput', 46 | package_dir={'uinput': 'src'}, 47 | packages=['uinput'], 48 | license='GPLv3+', 49 | platforms=['Linux'], 50 | classifiers=[ 51 | "Development Status :: 5 - Production/Stable", 52 | "Intended Audience :: Developers", 53 | "License :: OSI Approved :: GNU General Public License (GPL)", 54 | "Operating System :: POSIX :: Linux", 55 | "Topic :: System :: Operating System Kernels :: Linux", 56 | "Programming Language :: Python", 57 | "Programming Language :: Python :: 2", 58 | "Programming Language :: Python :: 2.7", 59 | "Programming Language :: Python :: 3", 60 | "Programming Language :: Python :: 3.12", 61 | ], 62 | long_description=""" 63 | Python-uinput is Python interface to Linux uinput kernel module which 64 | allows attaching userspace device drivers into kernel. In practice, 65 | Python-uinput makes it dead simple to create virtual joysticks, 66 | keyboards and mice for generating arbitrary input events 67 | programmatically. 68 | """, 69 | ext_modules=[Extension('_libsuinput', ['libsuinput/src/suinput.c'], 70 | libraries=[":%s" % libudev_so])] 71 | ) 72 | -------------------------------------------------------------------------------- /src/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # uinput - Python bindings for Linux uinput system 3 | # Copyright © 2012, 2013, 2014 Tuomas Räsänen 4 | 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | """ 19 | Python bindings to Linux uinput system. 20 | 21 | Usage: 22 | >>> import uinput 23 | >>> events = ( 24 | ... uinput.BTN_JOYSTICK, 25 | ... uinput.ABS_X + (0, 255, 0, 0), 26 | ... uinput.ABS_Y + (0, 255, 0, 0), 27 | ... ) 28 | >>> with uinput.Device(events) as device: 29 | ... device.emit(uinput.ABS_X, 5, syn=False) 30 | ... device.emit(uinput.ABS_Y, 5) 31 | ... device.emit_click(uinput.BTN_JOYSTICK) 32 | """ 33 | 34 | from __future__ import absolute_import 35 | 36 | import ctypes 37 | import errno 38 | import os 39 | try: 40 | import sysconfig 41 | except ImportError: 42 | # python < 3.2 43 | import distutils.sysconfig as sysconfig 44 | 45 | from .ev import * 46 | 47 | _UINPUT_MAX_NAME_SIZE = 80 48 | _ABS_CNT = ABS_MAX[1] + 1 49 | 50 | class _struct_input_id(ctypes.Structure): 51 | _fields_ = [("bustype", ctypes.c_int16), 52 | ("vendor", ctypes.c_int16), 53 | ("product", ctypes.c_int16), 54 | ("version", ctypes.c_int16), 55 | ] 56 | 57 | class _struct_uinput_user_dev(ctypes.Structure): 58 | _fields_ = [("name", ctypes.c_char * _UINPUT_MAX_NAME_SIZE), 59 | ("id", _struct_input_id), 60 | ("ff_effects_max", ctypes.c_int), 61 | ("absmax", ctypes.c_int * _ABS_CNT), 62 | ("absmin", ctypes.c_int * _ABS_CNT), 63 | ("absfuzz", ctypes.c_int * _ABS_CNT), 64 | ("absflat", ctypes.c_int * _ABS_CNT), 65 | ] 66 | 67 | def _open_error_handler(result, fn, args): 68 | if result == -1: 69 | code = ctypes.get_errno() 70 | msg = "Failed to open the uinput device: %s" % os.strerror(code) 71 | if code == errno.ENOENT: 72 | raise OSError(code, "%s. Perhaps load the uinput kernel module first?" % msg) 73 | else: 74 | raise OSError(code, msg) 75 | elif result < -1: 76 | raise RuntimeError("unexpected return value: %s" % result) 77 | return result 78 | 79 | def _error_handler(result, fn, args): 80 | if result == -1: 81 | code = ctypes.get_errno() 82 | raise OSError(code, os.strerror(code)) 83 | elif result < -1: 84 | raise RuntimeError("unexpected return value: %s" % result) 85 | return result 86 | 87 | def fdopen(): 88 | return _libsuinput.suinput_open() 89 | 90 | def get_libsuinput_path(): 91 | repo_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) 92 | # python 2 / 3 compatibility ("SO" is now deprecated) 93 | extension = sysconfig.get_config_var("EXT_SUFFIX") or sysconfig.get_config_var("SO") 94 | path = os.path.join(repo_dir, "_libsuinput" + extension) 95 | return path 96 | 97 | 98 | _libsuinput_path = get_libsuinput_path() 99 | _libsuinput = ctypes.CDLL(_libsuinput_path, use_errno=True) 100 | _libsuinput.suinput_open.errcheck = _open_error_handler 101 | _libsuinput.suinput_enable_event.errcheck = _error_handler 102 | _libsuinput.suinput_create.errcheck = _error_handler 103 | _libsuinput.suinput_write_event.errcheck = _error_handler 104 | _libsuinput.suinput_emit.errcheck = _error_handler 105 | _libsuinput.suinput_emit_click.errcheck = _error_handler 106 | _libsuinput.suinput_emit_combo.errcheck = _error_handler 107 | _libsuinput.suinput_syn.errcheck = _error_handler 108 | _libsuinput.suinput_destroy.errcheck = _error_handler 109 | 110 | _CHAR_MAP = { 111 | "a": KEY_A, 112 | "b": KEY_B, 113 | "c": KEY_C, 114 | "d": KEY_D, 115 | "e": KEY_E, 116 | "f": KEY_F, 117 | "g": KEY_G, 118 | "h": KEY_H, 119 | "i": KEY_I, 120 | "j": KEY_J, 121 | "k": KEY_K, 122 | "l": KEY_L, 123 | "m": KEY_M, 124 | "n": KEY_N, 125 | "o": KEY_O, 126 | "p": KEY_P, 127 | "q": KEY_Q, 128 | "r": KEY_R, 129 | "s": KEY_S, 130 | "t": KEY_T, 131 | "u": KEY_U, 132 | "v": KEY_V, 133 | "w": KEY_W, 134 | "x": KEY_X, 135 | "y": KEY_Y, 136 | "z": KEY_Z, 137 | "1": KEY_1, 138 | "2": KEY_2, 139 | "3": KEY_3, 140 | "4": KEY_4, 141 | "5": KEY_5, 142 | "6": KEY_6, 143 | "7": KEY_7, 144 | "8": KEY_8, 145 | "9": KEY_9, 146 | "0": KEY_0, 147 | "\t": KEY_TAB, 148 | "\n": KEY_ENTER, 149 | " ": KEY_SPACE, 150 | ".": KEY_DOT, 151 | ",": KEY_COMMA, 152 | "/": KEY_SLASH, 153 | "\\": KEY_BACKSLASH, 154 | } 155 | 156 | def _chars_to_events(chars): 157 | events = [] 158 | for char in chars: 159 | events.append(_CHAR_MAP.get(char)) 160 | return events 161 | 162 | class Device(object): 163 | 164 | """Device handle. 165 | 166 | `events` - a sequence of event capability descriptors 167 | 168 | `name` - name displayed in /proc/bus/input/devices 169 | 170 | `bustype` - bus type identifier, see linux/input.h 171 | 172 | `vendor` - vendor identifier 173 | 174 | `product` - product identifier 175 | 176 | `version` - version identifier 177 | """ 178 | 179 | def __init__(self, events, name="python-uinput", 180 | bustype=0, vendor=0, product=0, version=0, fd=None): 181 | self.__events = events 182 | self.__uinput_fd = -1 183 | self.__name = name.encode() 184 | 185 | user_dev = _struct_uinput_user_dev(self.__name) 186 | user_dev.id.bustype = bustype 187 | user_dev.id.vendor = vendor 188 | user_dev.id.product = product 189 | user_dev.id.version = version 190 | self.__uinput_fd = fd or fdopen() 191 | for ev_spec in self.__events: 192 | ev_type, ev_code = ev_spec[:2] 193 | _libsuinput.suinput_enable_event(self.__uinput_fd, ev_type, ev_code) 194 | if len(ev_spec) > 2: 195 | absmin, absmax, absfuzz, absflat = ev_spec[2:] 196 | user_dev.absmin[ev_code] = absmin 197 | user_dev.absmax[ev_code] = absmax 198 | user_dev.absfuzz[ev_code] = absfuzz 199 | user_dev.absflat[ev_code] = absflat 200 | 201 | _libsuinput.suinput_create(self.__uinput_fd, ctypes.pointer(user_dev)) 202 | 203 | def syn(self): 204 | """Fire all emitted events. 205 | 206 | All emitted events will be placed in a certain kind of event 207 | queue. Queued events will be fired when this method is 208 | called. This makes it possible to emit "atomic" events. For 209 | example sending REL_X and REL_Y atomically requires to emit 210 | first event without syn and the second with syn:: 211 | 212 | d.emit(uinput.REL_X, 1, syn=False) 213 | d.emit(uinput.REL_Y, 1) 214 | 215 | The call above appears as a single (+1, +1) event. 216 | """ 217 | 218 | _libsuinput.suinput_syn(self.__uinput_fd) 219 | 220 | def emit(self, event, value, syn=True): 221 | """Emit event. 222 | 223 | `event` - event identifier, for example uinput.REL_X 224 | 225 | `value` - value of the event 226 | KEY/BTN : 1 (key-press) or 0 (key-release) 227 | REL : integer value of the relative change 228 | ABS : integer value in the range of min and max values 229 | 230 | `syn` - If True, Device.syn(self) will be called before return. 231 | """ 232 | 233 | ev_type, ev_code = event 234 | _libsuinput.suinput_emit(self.__uinput_fd, ev_type, ev_code, value) 235 | if syn: 236 | self.syn() 237 | 238 | def emit_click(self, event, syn=True): 239 | """Emit click event. Only KEY and BTN events are accepted, 240 | otherwise ValueError is raised. 241 | 242 | `event` - event identifier, for example uinput.KEY_A 243 | 244 | `syn` - if True, Device.syn(self) is called before returning. 245 | """ 246 | ev_type, ev_code = event 247 | if ev_type != 0x01: 248 | raise ValueError("event must be of type KEY or BTN") 249 | _libsuinput.suinput_emit_click(self.__uinput_fd, ev_code) 250 | if syn: 251 | self.syn() 252 | 253 | def emit_combo(self, events, syn=True): 254 | """Emit key combination. Only KEY and BTN events are accepted, 255 | otherwise ValueError is raised. 256 | 257 | `events` - a sequence of event identifiers, for example 258 | (uinput.KEY_LEFTCTRL, uinput.KEY_LEFTALT, uinput.KEY_DELETE). 259 | 260 | `syn` if True, Device.syn(self) is called before returning. 261 | """ 262 | ev_types, ev_codes = zip(*events) 263 | if not all([ev_type == 0x01 for ev_type in ev_types]): 264 | raise ValueError("all events must be of type KEY or BTN") 265 | 266 | arrtype = ctypes.c_uint16 * len(events) 267 | _libsuinput.suinput_emit_combo(self.__uinput_fd, arrtype(*ev_codes), len(events)) 268 | if syn: 269 | self.syn() 270 | 271 | def destroy(self): 272 | """Destroy the device. This method destroys the device file and closes the 273 | underlying file descriptor. This method must be called exactly once for 274 | each created device. 275 | 276 | Alternatively, use ``with``-statement for example as follows: 277 | >>> import uinput 278 | >>> with uinput.Device([uinput.KEY_A]) as device: 279 | ... device.emit_click(uinput.KEY_A) 280 | 281 | This ensures ``Device.destroy()`` is called at the end of the block. 282 | 283 | """ 284 | try: 285 | _libsuinput.suinput_destroy(self.__uinput_fd) 286 | finally: 287 | ## There's probably nothing more we can do. If the suinput_destroy() 288 | ## has failed once, it almost certainly will fail again. Let's just 289 | ## reset the descriptor and give up. 290 | self.__uinput_fd = -1 291 | 292 | def __enter__(self): 293 | return self 294 | 295 | def __exit__(self, *args): 296 | self.destroy() 297 | return False ## Not handling any exceptions. 298 | 299 | def __del__(self): 300 | if self.__uinput_fd >= 0: 301 | self.destroy() 302 | -------------------------------------------------------------------------------- /src/ev.py: -------------------------------------------------------------------------------- 1 | KEY_RESERVED = (0x01, 0) 2 | KEY_ESC = (0x01, 1) 3 | KEY_1 = (0x01, 2) 4 | KEY_2 = (0x01, 3) 5 | KEY_3 = (0x01, 4) 6 | KEY_4 = (0x01, 5) 7 | KEY_5 = (0x01, 6) 8 | KEY_6 = (0x01, 7) 9 | KEY_7 = (0x01, 8) 10 | KEY_8 = (0x01, 9) 11 | KEY_9 = (0x01, 10) 12 | KEY_0 = (0x01, 11) 13 | KEY_MINUS = (0x01, 12) 14 | KEY_EQUAL = (0x01, 13) 15 | KEY_BACKSPACE = (0x01, 14) 16 | KEY_TAB = (0x01, 15) 17 | KEY_Q = (0x01, 16) 18 | KEY_W = (0x01, 17) 19 | KEY_E = (0x01, 18) 20 | KEY_R = (0x01, 19) 21 | KEY_T = (0x01, 20) 22 | KEY_Y = (0x01, 21) 23 | KEY_U = (0x01, 22) 24 | KEY_I = (0x01, 23) 25 | KEY_O = (0x01, 24) 26 | KEY_P = (0x01, 25) 27 | KEY_LEFTBRACE = (0x01, 26) 28 | KEY_RIGHTBRACE = (0x01, 27) 29 | KEY_ENTER = (0x01, 28) 30 | KEY_LEFTCTRL = (0x01, 29) 31 | KEY_A = (0x01, 30) 32 | KEY_S = (0x01, 31) 33 | KEY_D = (0x01, 32) 34 | KEY_F = (0x01, 33) 35 | KEY_G = (0x01, 34) 36 | KEY_H = (0x01, 35) 37 | KEY_J = (0x01, 36) 38 | KEY_K = (0x01, 37) 39 | KEY_L = (0x01, 38) 40 | KEY_SEMICOLON = (0x01, 39) 41 | KEY_APOSTROPHE = (0x01, 40) 42 | KEY_GRAVE = (0x01, 41) 43 | KEY_LEFTSHIFT = (0x01, 42) 44 | KEY_BACKSLASH = (0x01, 43) 45 | KEY_Z = (0x01, 44) 46 | KEY_X = (0x01, 45) 47 | KEY_C = (0x01, 46) 48 | KEY_V = (0x01, 47) 49 | KEY_B = (0x01, 48) 50 | KEY_N = (0x01, 49) 51 | KEY_M = (0x01, 50) 52 | KEY_COMMA = (0x01, 51) 53 | KEY_DOT = (0x01, 52) 54 | KEY_SLASH = (0x01, 53) 55 | KEY_RIGHTSHIFT = (0x01, 54) 56 | KEY_KPASTERISK = (0x01, 55) 57 | KEY_LEFTALT = (0x01, 56) 58 | KEY_SPACE = (0x01, 57) 59 | KEY_CAPSLOCK = (0x01, 58) 60 | KEY_F1 = (0x01, 59) 61 | KEY_F2 = (0x01, 60) 62 | KEY_F3 = (0x01, 61) 63 | KEY_F4 = (0x01, 62) 64 | KEY_F5 = (0x01, 63) 65 | KEY_F6 = (0x01, 64) 66 | KEY_F7 = (0x01, 65) 67 | KEY_F8 = (0x01, 66) 68 | KEY_F9 = (0x01, 67) 69 | KEY_F10 = (0x01, 68) 70 | KEY_NUMLOCK = (0x01, 69) 71 | KEY_SCROLLLOCK = (0x01, 70) 72 | KEY_KP7 = (0x01, 71) 73 | KEY_KP8 = (0x01, 72) 74 | KEY_KP9 = (0x01, 73) 75 | KEY_KPMINUS = (0x01, 74) 76 | KEY_KP4 = (0x01, 75) 77 | KEY_KP5 = (0x01, 76) 78 | KEY_KP6 = (0x01, 77) 79 | KEY_KPPLUS = (0x01, 78) 80 | KEY_KP1 = (0x01, 79) 81 | KEY_KP2 = (0x01, 80) 82 | KEY_KP3 = (0x01, 81) 83 | KEY_KP0 = (0x01, 82) 84 | KEY_KPDOT = (0x01, 83) 85 | KEY_ZENKAKUHANKAKU = (0x01, 85) 86 | KEY_102ND = (0x01, 86) 87 | KEY_F11 = (0x01, 87) 88 | KEY_F12 = (0x01, 88) 89 | KEY_RO = (0x01, 89) 90 | KEY_KATAKANA = (0x01, 90) 91 | KEY_HIRAGANA = (0x01, 91) 92 | KEY_HENKAN = (0x01, 92) 93 | KEY_KATAKANAHIRAGANA = (0x01, 93) 94 | KEY_MUHENKAN = (0x01, 94) 95 | KEY_KPJPCOMMA = (0x01, 95) 96 | KEY_KPENTER = (0x01, 96) 97 | KEY_RIGHTCTRL = (0x01, 97) 98 | KEY_KPSLASH = (0x01, 98) 99 | KEY_SYSRQ = (0x01, 99) 100 | KEY_RIGHTALT = (0x01, 100) 101 | KEY_LINEFEED = (0x01, 101) 102 | KEY_HOME = (0x01, 102) 103 | KEY_UP = (0x01, 103) 104 | KEY_PAGEUP = (0x01, 104) 105 | KEY_LEFT = (0x01, 105) 106 | KEY_RIGHT = (0x01, 106) 107 | KEY_END = (0x01, 107) 108 | KEY_DOWN = (0x01, 108) 109 | KEY_PAGEDOWN = (0x01, 109) 110 | KEY_INSERT = (0x01, 110) 111 | KEY_DELETE = (0x01, 111) 112 | KEY_MACRO = (0x01, 112) 113 | KEY_MUTE = (0x01, 113) 114 | KEY_VOLUMEDOWN = (0x01, 114) 115 | KEY_VOLUMEUP = (0x01, 115) 116 | KEY_POWER = (0x01, 116) 117 | KEY_KPEQUAL = (0x01, 117) 118 | KEY_KPPLUSMINUS = (0x01, 118) 119 | KEY_PAUSE = (0x01, 119) 120 | KEY_SCALE = (0x01, 120) 121 | KEY_KPCOMMA = (0x01, 121) 122 | KEY_HANGEUL = (0x01, 122) 123 | KEY_HANGUEL = (0x01, 122) 124 | KEY_HANJA = (0x01, 123) 125 | KEY_YEN = (0x01, 124) 126 | KEY_LEFTMETA = (0x01, 125) 127 | KEY_RIGHTMETA = (0x01, 126) 128 | KEY_COMPOSE = (0x01, 127) 129 | KEY_STOP = (0x01, 128) 130 | KEY_AGAIN = (0x01, 129) 131 | KEY_PROPS = (0x01, 130) 132 | KEY_UNDO = (0x01, 131) 133 | KEY_FRONT = (0x01, 132) 134 | KEY_COPY = (0x01, 133) 135 | KEY_OPEN = (0x01, 134) 136 | KEY_PASTE = (0x01, 135) 137 | KEY_FIND = (0x01, 136) 138 | KEY_CUT = (0x01, 137) 139 | KEY_HELP = (0x01, 138) 140 | KEY_MENU = (0x01, 139) 141 | KEY_CALC = (0x01, 140) 142 | KEY_SETUP = (0x01, 141) 143 | KEY_SLEEP = (0x01, 142) 144 | KEY_WAKEUP = (0x01, 143) 145 | KEY_FILE = (0x01, 144) 146 | KEY_SENDFILE = (0x01, 145) 147 | KEY_DELETEFILE = (0x01, 146) 148 | KEY_XFER = (0x01, 147) 149 | KEY_PROG1 = (0x01, 148) 150 | KEY_PROG2 = (0x01, 149) 151 | KEY_WWW = (0x01, 150) 152 | KEY_MSDOS = (0x01, 151) 153 | KEY_COFFEE = (0x01, 152) 154 | KEY_SCREENLOCK = (0x01, 152) 155 | KEY_ROTATE_DISPLAY = (0x01, 153) 156 | KEY_DIRECTION = (0x01, 153) 157 | KEY_CYCLEWINDOWS = (0x01, 154) 158 | KEY_MAIL = (0x01, 155) 159 | KEY_BOOKMARKS = (0x01, 156) 160 | KEY_COMPUTER = (0x01, 157) 161 | KEY_BACK = (0x01, 158) 162 | KEY_FORWARD = (0x01, 159) 163 | KEY_CLOSECD = (0x01, 160) 164 | KEY_EJECTCD = (0x01, 161) 165 | KEY_EJECTCLOSECD = (0x01, 162) 166 | KEY_NEXTSONG = (0x01, 163) 167 | KEY_PLAYPAUSE = (0x01, 164) 168 | KEY_PREVIOUSSONG = (0x01, 165) 169 | KEY_STOPCD = (0x01, 166) 170 | KEY_RECORD = (0x01, 167) 171 | KEY_REWIND = (0x01, 168) 172 | KEY_PHONE = (0x01, 169) 173 | KEY_ISO = (0x01, 170) 174 | KEY_CONFIG = (0x01, 171) 175 | KEY_HOMEPAGE = (0x01, 172) 176 | KEY_REFRESH = (0x01, 173) 177 | KEY_EXIT = (0x01, 174) 178 | KEY_MOVE = (0x01, 175) 179 | KEY_EDIT = (0x01, 176) 180 | KEY_SCROLLUP = (0x01, 177) 181 | KEY_SCROLLDOWN = (0x01, 178) 182 | KEY_KPLEFTPAREN = (0x01, 179) 183 | KEY_KPRIGHTPAREN = (0x01, 180) 184 | KEY_NEW = (0x01, 181) 185 | KEY_REDO = (0x01, 182) 186 | KEY_F13 = (0x01, 183) 187 | KEY_F14 = (0x01, 184) 188 | KEY_F15 = (0x01, 185) 189 | KEY_F16 = (0x01, 186) 190 | KEY_F17 = (0x01, 187) 191 | KEY_F18 = (0x01, 188) 192 | KEY_F19 = (0x01, 189) 193 | KEY_F20 = (0x01, 190) 194 | KEY_F21 = (0x01, 191) 195 | KEY_F22 = (0x01, 192) 196 | KEY_F23 = (0x01, 193) 197 | KEY_F24 = (0x01, 194) 198 | KEY_PLAYCD = (0x01, 200) 199 | KEY_PAUSECD = (0x01, 201) 200 | KEY_PROG3 = (0x01, 202) 201 | KEY_PROG4 = (0x01, 203) 202 | KEY_DASHBOARD = (0x01, 204) 203 | KEY_SUSPEND = (0x01, 205) 204 | KEY_CLOSE = (0x01, 206) 205 | KEY_PLAY = (0x01, 207) 206 | KEY_FASTFORWARD = (0x01, 208) 207 | KEY_BASSBOOST = (0x01, 209) 208 | KEY_PRINT = (0x01, 210) 209 | KEY_HP = (0x01, 211) 210 | KEY_CAMERA = (0x01, 212) 211 | KEY_SOUND = (0x01, 213) 212 | KEY_QUESTION = (0x01, 214) 213 | KEY_EMAIL = (0x01, 215) 214 | KEY_CHAT = (0x01, 216) 215 | KEY_SEARCH = (0x01, 217) 216 | KEY_CONNECT = (0x01, 218) 217 | KEY_FINANCE = (0x01, 219) 218 | KEY_SPORT = (0x01, 220) 219 | KEY_SHOP = (0x01, 221) 220 | KEY_ALTERASE = (0x01, 222) 221 | KEY_CANCEL = (0x01, 223) 222 | KEY_BRIGHTNESSDOWN = (0x01, 224) 223 | KEY_BRIGHTNESSUP = (0x01, 225) 224 | KEY_MEDIA = (0x01, 226) 225 | KEY_SWITCHVIDEOMODE = (0x01, 227) 226 | KEY_KBDILLUMTOGGLE = (0x01, 228) 227 | KEY_KBDILLUMDOWN = (0x01, 229) 228 | KEY_KBDILLUMUP = (0x01, 230) 229 | KEY_SEND = (0x01, 231) 230 | KEY_REPLY = (0x01, 232) 231 | KEY_FORWARDMAIL = (0x01, 233) 232 | KEY_SAVE = (0x01, 234) 233 | KEY_DOCUMENTS = (0x01, 235) 234 | KEY_BATTERY = (0x01, 236) 235 | KEY_BLUETOOTH = (0x01, 237) 236 | KEY_WLAN = (0x01, 238) 237 | KEY_UWB = (0x01, 239) 238 | KEY_UNKNOWN = (0x01, 240) 239 | KEY_VIDEO_NEXT = (0x01, 241) 240 | KEY_VIDEO_PREV = (0x01, 242) 241 | KEY_BRIGHTNESS_CYCLE = (0x01, 243) 242 | KEY_BRIGHTNESS_AUTO = (0x01, 244) 243 | KEY_BRIGHTNESS_ZERO = (0x01, 244) 244 | KEY_DISPLAY_OFF = (0x01, 245) 245 | KEY_WWAN = (0x01, 246) 246 | KEY_WIMAX = (0x01, 246) 247 | KEY_RFKILL = (0x01, 247) 248 | KEY_MICMUTE = (0x01, 248) 249 | KEY_OK = (0x01, 0x160) 250 | KEY_SELECT = (0x01, 0x161) 251 | KEY_GOTO = (0x01, 0x162) 252 | KEY_CLEAR = (0x01, 0x163) 253 | KEY_POWER2 = (0x01, 0x164) 254 | KEY_OPTION = (0x01, 0x165) 255 | KEY_INFO = (0x01, 0x166) 256 | KEY_TIME = (0x01, 0x167) 257 | KEY_VENDOR = (0x01, 0x168) 258 | KEY_ARCHIVE = (0x01, 0x169) 259 | KEY_PROGRAM = (0x01, 0x16a) 260 | KEY_CHANNEL = (0x01, 0x16b) 261 | KEY_FAVORITES = (0x01, 0x16c) 262 | KEY_EPG = (0x01, 0x16d) 263 | KEY_PVR = (0x01, 0x16e) 264 | KEY_MHP = (0x01, 0x16f) 265 | KEY_LANGUAGE = (0x01, 0x170) 266 | KEY_TITLE = (0x01, 0x171) 267 | KEY_SUBTITLE = (0x01, 0x172) 268 | KEY_ANGLE = (0x01, 0x173) 269 | KEY_ZOOM = (0x01, 0x174) 270 | KEY_MODE = (0x01, 0x175) 271 | KEY_KEYBOARD = (0x01, 0x176) 272 | KEY_SCREEN = (0x01, 0x177) 273 | KEY_PC = (0x01, 0x178) 274 | KEY_TV = (0x01, 0x179) 275 | KEY_TV2 = (0x01, 0x17a) 276 | KEY_VCR = (0x01, 0x17b) 277 | KEY_VCR2 = (0x01, 0x17c) 278 | KEY_SAT = (0x01, 0x17d) 279 | KEY_SAT2 = (0x01, 0x17e) 280 | KEY_CD = (0x01, 0x17f) 281 | KEY_TAPE = (0x01, 0x180) 282 | KEY_RADIO = (0x01, 0x181) 283 | KEY_TUNER = (0x01, 0x182) 284 | KEY_PLAYER = (0x01, 0x183) 285 | KEY_TEXT = (0x01, 0x184) 286 | KEY_DVD = (0x01, 0x185) 287 | KEY_AUX = (0x01, 0x186) 288 | KEY_MP3 = (0x01, 0x187) 289 | KEY_AUDIO = (0x01, 0x188) 290 | KEY_VIDEO = (0x01, 0x189) 291 | KEY_DIRECTORY = (0x01, 0x18a) 292 | KEY_LIST = (0x01, 0x18b) 293 | KEY_MEMO = (0x01, 0x18c) 294 | KEY_CALENDAR = (0x01, 0x18d) 295 | KEY_RED = (0x01, 0x18e) 296 | KEY_GREEN = (0x01, 0x18f) 297 | KEY_YELLOW = (0x01, 0x190) 298 | KEY_BLUE = (0x01, 0x191) 299 | KEY_CHANNELUP = (0x01, 0x192) 300 | KEY_CHANNELDOWN = (0x01, 0x193) 301 | KEY_FIRST = (0x01, 0x194) 302 | KEY_LAST = (0x01, 0x195) 303 | KEY_AB = (0x01, 0x196) 304 | KEY_NEXT = (0x01, 0x197) 305 | KEY_RESTART = (0x01, 0x198) 306 | KEY_SLOW = (0x01, 0x199) 307 | KEY_SHUFFLE = (0x01, 0x19a) 308 | KEY_BREAK = (0x01, 0x19b) 309 | KEY_PREVIOUS = (0x01, 0x19c) 310 | KEY_DIGITS = (0x01, 0x19d) 311 | KEY_TEEN = (0x01, 0x19e) 312 | KEY_TWEN = (0x01, 0x19f) 313 | KEY_VIDEOPHONE = (0x01, 0x1a0) 314 | KEY_GAMES = (0x01, 0x1a1) 315 | KEY_ZOOMIN = (0x01, 0x1a2) 316 | KEY_ZOOMOUT = (0x01, 0x1a3) 317 | KEY_ZOOMRESET = (0x01, 0x1a4) 318 | KEY_WORDPROCESSOR = (0x01, 0x1a5) 319 | KEY_EDITOR = (0x01, 0x1a6) 320 | KEY_SPREADSHEET = (0x01, 0x1a7) 321 | KEY_GRAPHICSEDITOR = (0x01, 0x1a8) 322 | KEY_PRESENTATION = (0x01, 0x1a9) 323 | KEY_DATABASE = (0x01, 0x1aa) 324 | KEY_NEWS = (0x01, 0x1ab) 325 | KEY_VOICEMAIL = (0x01, 0x1ac) 326 | KEY_ADDRESSBOOK = (0x01, 0x1ad) 327 | KEY_MESSENGER = (0x01, 0x1ae) 328 | KEY_DISPLAYTOGGLE = (0x01, 0x1af) 329 | KEY_BRIGHTNESS_TOGGLE = (0x01, 0x1af) 330 | KEY_SPELLCHECK = (0x01, 0x1b0) 331 | KEY_LOGOFF = (0x01, 0x1b1) 332 | KEY_DOLLAR = (0x01, 0x1b2) 333 | KEY_EURO = (0x01, 0x1b3) 334 | KEY_FRAMEBACK = (0x01, 0x1b4) 335 | KEY_FRAMEFORWARD = (0x01, 0x1b5) 336 | KEY_CONTEXT_MENU = (0x01, 0x1b6) 337 | KEY_MEDIA_REPEAT = (0x01, 0x1b7) 338 | KEY_10CHANNELSUP = (0x01, 0x1b8) 339 | KEY_10CHANNELSDOWN = (0x01, 0x1b9) 340 | KEY_IMAGES = (0x01, 0x1ba) 341 | KEY_DEL_EOL = (0x01, 0x1c0) 342 | KEY_DEL_EOS = (0x01, 0x1c1) 343 | KEY_INS_LINE = (0x01, 0x1c2) 344 | KEY_DEL_LINE = (0x01, 0x1c3) 345 | KEY_FN = (0x01, 0x1d0) 346 | KEY_FN_ESC = (0x01, 0x1d1) 347 | KEY_FN_F1 = (0x01, 0x1d2) 348 | KEY_FN_F2 = (0x01, 0x1d3) 349 | KEY_FN_F3 = (0x01, 0x1d4) 350 | KEY_FN_F4 = (0x01, 0x1d5) 351 | KEY_FN_F5 = (0x01, 0x1d6) 352 | KEY_FN_F6 = (0x01, 0x1d7) 353 | KEY_FN_F7 = (0x01, 0x1d8) 354 | KEY_FN_F8 = (0x01, 0x1d9) 355 | KEY_FN_F9 = (0x01, 0x1da) 356 | KEY_FN_F10 = (0x01, 0x1db) 357 | KEY_FN_F11 = (0x01, 0x1dc) 358 | KEY_FN_F12 = (0x01, 0x1dd) 359 | KEY_FN_1 = (0x01, 0x1de) 360 | KEY_FN_2 = (0x01, 0x1df) 361 | KEY_FN_D = (0x01, 0x1e0) 362 | KEY_FN_E = (0x01, 0x1e1) 363 | KEY_FN_F = (0x01, 0x1e2) 364 | KEY_FN_S = (0x01, 0x1e3) 365 | KEY_FN_B = (0x01, 0x1e4) 366 | KEY_BRL_DOT1 = (0x01, 0x1f1) 367 | KEY_BRL_DOT2 = (0x01, 0x1f2) 368 | KEY_BRL_DOT3 = (0x01, 0x1f3) 369 | KEY_BRL_DOT4 = (0x01, 0x1f4) 370 | KEY_BRL_DOT5 = (0x01, 0x1f5) 371 | KEY_BRL_DOT6 = (0x01, 0x1f6) 372 | KEY_BRL_DOT7 = (0x01, 0x1f7) 373 | KEY_BRL_DOT8 = (0x01, 0x1f8) 374 | KEY_BRL_DOT9 = (0x01, 0x1f9) 375 | KEY_BRL_DOT10 = (0x01, 0x1fa) 376 | KEY_NUMERIC_0 = (0x01, 0x200) 377 | KEY_NUMERIC_1 = (0x01, 0x201) 378 | KEY_NUMERIC_2 = (0x01, 0x202) 379 | KEY_NUMERIC_3 = (0x01, 0x203) 380 | KEY_NUMERIC_4 = (0x01, 0x204) 381 | KEY_NUMERIC_5 = (0x01, 0x205) 382 | KEY_NUMERIC_6 = (0x01, 0x206) 383 | KEY_NUMERIC_7 = (0x01, 0x207) 384 | KEY_NUMERIC_8 = (0x01, 0x208) 385 | KEY_NUMERIC_9 = (0x01, 0x209) 386 | KEY_NUMERIC_STAR = (0x01, 0x20a) 387 | KEY_NUMERIC_POUND = (0x01, 0x20b) 388 | KEY_NUMERIC_A = (0x01, 0x20c) 389 | KEY_NUMERIC_B = (0x01, 0x20d) 390 | KEY_NUMERIC_C = (0x01, 0x20e) 391 | KEY_NUMERIC_D = (0x01, 0x20f) 392 | KEY_CAMERA_FOCUS = (0x01, 0x210) 393 | KEY_WPS_BUTTON = (0x01, 0x211) 394 | KEY_TOUCHPAD_TOGGLE = (0x01, 0x212) 395 | KEY_TOUCHPAD_ON = (0x01, 0x213) 396 | KEY_TOUCHPAD_OFF = (0x01, 0x214) 397 | KEY_CAMERA_ZOOMIN = (0x01, 0x215) 398 | KEY_CAMERA_ZOOMOUT = (0x01, 0x216) 399 | KEY_CAMERA_UP = (0x01, 0x217) 400 | KEY_CAMERA_DOWN = (0x01, 0x218) 401 | KEY_CAMERA_LEFT = (0x01, 0x219) 402 | KEY_CAMERA_RIGHT = (0x01, 0x21a) 403 | KEY_ATTENDANT_ON = (0x01, 0x21b) 404 | KEY_ATTENDANT_OFF = (0x01, 0x21c) 405 | KEY_ATTENDANT_TOGGLE = (0x01, 0x21d) 406 | KEY_LIGHTS_TOGGLE = (0x01, 0x21e) 407 | KEY_ALS_TOGGLE = (0x01, 0x230) 408 | KEY_BUTTONCONFIG = (0x01, 0x240) 409 | KEY_TASKMANAGER = (0x01, 0x241) 410 | KEY_JOURNAL = (0x01, 0x242) 411 | KEY_CONTROLPANEL = (0x01, 0x243) 412 | KEY_APPSELECT = (0x01, 0x244) 413 | KEY_SCREENSAVER = (0x01, 0x245) 414 | KEY_VOICECOMMAND = (0x01, 0x246) 415 | KEY_BRIGHTNESS_MIN = (0x01, 0x250) 416 | KEY_BRIGHTNESS_MAX = (0x01, 0x251) 417 | KEY_KBDINPUTASSIST_PREV = (0x01, 0x260) 418 | KEY_KBDINPUTASSIST_NEXT = (0x01, 0x261) 419 | KEY_KBDINPUTASSIST_PREVGROUP = (0x01, 0x262) 420 | KEY_KBDINPUTASSIST_NEXTGROUP = (0x01, 0x263) 421 | KEY_KBDINPUTASSIST_ACCEPT = (0x01, 0x264) 422 | KEY_KBDINPUTASSIST_CANCEL = (0x01, 0x265) 423 | KEY_MIN_INTERESTING = (0x01, 113) 424 | KEY_MAX = (0x01, 0x2ff) 425 | BTN_MISC = (0x01, 0x100) 426 | BTN_0 = (0x01, 0x100) 427 | BTN_1 = (0x01, 0x101) 428 | BTN_2 = (0x01, 0x102) 429 | BTN_3 = (0x01, 0x103) 430 | BTN_4 = (0x01, 0x104) 431 | BTN_5 = (0x01, 0x105) 432 | BTN_6 = (0x01, 0x106) 433 | BTN_7 = (0x01, 0x107) 434 | BTN_8 = (0x01, 0x108) 435 | BTN_9 = (0x01, 0x109) 436 | BTN_MOUSE = (0x01, 0x110) 437 | BTN_LEFT = (0x01, 0x110) 438 | BTN_RIGHT = (0x01, 0x111) 439 | BTN_MIDDLE = (0x01, 0x112) 440 | BTN_SIDE = (0x01, 0x113) 441 | BTN_EXTRA = (0x01, 0x114) 442 | BTN_FORWARD = (0x01, 0x115) 443 | BTN_BACK = (0x01, 0x116) 444 | BTN_TASK = (0x01, 0x117) 445 | BTN_JOYSTICK = (0x01, 0x120) 446 | BTN_TRIGGER = (0x01, 0x120) 447 | BTN_THUMB = (0x01, 0x121) 448 | BTN_THUMB2 = (0x01, 0x122) 449 | BTN_TOP = (0x01, 0x123) 450 | BTN_TOP2 = (0x01, 0x124) 451 | BTN_PINKIE = (0x01, 0x125) 452 | BTN_BASE = (0x01, 0x126) 453 | BTN_BASE2 = (0x01, 0x127) 454 | BTN_BASE3 = (0x01, 0x128) 455 | BTN_BASE4 = (0x01, 0x129) 456 | BTN_BASE5 = (0x01, 0x12a) 457 | BTN_BASE6 = (0x01, 0x12b) 458 | BTN_DEAD = (0x01, 0x12f) 459 | BTN_GAMEPAD = (0x01, 0x130) 460 | BTN_SOUTH = (0x01, 0x130) 461 | BTN_A = (0x01, 0x130) 462 | BTN_EAST = (0x01, 0x131) 463 | BTN_B = (0x01, 0x131) 464 | BTN_C = (0x01, 0x132) 465 | BTN_NORTH = (0x01, 0x133) 466 | BTN_X = (0x01, 0x133) 467 | BTN_WEST = (0x01, 0x134) 468 | BTN_Y = (0x01, 0x134) 469 | BTN_Z = (0x01, 0x135) 470 | BTN_TL = (0x01, 0x136) 471 | BTN_TR = (0x01, 0x137) 472 | BTN_TL2 = (0x01, 0x138) 473 | BTN_TR2 = (0x01, 0x139) 474 | BTN_SELECT = (0x01, 0x13a) 475 | BTN_START = (0x01, 0x13b) 476 | BTN_MODE = (0x01, 0x13c) 477 | BTN_THUMBL = (0x01, 0x13d) 478 | BTN_THUMBR = (0x01, 0x13e) 479 | BTN_DIGI = (0x01, 0x140) 480 | BTN_TOOL_PEN = (0x01, 0x140) 481 | BTN_TOOL_RUBBER = (0x01, 0x141) 482 | BTN_TOOL_BRUSH = (0x01, 0x142) 483 | BTN_TOOL_PENCIL = (0x01, 0x143) 484 | BTN_TOOL_AIRBRUSH = (0x01, 0x144) 485 | BTN_TOOL_FINGER = (0x01, 0x145) 486 | BTN_TOOL_MOUSE = (0x01, 0x146) 487 | BTN_TOOL_LENS = (0x01, 0x147) 488 | BTN_TOOL_QUINTTAP = (0x01, 0x148) 489 | BTN_TOUCH = (0x01, 0x14a) 490 | BTN_STYLUS = (0x01, 0x14b) 491 | BTN_STYLUS2 = (0x01, 0x14c) 492 | BTN_TOOL_DOUBLETAP = (0x01, 0x14d) 493 | BTN_TOOL_TRIPLETAP = (0x01, 0x14e) 494 | BTN_TOOL_QUADTAP = (0x01, 0x14f) 495 | BTN_WHEEL = (0x01, 0x150) 496 | BTN_GEAR_DOWN = (0x01, 0x150) 497 | BTN_GEAR_UP = (0x01, 0x151) 498 | BTN_DPAD_UP = (0x01, 0x220) 499 | BTN_DPAD_DOWN = (0x01, 0x221) 500 | BTN_DPAD_LEFT = (0x01, 0x222) 501 | BTN_DPAD_RIGHT = (0x01, 0x223) 502 | BTN_TRIGGER_HAPPY = (0x01, 0x2c0) 503 | BTN_TRIGGER_HAPPY1 = (0x01, 0x2c0) 504 | BTN_TRIGGER_HAPPY2 = (0x01, 0x2c1) 505 | BTN_TRIGGER_HAPPY3 = (0x01, 0x2c2) 506 | BTN_TRIGGER_HAPPY4 = (0x01, 0x2c3) 507 | BTN_TRIGGER_HAPPY5 = (0x01, 0x2c4) 508 | BTN_TRIGGER_HAPPY6 = (0x01, 0x2c5) 509 | BTN_TRIGGER_HAPPY7 = (0x01, 0x2c6) 510 | BTN_TRIGGER_HAPPY8 = (0x01, 0x2c7) 511 | BTN_TRIGGER_HAPPY9 = (0x01, 0x2c8) 512 | BTN_TRIGGER_HAPPY10 = (0x01, 0x2c9) 513 | BTN_TRIGGER_HAPPY11 = (0x01, 0x2ca) 514 | BTN_TRIGGER_HAPPY12 = (0x01, 0x2cb) 515 | BTN_TRIGGER_HAPPY13 = (0x01, 0x2cc) 516 | BTN_TRIGGER_HAPPY14 = (0x01, 0x2cd) 517 | BTN_TRIGGER_HAPPY15 = (0x01, 0x2ce) 518 | BTN_TRIGGER_HAPPY16 = (0x01, 0x2cf) 519 | BTN_TRIGGER_HAPPY17 = (0x01, 0x2d0) 520 | BTN_TRIGGER_HAPPY18 = (0x01, 0x2d1) 521 | BTN_TRIGGER_HAPPY19 = (0x01, 0x2d2) 522 | BTN_TRIGGER_HAPPY20 = (0x01, 0x2d3) 523 | BTN_TRIGGER_HAPPY21 = (0x01, 0x2d4) 524 | BTN_TRIGGER_HAPPY22 = (0x01, 0x2d5) 525 | BTN_TRIGGER_HAPPY23 = (0x01, 0x2d6) 526 | BTN_TRIGGER_HAPPY24 = (0x01, 0x2d7) 527 | BTN_TRIGGER_HAPPY25 = (0x01, 0x2d8) 528 | BTN_TRIGGER_HAPPY26 = (0x01, 0x2d9) 529 | BTN_TRIGGER_HAPPY27 = (0x01, 0x2da) 530 | BTN_TRIGGER_HAPPY28 = (0x01, 0x2db) 531 | BTN_TRIGGER_HAPPY29 = (0x01, 0x2dc) 532 | BTN_TRIGGER_HAPPY30 = (0x01, 0x2dd) 533 | BTN_TRIGGER_HAPPY31 = (0x01, 0x2de) 534 | BTN_TRIGGER_HAPPY32 = (0x01, 0x2df) 535 | BTN_TRIGGER_HAPPY33 = (0x01, 0x2e0) 536 | BTN_TRIGGER_HAPPY34 = (0x01, 0x2e1) 537 | BTN_TRIGGER_HAPPY35 = (0x01, 0x2e2) 538 | BTN_TRIGGER_HAPPY36 = (0x01, 0x2e3) 539 | BTN_TRIGGER_HAPPY37 = (0x01, 0x2e4) 540 | BTN_TRIGGER_HAPPY38 = (0x01, 0x2e5) 541 | BTN_TRIGGER_HAPPY39 = (0x01, 0x2e6) 542 | BTN_TRIGGER_HAPPY40 = (0x01, 0x2e7) 543 | REL_X = (0x02, 0x00) 544 | REL_Y = (0x02, 0x01) 545 | REL_Z = (0x02, 0x02) 546 | REL_RX = (0x02, 0x03) 547 | REL_RY = (0x02, 0x04) 548 | REL_RZ = (0x02, 0x05) 549 | REL_HWHEEL = (0x02, 0x06) 550 | REL_DIAL = (0x02, 0x07) 551 | REL_WHEEL = (0x02, 0x08) 552 | REL_MISC = (0x02, 0x09) 553 | REL_WHEEL_HI_RES = (0x02, 0x0b) 554 | REL_HWHEEL_HI_RES = (0x02, 0x0c) 555 | REL_MAX = (0x02, 0x0f) 556 | ABS_X = (0x03, 0x00) 557 | ABS_Y = (0x03, 0x01) 558 | ABS_Z = (0x03, 0x02) 559 | ABS_RX = (0x03, 0x03) 560 | ABS_RY = (0x03, 0x04) 561 | ABS_RZ = (0x03, 0x05) 562 | ABS_THROTTLE = (0x03, 0x06) 563 | ABS_RUDDER = (0x03, 0x07) 564 | ABS_WHEEL = (0x03, 0x08) 565 | ABS_GAS = (0x03, 0x09) 566 | ABS_BRAKE = (0x03, 0x0a) 567 | ABS_HAT0X = (0x03, 0x10) 568 | ABS_HAT0Y = (0x03, 0x11) 569 | ABS_HAT1X = (0x03, 0x12) 570 | ABS_HAT1Y = (0x03, 0x13) 571 | ABS_HAT2X = (0x03, 0x14) 572 | ABS_HAT2Y = (0x03, 0x15) 573 | ABS_HAT3X = (0x03, 0x16) 574 | ABS_HAT3Y = (0x03, 0x17) 575 | ABS_PRESSURE = (0x03, 0x18) 576 | ABS_DISTANCE = (0x03, 0x19) 577 | ABS_TILT_X = (0x03, 0x1a) 578 | ABS_TILT_Y = (0x03, 0x1b) 579 | ABS_TOOL_WIDTH = (0x03, 0x1c) 580 | ABS_VOLUME = (0x03, 0x20) 581 | ABS_MISC = (0x03, 0x28) 582 | ABS_MT_SLOT = (0x03, 0x2f) 583 | ABS_MT_TOUCH_MAJOR = (0x03, 0x30) 584 | ABS_MT_TOUCH_MINOR = (0x03, 0x31) 585 | ABS_MT_WIDTH_MAJOR = (0x03, 0x32) 586 | ABS_MT_WIDTH_MINOR = (0x03, 0x33) 587 | ABS_MT_ORIENTATION = (0x03, 0x34) 588 | ABS_MT_POSITION_X = (0x03, 0x35) 589 | ABS_MT_POSITION_Y = (0x03, 0x36) 590 | ABS_MT_TOOL_TYPE = (0x03, 0x37) 591 | ABS_MT_BLOB_ID = (0x03, 0x38) 592 | ABS_MT_TRACKING_ID = (0x03, 0x39) 593 | ABS_MT_PRESSURE = (0x03, 0x3a) 594 | ABS_MT_DISTANCE = (0x03, 0x3b) 595 | ABS_MT_TOOL_X = (0x03, 0x3c) 596 | ABS_MT_TOOL_Y = (0x03, 0x3d) 597 | ABS_MAX = (0x03, 0x3f) 598 | -------------------------------------------------------------------------------- /tests/test_uinput.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | import uinput 4 | 5 | MOUSE_KEYS = [uinput.REL_X, uinput.REL_Y, uinput.BTN_LEFT, uinput.BTN_RIGHT] 6 | 7 | class DeviceTest(unittest.TestCase): 8 | def test_device_empty(self): 9 | with uinput.Device([]) as device: 10 | pass 11 | 12 | def test_keyboard_click(self): 13 | test_key = uinput.KEY_LEFTCTRL 14 | with uinput.Device([test_key]) as device: 15 | device.emit_click(test_key) 16 | 17 | def test_mouse_move(self): 18 | with uinput.Device(MOUSE_KEYS) as device: 19 | device.emit(uinput.REL_X, 1) 20 | 21 | 22 | if __name__ == "__main__": 23 | unittest.main() 24 | -------------------------------------------------------------------------------- /udev-rules/40-uinput.rules: -------------------------------------------------------------------------------- 1 | SUBSYSTEM=="misc", KERNEL=="uinput", MODE="0660", GROUP="uinput" 2 | --------------------------------------------------------------------------------