0.0
No commit activity in last 3 years
No release in over 3 years
FFI structs and constants for linux's input subsystem
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

~> 1.9
 Project Readme

LinuxInput

FFI structs and constants for linux's input subsystem found in linux/input.h

Have a look at the Libevdev gem for an easier to use interface to the input subsystem.

Installation

Add this line to your application's Gemfile:

gem 'linux_input'

And then execute:

$ bundle

Or install it yourself as:

$ gem install linux_input

Usage

require 'linux_input'

All constants and structures are accessible through the LinuxInput module.

snake_case C structure names are transformed into CamelCase Ruby constant names:

LinuxInput::InputEvent   # input_event struct
LinuxInput::FfEffect     # ff_effect struct
# and so on ...

Constant names are left untouched:

LinuxInput::EV_KEY     # => 0x01 (key event bit)
LinuxInput::KEY_A      # => 30 (key code of the a key)
# and so on ...

Ioctl constants and macros:

LinuxInput::EVIOCGID
LinuxInput::EVIOCGNAME(len)
# and so on ...

Mapping a received event to the input_event struct:

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

loop do
    raw_event = file.read LinuxInput::InputEvent.size
    raw_event_ptr = FFI::MemoryPointer.from_string(raw_event)
    event = LinuxInput::InputEvent.new(raw_event_ptr)
    puts Time.at(event[:time][:tv_sec])
    puts event[:type]
    puts event[:code]
    puts event[:value]
end

(Re-)Compiling the interface on a linux machine

Reads your local linux/input.h

$ rake ffi:generate