uinput-device 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc5cdcee9ce23ba8f3f887e2a6a74ff5cc3c796a
4
- data.tar.gz: e79ee264fc67b72d779449e8b00bd25229520671
3
+ metadata.gz: 2503ff8c87ba140f94739e10a14f94b538a682c2
4
+ data.tar.gz: 2b89aa69f0e187cab4d349dfd4a856b4dfd54646
5
5
  SHA512:
6
- metadata.gz: 2783dffae5319696c7f21785a1d83d52c0398cb4aa7210227105066bdb1c3b6b635c10e9f6290297ed505e4db56d3c5fdde7e25605267313d4eb55519ed2c553
7
- data.tar.gz: c34d259be67c8164596f9e353802e5e14ce6922832c5e6ebd4c469a5db2c9a3cd4aec227bebc30d6402359062ef607014f5dc89c83ec40bffdb584381734d2e4
6
+ metadata.gz: 85bd8762b90000c510ca7e69107ffada74299c37664e53990fcd05c7184da7045017f640b528253c983849834d7e1b67dd79c514d79c470f3e901075385c362a
7
+ data.tar.gz: 766fd36f2ce8331df4c2e45127d37ce2e6f333dd7cd027278ab246077bb7cc58876acf7e788b87ef8725aec9bcad8953674a8f3dbf64805dc4cdd0cb6c86b5e7
@@ -1,7 +1,7 @@
1
- require 'bundler/setup'
2
1
  require 'uinput'
2
+
3
3
  require_relative "device/version"
4
- require_relative "device/system_initializer"
4
+ require_relative "device/initializer"
5
5
  require_relative "device/error"
6
6
 
7
7
  module Uinput
@@ -9,35 +9,33 @@ module Uinput
9
9
  SYS_INPUT_DIR = '/sys/devices/virtual/input/'
10
10
 
11
11
  def initialize(&block)
12
- @file = self.class::SystemInitializer.new(self, &block).create
13
- end
14
-
15
- def destroy
16
- @file.ioctl(UI_DEV_DESTROY, nil)
17
- @file = nil
18
- end
12
+ @file = self.class::Initializer.new(self, &block).create
19
13
 
20
- def sysname
21
- @sysname ||= begin
14
+ @sysname = begin
22
15
  name_len = 128
23
16
  name_buffer = [' ' * name_len].pack("A#{name_len}")
24
17
  @file.ioctl(Uinput.UI_GET_SYSNAME(name_len), name_buffer)
25
18
  name_buffer.unpack("A#{name_len}").first
26
19
  end
27
- end
28
20
 
29
- def sys_path
30
- "#{SYS_INPUT_DIR}#{sysname}"
21
+ @sys_path = "#{SYS_INPUT_DIR}#{@sysname}"
22
+
23
+ @dev_path = begin
24
+ event_dir = Dir["#{@sys_path}/event*"].first
25
+ event = File.basename(event_dir)
26
+ "/dev/input/#{event}"
27
+ end
31
28
  end
32
29
 
33
- def dev_path
34
- event_dir = Dir["#{sys_path}/event*"].first
35
- event = File.basename(event_dir)
36
- "/dev/input/#{event}"
30
+ attr_reader :file, :sysname, :sys_path, :dev_path
31
+
32
+ def destroy
33
+ @file.ioctl(UI_DEV_DESTROY, nil)
34
+ @file = nil
37
35
  end
38
36
 
39
37
  def name
40
- File.read("#{sys_path}/name").strip
38
+ File.read("#{@sys_path}/name").strip
41
39
  end
42
40
 
43
41
  def active?
@@ -0,0 +1,66 @@
1
+ require 'fcntl'
2
+
3
+ module Uinput
4
+ class Device
5
+ class Initializer
6
+ def initialize(device, &block)
7
+ @file = Uinput.open_file(Fcntl::O_RDWR | Fcntl::O_NONBLOCK)
8
+
9
+ if Uinput.version == 5
10
+ @device = UinputSetup.new
11
+ else
12
+ @device = UinputUserDev.new
13
+ end
14
+
15
+ self.name = "Virtual Ruby Device"
16
+ self.type = LinuxInput::BUS_VIRTUAL
17
+ self.vendor = 0
18
+ self.product = 0
19
+ self.version = 0
20
+
21
+ instance_exec &block if block
22
+
23
+ if Uinput.version >= 5
24
+ @file.ioctl UI_DEV_SETUP, @device.pointer.read_bytes(@device.size)
25
+ else
26
+ @file.syswrite @device.pointer.read_bytes(@device.size)
27
+ end
28
+ end
29
+
30
+ def name=(name)
31
+ @device[:name] = name[0,UINPUT_MAX_NAME_SIZE]
32
+ end
33
+
34
+ def type=(type)
35
+ @device[:id][:bustype] = (type.is_a? Symbol) ? LinuxInput.const_get(type) : type
36
+ end
37
+
38
+ def vendor=(vendor)
39
+ @device[:id][:vendor] = vendor
40
+ end
41
+
42
+ def product=(product)
43
+ @device[:id][:product] = product
44
+ end
45
+
46
+ def version=(version)
47
+ @device[:id][:version] = version
48
+ end
49
+
50
+ def add_key(key)
51
+ @file.ioctl(UI_SET_KEYBIT, (key.is_a? Symbol) ? LinuxInput.const_get(key) : key)
52
+ end
53
+ alias_method :add_button, :add_key
54
+
55
+ def add_event(event)
56
+ @file.ioctl(UI_SET_EVBIT, (event.is_a? Symbol) ? LinuxInput.const_get(event) : event)
57
+ end
58
+
59
+ def create
60
+ if @file.ioctl(UI_DEV_CREATE).zero?
61
+ @file
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -1,5 +1,5 @@
1
1
  module Uinput
