Project

uinput

0.0
No commit activity in last 3 years
No release in over 3 years
Structs and Constants to use uinput with ruby.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

Uinput

FFI Structs and Constants of to use uinput with ruby. Depends on the linux_input gem.

This is pretty low level. For a higher level and more user friendly abstraction have a look at the uinput-device gem.

Installation

Add this line to your application's Gemfile:

gem 'uinput'

And then execute:

$ bundle

Or install it yourself as:

$ gem install uinput

Usage

require 'uinput'

Creating a new virtual keyboard having an A key:

file = File.open('/dev/uinput', Fcntl::O_WRONLY | Fcntl::O_NDELAY)
device = Uinput::UinputUserDev.new

device[:name] = "Virtual Ruby Device"
device[:id][:type] = LinuxInput::BUS_VIRTUAL
device[:id][:vendor] = 0
device[:id][:product] = 0
device[:id][:version] = 0

file.ioctl(Uinput::UI_SET_KEYBIT, LinuxInput::KEY_A)
file.ioctl(Uinput::UI_SET_EVBIT, LinuxInput::EV_KEY)
file.ioctl(Uinput::UI_SET_EVBIT, LinuxInput::EV_SYN)

file.syswrite(device.pointer.read_bytes(device.size))
file.ioctl(Uinput::UI_DEV_CREATE)

Typing an 'a' on our keyboard:

# key down event
event = LinuxInput::InputEvent.new
event[:time] = LinuxInput::Timeval.new
event[:time][:tv_sec] = Time.now.to_i
event[:type] = LinuxInput::EV_KEY
event[:code] = LinuxInput::KEY_A
event[:value] = 1
file.syswrite(event.pointer.read_bytes(event.size))

# sync event for key down
event = LinuxInput::InputEvent.new
event[:time] = LinuxInput::Timeval.new
event[:time][:tv_sec] = Time.now.to_i
event[:type] = LinuxInput::EV_SYN
event[:code] = LinuxInput::SYN_REPORT
event[:value] = 0
file.syswrite(event.pointer.read_bytes(event.size))

# key up event
event = LinuxInput::InputEvent.new
event[:time] = LinuxInput::Timeval.new
event[:time][:tv_sec] = Time.now.to_i
event[:type] = LinuxInput::EV_KEY
event[:code] = LinuxInput::KEY_A
event[:value] = 0
file.syswrite(event.pointer.read_bytes(event.size))

# sync event for key up
event = LinuxInput::InputEvent.new
event[:time] = LinuxInput::Timeval.new
event[:time][:tv_sec] = Time.now.to_i
event[:type] = LinuxInput::EV_SYN
event[:code] = LinuxInput::SYN_REPORT
event[:value] = 0
file.syswrite(event.pointer.read_bytes(event.size))

Destroying the device:

file.ioctl(Uinput::UI_DEV_DESTROY, nil)

(Re-)Compiling the interface on a linux machine

Reads your local linux/uinput.h

$ rake ffi:generate