class Uinput::Device

Constants

SYS_INPUT_DIR
VERSION

Attributes

dev_path[R]
file[R]
sys_path[R]
sysname[R]

Public Class Methods

new(&block) click to toggle source
# File lib/uinput/device.rb, line 11
def initialize(&block)
  @file = self.class::Initializer.new(self, &block).create

  @sysname = begin
    name_len = 128
    name_buffer = [' ' * name_len].pack("A#{name_len}")
    @file.ioctl(Uinput.UI_GET_SYSNAME(name_len), name_buffer)
    name_buffer.unpack("A#{name_len}").first
  end

  @sys_path = "#{SYS_INPUT_DIR}#{@sysname}"

  @dev_path = begin
    event_dir = Dir["#{@sys_path}/event*"].first
    event = File.basename(event_dir)
    "/dev/input/#{event}"
  end
end

Public Instance Methods

active?() click to toggle source
# File lib/uinput/device.rb, line 41
def active?
  not @file.nil?
end
destroy() click to toggle source
# File lib/uinput/device.rb, line 32
def destroy
  @file.ioctl(UI_DEV_DESTROY, nil)
  @file = nil
end
name() click to toggle source
# File lib/uinput/device.rb, line 37
def name
  File.read("#{@sys_path}/name").strip
end
send_event(type, code, value = 0) click to toggle source
# File lib/uinput/device.rb, line 45
def send_event(type, code, value = 0)
  event = LinuxInput::InputEvent.new
  event[:time] = LinuxInput::Timeval.new
  event[:time][:tv_sec] = Time.now.to_i
  event[:type] = type.is_a?(Symbol) ? LinuxInput.const_get(type) : type
  event[:code] = code.is_a?(Symbol) ? LinuxInput.const_get(code) : code
  event[:value] = value
  @file.syswrite(event.pointer.read_bytes(event.size))
end