2
2
  class Device
3
- VERSION = "0.3.3"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
data/test.rb ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative 'lib/uinput/device'
4
+
5
+ device = Uinput::Device.new do
6
+ add_key(:KEY_A)
7
+ add_event(:EV_KEY)
8
+ add_event(:EV_SYN)
9
+ end
10
+
11
+ puts "set up: #{device.name}"
12
+
13
+ input = File.open device.dev_path
14
+
15
+ # key down
16
+ device.send_event(:EV_KEY, :KEY_A, 1)
17
+ device.send_event(:EV_SYN, :SYN_REPORT)
18
+ puts 'pressed a'
19
+
20
+ # key up
21
+ device.send_event(:EV_KEY, :KEY_A, 0)
22
+ device.send_event(:EV_SYN, :SYN_REPORT)
23
+ puts 'released a'
24
+
25
+ event1 = LinuxInput::InputEvent.new FFI::MemoryPointer.from_string input.read LinuxInput::InputEvent.size
26
+ event2 = LinuxInput::InputEvent.new FFI::MemoryPointer.from_string input.read LinuxInput::InputEvent.size
27
+ event3 = LinuxInput::InputEvent.new FFI::MemoryPointer.from_string input.read LinuxInput::InputEvent.size
28
+ event4 = LinuxInput::InputEvent.new FFI::MemoryPointer.from_string input.read LinuxInput::InputEvent.size
29
+ p event1.values
30
+ p event2.values
31
+ p event3.values
32
+ p event4.values
33
+
34
+ device.destroy
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uinput-device
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Aue
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-03 00:00:00.000000000 Z
11
+ date: 2017-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uinput
@@ -68,8 +68,9 @@ files:
68
68
  - Rakefile
69
69
  - lib/uinput/device.rb
70
70
  - lib/uinput/device/error.rb
71
- - lib/uinput/device/system_initializer.rb
71
+ - lib/uinput/device/initializer.rb
72
72
  - lib/uinput/device/version.rb
73
+ - test.rb
73
74
  - uinput-device.gemspec
74
75
  homepage: https://github.com/christopheraue/ruby-uinput-device
75
76
  licenses:
@@ -91,8 +92,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
92
  version: '0'
92
93
  requirements: []
93
94
  rubyforge_project:
94
- rubygems_version: 2.4.5.1
95
+ rubygems_version: 2.5.1
95
96
  signing_key:
96
97
  specification_version: 4
97
98
  summary: Generic ruby wrapper around uinput to create devices.
98
99
  test_files: []
100
+ has_rdoc:
@@ -1,56 +0,0 @@
1
- require 'fcntl'
2
-
3
- module Uinput
4
- class Device
5
- class SystemInitializer
6
- FILE = '/dev/uinput'
7
-
8
- def initialize(device, &block)
9
- @file = File.open(FILE, Fcntl::O_WRONLY | Fcntl::O_NDELAY)
10
- @device = UinputUserDev.new
11
-
12
- self.name = "Virtual Ruby Device"
13
- self.type = LinuxInput::BUS_VIRTUAL
14
- self.vendor = 0
15
- self.product = 0
16
- self.version = 0
17
-
18
- instance_exec &block if block
19
- end
20
-
21
- def name=(name)
22
- @device[:name] = name
23
- end
24
-
25
- def type=(type)
26
- @device[:id][:bustype] = type.is_a?(Symbol) ? LinuxInput.const_get(type) : type
27
- end
28
-
29
- def vendor=(vendor)
30
- @device[:id][:vendor] = vendor
31
- end
32
-
33
- def product=(product)
34
- @device[:id][:product] = product
35
- end
36
-
37
- def version=(version)
38
- @device[:id][:version] = version
39
- end
40
-
41
- def add_key(key)
42
- @file.ioctl(UI_SET_KEYBIT, key.is_a?(Symbol) ? LinuxInput.const_get(key) : key)
43
- end
44
- alias_method :add_button, :add_key
45
-
46
- def add_event(event)
47
- @file.ioctl(UI_SET_EVBIT, event.is_a?(Symbol) ? LinuxInput.const_get(event) : event)
48
- end
49
-
50
- def create
51
- @file.syswrite(@device.pointer.read_bytes(@device.size))
52
- @file if @file.ioctl(UI_DEV_CREATE).zero?
53
- end
54
- end
55
- end
56
- end