Skip to content

Commit 4b1be01

Browse files
docs: generate API docs (#5)
Co-authored-by: haithium <128622475+haithium@users.noreply.github.com>
1 parent 9aeb509 commit 4b1be01

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

docs/index.md

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

0 commit comments

Comments
 (0)