|
1 | 1 | # evdev |
2 | 2 |
|
3 | | -Lua bindings for Linux `evdev` input devices and `/dev/uinput` virtual |
4 | | -keyboards, pointers. |
| 3 | +Lua bindings for Linux `evdev` input devices and `/dev/uinput` virtual devices |
| 4 | +(keyboards, mice, and relative pointers). |
5 | 5 |
|
6 | | -## Install |
| 6 | +Get started with the |
| 7 | +[documentation and tutorials](https://bluelua.github.io/evdev). |
| 8 | + |
| 9 | +[](https://luarocks.org/modules/BlueLua/bluelua-evdev) |
| 10 | +[](LICENSE) |
| 11 | + |
| 12 | +## 🚀 Features |
| 13 | + |
| 14 | +- **Device Discovery**: List and search for connected input devices by name, |
| 15 | + path, or physical location. |
| 16 | +- **Event Stream**: Easily read kernel input events with high-resolution |
| 17 | + timestamps. |
| 18 | +- **Virtual Devices (uinput)**: Emulate any hardware input device (mouse, |
| 19 | + keyboard, gamepad) programmatically. |
| 20 | +- **Event Selector**: Poll multiple input devices concurrently in a single |
| 21 | + non-blocking event loop. |
| 22 | +- **Multiple Lua Versions**: Compatible with LuaJIT, Lua 5.1, 5.2, 5.3, 5.4, and |
| 23 | + 5.5. |
| 24 | + |
| 25 | +--- |
| 26 | + |
| 27 | +## 📦 Installation |
| 28 | + |
| 29 | +Install the library via LuaRocks: |
7 | 30 |
|
8 | 31 | ```bash |
9 | 32 | luarocks install bluelua-evdev |
10 | 33 | ``` |
| 34 | + |
| 35 | +## 🛠️ Quick Examples |
| 36 | + |
| 37 | +### Listening to Key Presses |
| 38 | + |
| 39 | +```lua |
| 40 | +local evdev = require "evdev" |
| 41 | + |
| 42 | +-- Find and open the primary keyboard |
| 43 | +local dev = assert(evdev.device.open("/dev/input/event0")) |
| 44 | +print("Opened device: " .. dev.name) |
| 45 | + |
| 46 | +-- Process events in a loop |
| 47 | +for event in dev:events() do |
| 48 | + if evdev.events.is_press(event) then |
| 49 | + print("Key Pressed! Code: " .. event.code) |
| 50 | + end |
| 51 | +end |
| 52 | +``` |
| 53 | + |
| 54 | +### Creating a Virtual Keyboard |
| 55 | + |
| 56 | +```lua |
| 57 | +local evdev = require "evdev" |
| 58 | +local ecodes = evdev.ecodes |
| 59 | + |
| 60 | +-- Create the virtual keyboard |
| 61 | +local ui = assert(evdev.uinput.create()) |
| 62 | + |
| 63 | +-- Press Shift + A |
| 64 | +ui:emit(ecodes.EV_KEY, ecodes.KEY_LEFTSHIFT, 1) |
| 65 | +ui:emit(ecodes.EV_KEY, ecodes.KEY_A, 1) |
| 66 | +ui:sync() |
| 67 | + |
| 68 | +-- Release Shift + A |
| 69 | +ui:emit(ecodes.EV_KEY, ecodes.KEY_A, 0) |
| 70 | +ui:emit(ecodes.EV_KEY, ecodes.KEY_LEFTSHIFT, 0) |
| 71 | +ui:sync() |
| 72 | + |
| 73 | +ui:close() |
| 74 | +``` |
0 commit comments