Skip to content

Commit f9f970c

Browse files
docs(evdev): generate API docs (#13)
Co-authored-by: haithium <128622475+haithium@users.noreply.github.com>
1 parent cf49132 commit f9f970c

2 files changed

Lines changed: 77 additions & 17 deletions

File tree

docs/src/evdev/api/device.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ local Device = evdev.device.open
110110
local dev = assert(Device("/dev/input/eventX"))
111111

112112
assert(dev:grab())
113-
os.execute("sleep 3")
114-
115113
-- Move the mouse or press keys during the sleep.
116114

117115
local dropped = assert(dev:flush())

docs/src/evdev/api/uinput.md

Lines changed: 77 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ Configuration used to create a `/dev/uinput` virtual device.
88

99
## Functions
1010

11-
| Function | Description |
12-
| ------------------------------------- | ------------------------------------------------ |
13-
| [`close()`](#fn-close) | Destroy and close the virtual device. |
14-
| [`create(spec?)`](#fn-create) | Create a virtual input device. |
15-
| [`emit(type, code, value)`](#fn-emit) | Emit one raw input event. |
16-
| [`is_open()`](#fn-is-open) | Return whether the virtual device is still open. |
17-
| [`sync()`](#fn-sync) | Emit a `SYN_REPORT` event. |
11+
| Function | Description |
12+
| --------------------------------------------- | ------------------------------------------------------------- |
13+
| [`close()`](#fn-close) | Destroy and close the virtual device. |
14+
| [`create(spec?)`](#fn-create) | Create a virtual input device. |
15+
| [`emit(type, code, value)`](#fn-emit) | Emit one raw input event. |
16+
| [`fd()`](#fn-fd) | Get the file descriptor of the virtual device. |
17+
| [`get_repeat()`](#fn-get-repeat) | Get the current keyboard repeat rate from the virtual device. |
18+
| [`is_open()`](#fn-is-open) | Return whether the virtual device is still open. |
19+
| [`set_repeat(delay, period)`](#fn-set-repeat) | Set the keyboard repeat rate on the virtual device. |
20+
| [`sync()`](#fn-sync) | Emit a `SYN_REPORT` event. |
1821

1922
<a id="fn-close"></a>
2023

@@ -56,10 +59,6 @@ Create a virtual input device.
5659
local UInput = evdev.uinput.create
5760
local ui = assert(UInput())
5861

59-
-- Give the system a moment to notice the new virtual device.
60-
-- Replace this with your preferred sleep helper.
61-
os.execute("sleep 0.5")
62-
6362
ui:emit(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_A, 1)
6463
ui:emit(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_A, 0)
6564
ui:sync()
@@ -91,10 +90,6 @@ Emit one raw input event.
9190
local UInput = evdev.uinput.create
9291
local ui = assert(UInput())
9392

94-
-- Give the system a moment to notice the new virtual device.
95-
-- Replace this with your preferred sleep helper.
96-
os.execute("sleep 0.5")
97-
9893
local EV_KEY = evdev.ecodes.EV_KEY
9994
ui:emit(EV_KEY, evdev.ecodes.KEY_A, 1)
10095
ui:emit(EV_KEY, evdev.ecodes.KEY_A, 0)
@@ -106,6 +101,47 @@ ui:emit(EV_REL, evdev.ecodes.REL_Y, 10)
106101
ui:sync()
107102
```
108103

104+
<a id="fn-fd"></a>
105+
106+
### `fd()`
107+
108+
Get the file descriptor of the virtual device.
109+
110+
**Return**:
111+
112+
- `fd` (`evdev.fd?`): Linux file descriptor.
113+
114+
**Example**:
115+
116+
```lua
117+
local UInput = evdev.uinput.create
118+
local ui = assert(UInput())
119+
print(ui:fd())
120+
```
121+
122+
<a id="fn-get-repeat"></a>
123+
124+
### `get_repeat()`
125+
126+
Get the current keyboard repeat rate from the virtual device.
127+
128+
**Return**:
129+
130+
- `delay` (`integer?`): Repeat delay in milliseconds.
131+
- `period` (`integer?`): Repeat period in milliseconds.
132+
- `err` (`string?`): Error message on failure.
133+
134+
**Example**:
135+
136+
```lua
137+
local UInput = evdev.uinput.create
138+
local ui = assert(UInput())
139+
140+
local delay, period, err = ui:get_repeat()
141+
assert(delay, err)
142+
print(delay, period)
143+
```
144+
109145
<a id="fn-is-open"></a>
110146

111147
### `is_open()`
@@ -127,6 +163,32 @@ if ui:is_open() then
127163
end
128164
```
129165

166+
<a id="fn-set-repeat"></a>
167+
168+
### `set_repeat(delay, period)`
169+
170+
Set the keyboard repeat rate on the virtual device.
171+
172+
**Parameters**:
173+
174+
- `delay` (`integer`): Delay in milliseconds before key repeat starts.
175+
- `period` (`integer`): Period in milliseconds between repeated key events.
176+
177+
**Return**:
178+
179+
- `ok` (`true?`): `true` when the repeat rate is set successfully.
180+
- `err` (`string?`): Error message on failure.
181+
182+
**Example**:
183+
184+
```lua
185+
local UInput = evdev.uinput.create
186+
local ui = assert(UInput())
187+
188+
-- Set repeat delay to 500ms, repeat period to 50ms
189+
ui:set_repeat(500, 50)
190+
```
191+
130192
<a id="fn-sync"></a>
131193

132194
### `sync()`

0 commit comments

Comments
 (0)