Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/muniftanjim/lua-evdev
LuaJIT FFI Bindings for libevdev.
https://github.com/muniftanjim/lua-evdev
evdev ffi libevdev luajit
Last synced: about 2 months ago
JSON representation
LuaJIT FFI Bindings for libevdev.
- Host: GitHub
- URL: https://github.com/muniftanjim/lua-evdev
- Owner: MunifTanjim
- License: mit
- Created: 2021-12-25T17:59:19.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-08-27T12:49:40.000Z (over 2 years ago)
- Last Synced: 2024-10-11T08:19:11.192Z (2 months ago)
- Topics: evdev, ffi, libevdev, luajit
- Language: Lua
- Homepage: https://luarocks.org/modules/MunifTanjim/lua-evdev
- Size: 53.7 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lua-evdev
LuaJIT FFI Bindings for [`libevdev`](https://gitlab.freedesktop.org/libevdev/libevdev).
## Usage
### Initializing a Device
```lua
local Device = require("evdev.device")---@param dev Device
local function print_device(dev)
local name = dev:name():gsub("\n", " | ")
print("============", "===")
print("= Name: ", name)
print("= Phys: ", dev:phys())
print("= Uniq: ", dev:uniq())
print("= Product: ", dev:product_id())
print("= Vendor: ", dev:vendor_id())
print("= Bustype: ", dev:bustype())
print("= Version: ", dev:version())
print("============", "===")
endlocal dev = Device:new("/dev/input/event7")
print_device(dev)
```### Reading Events from a Device
```lua
local Event = require("evdev.event")
local Device = require("evdev.device")
local libevdev = require("evdev.libevdev")
local input = require("evdev.linux.input")local enum = libevdev.enum
local input_constant = input.constant---@param ev Event
local function print_event(ev)
print(string.format("{'%s', '%s', %d};", ev:type_name(), ev:code_name(), ev:value()))
end---@param dev Device
---@param initial_state table
local function events(dev, initial_state)
initial_state = initial_state or {}if not initial_state.read_flag then
initial_state.read_flag = initial_state.read_flag or enum.libevdev_read_flag.NORMAL
endif not initial_state.should_skip then
initial_state.should_skip = function()
return false
end
end---@return Event
local function iter(state)
local rc, ev = 0, Event:new()repeat
rc, ev = dev:next_event(state.read_flag, ev)
if (rc == enum.libevdev_read_status.SUCCESS) or (rc == enum.libevdev_read_status.SYNC) then
if not state.should_skip(ev) then
return ev, state
end
end
until rc ~= enum.libevdev_read_status.SUCCESS and rc ~= enum.libevdev_read_status.SYNC and rc ~= -11return nil, state
endreturn iter, initial_state
endlocal dev = Device:new("/dev/input/event7")
local initial_state = {
---@param ev Event
should_skip = function(ev)
ev:is_type(input_constant.EV_KEY)
end,
}for ev in events(dev, initial_state) do
print_event(ev)
end
```### Initializing a UInputDevice
```lua
local Device = require("evdev.device")
local UIDevice = require("evdev.uinput-device")---@param uidev UInputDevice
local function print_uinput_device(uidev)
print("============", "===")
print("= FD: ", uidev:fd())
print("= SysPath: ", uidev:syspath())
print("= DevNode: ", uidev:devnode())
print("============", "===")
endlocal dev = Device:new("/dev/input/event7")
local uidev = UIDevice:new(dev)
print_uinput_device(uidev)
```## License
Licensed under the MIT License. Check the [LICENSE](./LICENSE) file for details.