Skip to content

Latest commit

 

History

History
75 lines (56 loc) · 2.26 KB

File metadata and controls

75 lines (56 loc) · 2.26 KB

evdev

LuaRocks Test Status Lua Versions Platform License

Lua bindings for Linux evdev input devices and /dev/uinput virtual devices (keyboards, mice, and relative pointers).

Get started with the documentation and tutorials.

✨ Features

  • Device Discovery: List and search for connected input devices by name, path, or physical location.
  • Event Stream: Easily read kernel input events with high-resolution timestamps.
  • Virtual Devices (uinput): Emulate any hardware input device (mouse, keyboard, gamepad) programmatically.
  • Event Selector: Poll multiple input devices concurrently in a single non-blocking event loop.
  • Multiple Lua Versions: Compatible with LuaJIT, Lua 5.1, 5.2, 5.3, 5.4, and 5.5.

📦 Installation

Install the library via LuaRocks:

luarocks install bluelua-evdev

🚀 Usage

Listening to Key Presses

local evdev = require "evdev"

-- Find and open the primary keyboard
local dev = assert(evdev.device.open("/dev/input/event0"))
print("Opened device: " .. dev.name)

-- Process events in a loop
for event in dev:events() do
  if evdev.events.is_press(event) then
    print("Key Pressed! Code: " .. event.code)
  end
end

Creating a Virtual Keyboard

local evdev = require "evdev"
local ecodes = evdev.ecodes

-- Create the virtual keyboard
local ui = assert(evdev.uinput.create())

-- Press Shift + A
ui:emit(ecodes.EV_KEY, ecodes.KEY_LEFTSHIFT, 1)
ui:emit(ecodes.EV_KEY, ecodes.KEY_A, 1)
ui:sync()

-- Release Shift + A
ui:emit(ecodes.EV_KEY, ecodes.KEY_A, 0)
ui:emit(ecodes.EV_KEY, ecodes.KEY_LEFTSHIFT, 0)
ui:sync()

ui:close()