Class: Uinput::Device::Initializer
- Inherits:
-
Object
- Object
- Uinput::Device::Initializer
- Defined in:
- lib/uinput/device/initializer.rb
Instance Method Summary collapse
- #add_event(event) ⇒ Object
- #add_key(key) ⇒ Object (also: #add_button)
- #create ⇒ Object
-
#initialize(device, &block) ⇒ Initializer
constructor
A new instance of Initializer.
- #name=(name) ⇒ Object
- #product=(product) ⇒ Object
- #type=(type) ⇒ Object
- #vendor=(vendor) ⇒ Object
- #version=(version) ⇒ Object
Constructor Details
#initialize(device, &block) ⇒ Initializer
Returns a new instance of Initializer.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/uinput/device/initializer.rb', line 6 def initialize(device, &block) @file = Uinput.open_file(Fcntl::O_RDWR | Fcntl::O_NONBLOCK) if Uinput.version == 5 @device = UinputSetup.new else @device = UinputUserDev.new end self.name = "Virtual Ruby Device" self.type = LinuxInput::BUS_VIRTUAL self.vendor = 0 self.product = 0 self.version = 0 instance_exec &block if block if Uinput.version >= 5 @file.ioctl UI_DEV_SETUP, @device.pointer.read_bytes(@device.size) else @file.syswrite @device.pointer.read_bytes(@device.size) end end |
Instance Method Details
#add_event(event) ⇒ Object
55 56 57 |
# File 'lib/uinput/device/initializer.rb', line 55 def add_event(event) @file.ioctl(UI_SET_EVBIT, (event.is_a? Symbol) ? LinuxInput.const_get(event) : event) end |
#add_key(key) ⇒ Object Also known as:
50 51 52 |
# File 'lib/uinput/device/initializer.rb', line 50 def add_key(key) @file.ioctl(UI_SET_KEYBIT, (key.is_a? Symbol) ? LinuxInput.const_get(key) : key) end |
#create ⇒ Object
59 60 61 62 63 |
# File 'lib/uinput/device/initializer.rb', line 59 def create if @file.ioctl(UI_DEV_CREATE).zero? @file end end |
#name=(name) ⇒ Object
30 31 32 |
# File 'lib/uinput/device/initializer.rb', line 30 def name=(name) @device[:name] = name[0,UINPUT_MAX_NAME_SIZE] end |
#product=(product) ⇒ Object
42 43 44 |
# File 'lib/uinput/device/initializer.rb', line 42 def product=(product) @device[:id][:product] = product end |
#type=(type) ⇒ Object
34 35 36 |
# File 'lib/uinput/device/initializer.rb', line 34 def type=(type) @device[:id][:bustype] = (type.is_a? Symbol) ? LinuxInput.const_get(type) : type end |
#vendor=(vendor) ⇒ Object
38 39 40 |
# File 'lib/uinput/device/initializer.rb', line 38 def vendor=(vendor) @device[:id][:vendor] = vendor end |
#version=(version) ⇒ Object
46 47 48 |
# File 'lib/uinput/device/initializer.rb', line 46 def version=(version) @device[:id][:version] = version end |