11--- @meta evdev.device
22
33---
4- --- One Linux input event returned by `Device:read()` .
4+ --- A Linux input event.
55---
66--- @class evdev.event
77--- @field device ? evdev.Device
@@ -51,9 +51,7 @@ local Device = {}
5151--- Close the device.
5252---
5353--- ```lua
54- --- local Device = evdev.device.open
5554--- local dev = assert(Device("/dev/input/eventX"))
56- ---
5755--- print(dev:is_open()) --> true
5856--- dev:close()
5957--- print(dev:is_open()) --> false
@@ -67,9 +65,7 @@ function Device:close() end
6765--- Return whether this device handle still has an open file descriptor.
6866---
6967--- ```lua
70- --- local Device = evdev.device.open
7168--- local dev = assert(Device("/dev/input/eventX"))
72- ---
7369--- if dev:is_open()
7470--- then dev:close()
7571--- end
@@ -82,9 +78,7 @@ function Device:is_open() end
8278--- Return the current auto-repeat delay and period in milliseconds.
8379---
8480--- ```lua
85- --- local Device = evdev.device.open
8681--- local dev = assert(Device("/dev/input/eventX"))
87- ---
8882--- local delay, period, err = dev:get_repeat()
8983--- assert(delay, err)
9084--- print(delay, period)
@@ -93,16 +87,16 @@ function Device:is_open() end
9387--- @return integer ? delay Initial delay before repeating (milliseconds ).
9488--- @return integer ? period Interval between repeats (milliseconds ).
9589--- @return string ? err Error message on failure.
90+ --- @nodiscard
9691function Device :get_repeat () end
9792
9893---
9994--- Set the auto-repeat delay and period in milliseconds.
10095---
10196--- ```lua
102- --- local Device = evdev.device.open
10397--- local dev = assert(Device("/dev/input/eventX"))
104- ---
10598--- local delay, period, err = dev:get_repeat()
99+ ---
106100--- assert(delay, err)
107101--- print(delay, period)
108102---
@@ -120,9 +114,7 @@ function Device:set_repeat(delay, period) end
120114--- Return the underlying Linux file descriptor.
121115---
122116--- ```lua
123- --- local Device = evdev.device.open
124117--- local dev = assert(Device("/dev/input/eventX"))
125- ---
126118--- local fd = dev:fd()
127119--- print(fd)
128120--- ```
@@ -135,7 +127,6 @@ function Device:fd() end
135127--- Take exclusive control of the input device.
136128---
137129--- ```lua
138- --- local Device = evdev.device.open
139130--- local dev = assert(Device("/dev/input/eventX"))
140131--- assert(dev:grab())
141132--- ```
@@ -148,7 +139,6 @@ function Device:grab() end
148139--- Release exclusive control of the input device.
149140---
150141--- ```lua
151- --- local Device = evdev.device.open
152142--- local dev = assert(Device("/dev/input/eventX"))
153143--- assert(dev:grab())
154144--- assert(dev:ungrab())
@@ -161,13 +151,11 @@ function Device:ungrab() end
161151---
162152--- Wait in the kernel until this device has input available.
163153---
164- --- This does not spin the CPU. It returns when `read()` can fetch at least one
154+ --- This does not spin the CPU. It returns when `evdev.device. read()` can fetch at least one
165155--- queued event.
166156---
167157--- ```lua
168- --- local Device = evdev.device.open
169158--- local ecodes = evdev.ecodes
170- ---
171159--- local dev = assert(Device("/dev/input/eventX"))
172160---
173161---- - This is the manual form of `dev:events()`.
@@ -190,26 +178,22 @@ function Device:poll() end
190178--- Return an iterator that waits for and yields input events one by one.
191179---
192180--- ```lua
193- --- local Device = evdev.device.open
194181--- local dev = assert(Device("/dev/input/eventX"))
195- ---
196182--- for e in dev:events() do
197183--- if e.type == ecodes.EV_KEY then
198184--- print(e.code, e.value)
199185--- end
200186--- end
201187--- ```
202188---
203- --- @return fun (): evdev.event ?
189+ --- @return fun ():( ev : evdev.event ?)
204190function Device :events () end
205191
206192---
207193--- Read one input event. Returns `nil` when no event is queued.
208194---
209195--- ```lua
210- --- local Device = evdev.device.open
211196--- local dev = assert(Device("/dev/input/eventX"))
212- ---
213197---- - This is the manual form of `dev:events()`.
214198--- while true do
215199--- if assert(dev:poll()) then
@@ -233,9 +217,7 @@ function Device:read() end
233217--- events that were already queued.
234218---
235219--- ```lua
236- --- local Device = evdev.device.open
237220--- local dev = assert(Device("/dev/input/eventX"))
238- ---
239221--- assert(dev:grab())
240222---- - Move the mouse or press keys during the sleep.
241223---
@@ -250,17 +232,19 @@ function Device:flush() end
250232---
251233--- Query and monitor physical Linux input devices.
252234---
235+ --- ## Usage
236+ ---
253237--- ```lua
254238--- local evdev = require "evdev"
255239---
256- ---- - Find and open the primary keyboard
257- --- local dev = assert(evdev.device.open ("/dev/input/event0"))
240+ ---- - Open an input device (e.g., event0)
241+ --- local dev = assert(Device ("/dev/input/event0"))
258242--- print("Opened device: " .. dev.name)
259243---
260244---- - Process events in a loop
261- --- for event in dev:events() do
262- --- if evdev.events.is_press(event ) then
263- --- print("Key Pressed! Code: " .. event .code)
245+ --- for ev in dev:events() do
246+ --- if evdev.events.is_press(ev ) then
247+ --- print("Key Pressed! Code: " .. ev .code)
264248--- end
265249--- end
266250--- ```
@@ -288,7 +272,6 @@ function M.is_device(value) end
288272--- Open an input device by path.
289273---
290274--- ```lua
291- --- local Device = evdev.device.open
292275--- local dev = assert(Device("/dev/input/eventX"))
293276--- ```
294277---
0 commit comments