Project

libevdev

0.0
No commit activity in last 3 years
No release in over 3 years
libevdev bindings for ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

~> 1.8
~> 1.9
 Project Readme

Libevdev

1:1 FFI ruby bindings for libevdev.

For a nice object wrapper around the raw bindings have a look at the evdev gem.

Installation

Add this line to your application's Gemfile:

gem 'libevdev'

And then execute:

$ bundle

Or install it yourself as:

$ gem install libevdev

Usage

require 'libevdev'

All libevdev constants and methods are available under the Libevdev namespace. The LIBEVDEV_ and libevdev_ prefixes of the C API have been dropped. Besides that, all names were left unchanged.

Accessing constants

Libevdev::READ_FLAG_SYNC
Libevdev::GRAB
Libevdev::READ_STATUS_SUCCESS
# an so on …

Initializing a new libevdev device

file = File.open('/dev/input/event0')

# pointer to the pointer of the to be created libevdev struct
evdev_ptr = FFI::MemoryPointer.new :pointer

Libevdev.new_from_fd(file.fileno, evdev_ptr)

# get the pointer to the actual opaque libevdev struct
evdev = evdev_ptr.read_pointer

Listening to events

Libevdev also loads the LinuxInput gem for its structs and constants.

event = LinuxInput::InputEvent.new
loop do
    Libevdev.next_event(evdev, Libevdev::READ_FLAG_NORMAL, event.pointer)
    puts event[:type]
    puts event[:code]
    puts event[:value]
end

Freeing the device

Libevdev.free(evdev)