Skip to content

Repository files navigation

lua-evdev

LuaJIT FFI Bindings for libevdev.

Usage

Initializing a Device

localDevice=require("evdev.device")
---@paramdevDevicelocalfunctionprint_device(dev)
localname=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("============", "===")
endlocaldev=Device:new("/dev/input/event7")
print_device(dev)

Reading Events from a Device

localEvent=require("evdev.event")
localDevice=require("evdev.device")
locallibevdev=require("evdev.libevdev")
localinput=require("evdev.linux.input")
localenum=libevdev.enumlocalinput_constant=input.constant---@paramevEventlocalfunctionprint_event(ev)
print(string.format("{'%s', '%s', %d};", ev:type_name(), ev:code_name(), ev:value()))
end---@paramdevDevice---@paraminitial_statetablelocalfunctionevents(dev, initial_state)
initial_state=initial_stateor {}
ifnotinitial_state.read_flagtheninitial_state.read_flag=initial_state.read_flagorenum.libevdev_read_flag.NORMALendifnotinitial_state.should_skiptheninitial_state.should_skip=function()
returnfalseendend---@returnEventlocalfunctioniter(state)
localrc, ev=0, Event:new()
repeatrc, ev=dev:next_event(state.read_flag, ev)
if (rc==enum.libevdev_read_status.SUCCESS) or (rc==enum.libevdev_read_status.SYNC) thenifnotstate.should_skip(ev) thenreturnev, stateendenduntilrc~=enum.libevdev_read_status.SUCCESSandrc~=enum.libevdev_read_status.SYNCandrc~=-11returnnil, stateendreturniter, initial_stateendlocaldev=Device:new("/dev/input/event7")
localinitial_state= {
---@paramevEventshould_skip=function(ev)
ev:is_type(input_constant.EV_KEY)
end,
}
forevinevents(dev, initial_state) doprint_event(ev)
end

Initializing a UInputDevice

localDevice=require("evdev.device")
localUIDevice=require("evdev.uinput-device")
---@paramuidevUInputDevicelocalfunctionprint_uinput_device(uidev)
print("============", "===")
print("= FD: ", uidev:fd())
print("= SysPath: ", uidev:syspath())
print("= DevNode: ", uidev:devnode())
print("============", "===")
endlocaldev=Device:new("/dev/input/event7")
localuidev=UIDevice:new(dev)
print_uinput_device(uidev)

License

Licensed under the MIT License. Check the LICENSE file for details.

About

LuaJIT FFI Bindings for libevdev.

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Contributors

Languages