Class: Uinput::Device
- Inherits:
-
Object
- Object
- Uinput::Device
- Defined in:
- lib/uinput/device.rb,
lib/uinput/device/error.rb,
lib/uinput/device/version.rb,
lib/uinput/device/initializer.rb
Defined Under Namespace
Classes: Error, Initializer
Constant Summary collapse
- SYS_INPUT_DIR =
'/sys/devices/virtual/input/'- VERSION =
"0.4.0"
Instance Attribute Summary collapse
-
#dev_path ⇒ Object
readonly
Returns the value of attribute dev_path.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#sys_path ⇒ Object
readonly
Returns the value of attribute sys_path.
-
#sysname ⇒ Object
readonly
Returns the value of attribute sysname.
Instance Method Summary collapse
- #active? ⇒ Boolean
- #destroy ⇒ Object
-
#initialize(&block) ⇒ Device
constructor
A new instance of Device.
- #name ⇒ Object
- #send_event(type, code, value = 0) ⇒ Object
Constructor Details
#initialize(&block) ⇒ Device
Returns a new instance of Device.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# 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 |
Instance Attribute Details
#dev_path ⇒ Object (readonly)
Returns the value of attribute dev_path.
30 31 32 |
# File 'lib/uinput/device.rb', line 30 def dev_path @dev_path end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
30 31 32 |
# File 'lib/uinput/device.rb', line 30 def file @file end |
#sys_path ⇒ Object (readonly)
Returns the value of attribute sys_path.
30 31 32 |
# File 'lib/uinput/device.rb', line 30 def sys_path @sys_path end |
#sysname ⇒ Object (readonly)
Returns the value of attribute sysname.
30 31 32 |
# File 'lib/uinput/device.rb', line 30 def sysname @sysname end |
Instance Method Details
#active? ⇒ Boolean
41 42 43 |
# File 'lib/uinput/device.rb', line 41 def active? not @file.nil? end |
#destroy ⇒ Object
32 33 34 35 |
# File 'lib/uinput/device.rb', line 32 def destroy @file.ioctl(UI_DEV_DESTROY, nil) @file = nil end |
#name ⇒ Object
37 38 39 |
# File 'lib/uinput/device.rb', line 37 def name File.read("#{@sys_path}/name").strip end |
#send_event(type, code, value = 0) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# 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 |