Class: Revdev::EventDevice

Inherits:
Object
  • Object
show all
Defined in:
lib/revdev.rb,
lib/revdev/event_device.rb

Instance Method Summary collapse

Constructor Details

#initialize(arg) ⇒ EventDevice

Returns a new instance of EventDevice.



6
7
8
9
10
11
12
# File 'lib/revdev/event_device.rb', line 6

def initialize arg
  if arg.kind_of? File
    @file = arg
  else
    @file = File.new arg, 'r+'
  end
end

Instance Method Details

#all_leds_statusObject



50
51
52
# File 'lib/revdev/event_device.rb', line 50

def all_leds_status
  read_ioctl_as_string_with EVIOCGLED
end

#all_sounds_statusObject



54
55
56
# File 'lib/revdev/event_device.rb', line 54

def all_sounds_status
  read_ioctl_as_string_with EVIOCGSND
end

#all_switch_statusObject



58
59
60
# File 'lib/revdev/event_device.rb', line 58

def all_switch_status
  read_ioctl_as_string_with EVIOCGSW
end

#device_nameObject



30
31
32
# File 'lib/revdev/event_device.rb', line 30

def device_name
  read_ioctl_as_string_with EVIOCGNAME
end

#device_propObject



42
43
44
# File 'lib/revdev/event_device.rb', line 42

def device_prop
  read_ioctl_as_string_with EVIOCGPROP
end

#driver_versionObject



20
21
22
23
# File 'lib/revdev/event_device.rb', line 20

def driver_version
  r = read_ioctl_with EVIOCGVERSION
  r.unpack('i').first
end

#global_key_stateObject



46
47
48
# File 'lib/revdev/event_device.rb', line 46

def global_key_state
  read_ioctl_as_string_with EVIOCGKEY
end

#grabObject

grab all input events of the event device



63
64
65
# File 'lib/revdev/event_device.rb', line 63

def grab
  @file.ioctl EVIOCGRAB, 1
end

#physical_locationObject



34
35
36
# File 'lib/revdev/event_device.rb', line 34

def physical_location
  read_ioctl_as_string_with EVIOCGPHYS
end

#read_input_eventObject



72
73
74
# File 'lib/revdev/event_device.rb', line 72

def read_input_event
  InputEvent.new @file.read InputEvent::SIZEOF
end

#read_ioctl_as_string_with(command) ⇒ Object



25
26
27
28
# File 'lib/revdev/event_device.rb', line 25

def read_ioctl_as_string_with command
  r = read_ioctl_with command
  r.unpack('Z*').first
end

#read_ioctl_with(command) ⇒ Object



14
15
16
17
18
# File 'lib/revdev/event_device.rb', line 14

def read_ioctl_with command
  r = ""
  @file.ioctl command, r
  return r
end

#ungrabObject

release the grabbed event device



68
69
70
# File 'lib/revdev/event_device.rb', line 68

def ungrab
  @file.ioctl EVIOCGRAB, 0
end

#uniq_idObject



38
39
40
# File 'lib/revdev/event_device.rb', line 38

def uniq_id
  read_ioctl_as_string_with EVIOCGUNIQ
end

#write_input_event(ie) ⇒ Object



76
77
78
# File 'lib/revdev/event_device.rb', line 76

def write_input_event ie
  @file.syswrite ie.to_byte_string
end