Class: Uinput::Device
- Inherits:
-
Object
show all
- Defined in:
- lib/uinput/device.rb,
lib/uinput/device/error.rb,
lib/uinput/device/version.rb,
lib/uinput/device/system_initializer.rb
Defined Under Namespace
Classes: Error, SystemInitializer
Constant Summary
collapse
- SYS_INPUT_DIR =
'/sys/devices/virtual/input/'
- VERSION =
"0.3.1"
Instance Method Summary
collapse
Constructor Details
#initialize(&block) ⇒ Device
Returns a new instance of Device.
11
12
13
|
# File 'lib/uinput/device.rb', line 11
def initialize(&block)
@file = self.class::SystemInitializer.new(self, &block).create
end
|
Instance Method Details
#active? ⇒ Boolean
43
44
45
|
# File 'lib/uinput/device.rb', line 43
def active?
not @file.nil?
end
|
#destroy ⇒ Object
15
16
17
18
|
# File 'lib/uinput/device.rb', line 15
def destroy
@file.ioctl(UI_DEV_DESTROY, nil)
@file = nil
end
|
#dev_path ⇒ Object
33
34
35
36
37
|
# File 'lib/uinput/device.rb', line 33
def dev_path
event_dir = Dir["#{sys_path}/event*"].first
event = File.basename(event_dir)
"/dev/input/#{event}"
end
|
#name ⇒ Object
39
40
41
|
# File 'lib/uinput/device.rb', line 39
def name
File.read("#{sys_path}/name")
end
|
#send_event(type, code, value = 0) ⇒ Object
47
48
49
50
51
52
53
54
55
|
# File 'lib/uinput/device.rb', line 47
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
|
#sys_path ⇒ Object
29
30
31
|
# File 'lib/uinput/device.rb', line 29
def sys_path
"#{SYS_INPUT_DIR}#{sysname}"
end
|
#sysname ⇒ Object
20
21
22
23
24
25
26
27
|
# File 'lib/uinput/device.rb', line 20
def sysname
@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
end
|