|
3 | 3 | `evdev` is a Lua module for working with Linux input devices through the evdev |
4 | 4 | interface. |
5 | 5 |
|
6 | | -It lets Lua discover Linux input devices, read raw events, grab devices, and |
7 | | -create virtual input devices with uinput. |
| 6 | +Compatible with Lua 5.1, 5.2, 5.3, 5.4, 5.5, and LuaJIT. |
8 | 7 |
|
9 | | -## Compatibility |
| 8 | +Use `evdev` to read events from keyboards, mice, gamepads, and other |
| 9 | +`/dev/input` devices, grab a device while handling input yourself, or create |
| 10 | +virtual keyboards, mice, and controllers through `/dev/uinput`. |
10 | 11 |
|
11 | | -`evdev` supports: |
| 12 | +## Install |
12 | 13 |
|
13 | | -- Lua 5.1 |
14 | | -- Lua 5.2 |
15 | | -- Lua 5.3 |
16 | | -- Lua 5.4 |
17 | | -- Lua 5.5 |
18 | | -- LuaJIT |
| 14 | +::: code-group |
19 | 15 |
|
20 | | -## Use Cases |
| 16 | +```sh [LuaRocks] |
| 17 | +luarocks install bluelua-evdev |
| 18 | +``` |
21 | 19 |
|
22 | | -- Build input automation tools. |
23 | | -- Read keyboard, mouse, gamepad, and other Linux input events from Lua. |
24 | | -- Inspect devices under `/dev/input`. |
25 | | -- Grab a device while handling input yourself. |
26 | | -- Create virtual keyboards, mice, or controllers for tests and tooling. |
| 20 | +::: |
| 21 | + |
| 22 | +## Quick Start |
| 23 | + |
| 24 | +::: code-group |
| 25 | + |
| 26 | +```lua [lis-devices.lua] |
| 27 | +local evdev = require "evdev" |
| 28 | + |
| 29 | +for _, info in ipairs(devices) do |
| 30 | + print(info.path, info.name) |
| 31 | +end |
| 32 | +``` |
| 33 | + |
| 34 | +```lua [open-device.lua] |
| 35 | +local evdev = require "evdev" |
| 36 | + |
| 37 | +local dev = assert(evdev.device("/dev/input/event3")) |
| 38 | +print("opened:", dev.name) |
| 39 | +``` |
| 40 | + |
| 41 | +```lua [read-events.lua] |
| 42 | +local evdev = require "evdev" |
| 43 | +local dev = assert(evdev.device("/dev/input/event3")) |
| 44 | + |
| 45 | +for event in dev:events() do |
| 46 | + print(event.type, event.code, event.value) |
| 47 | +end |
| 48 | +``` |
| 49 | + |
| 50 | +::: |
0 commit comments