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.
Add this line to your application's Gemfile:
gem 'linux_input'
And then execute:
$ bundle
Or install it yourself as:
$ gem install linux_input
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
Reads your local linux/input.h
$ rake ffi:generate