uinput-device 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +39 -0
- data/lib/uinput/device.rb +7 -10
- data/lib/uinput/device/{factory.rb → system_initializer.rb} +5 -15
- data/lib/uinput/device/version.rb +1 -1
- data/uinput-device.gemspec +1 -2
- metadata +5 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2f68045a5faf497f1608f21b0878dd8f9bf151f
|
4
|
+
data.tar.gz: 7e9221d8b6bf3066a6fc7a42ff0d0176d171595f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3560fcba16b1e5dc8a2e7675b21a0e4a0e2ee397a2d3023142e7acc7823fc076fa886f4c5f32b902291ad51a991ad66b5bcf1ea98b2cae8abe47dbae043ce76e
|
7
|
+
data.tar.gz: 956397f608409ec6979f450abdf242b3f0a835b34225a2e94a49e5ba526f01bda204724cb6277717f27dc4334261d7aa6c6541c67b3dff70436a849543034d54
|
data/README.md
CHANGED
@@ -17,3 +17,42 @@ And then execute:
|
|
17
17
|
Or install it yourself as:
|
18
18
|
|
19
19
|
$ gem install uinput-device
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'uinput/device'
|
25
|
+
```
|
26
|
+
|
27
|
+
Initializing a new virtual device having an A key:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
device = Uinput::Device.new do
|
31
|
+
self.name = "Our virtual device"
|
32
|
+
self.type = LinuxInput::BUS_VIRTUAL
|
33
|
+
self.add_key(:KEY_A)
|
34
|
+
self.add_event(:EV_KEY)
|
35
|
+
self.add_event(:EV_SYN)
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
Symbols like `:KEY_A` are mapped to constants in the `LinuxInput` namespace (see
|
40
|
+
[linux_input](https://github.com/christopheraue/ruby-linux_input))
|
41
|
+
|
42
|
+
Typing an 'a' on our keyboard:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
# key down
|
46
|
+
device.send_event(:EV_KEY, :KEY_A, 1)
|
47
|
+
device.send_event(:EV_SYN, :SYN_REPORT)
|
48
|
+
|
49
|
+
# key up
|
50
|
+
device.send_event(:EV_KEY, :KEY_A, 0)
|
51
|
+
device.send_event(:EV_SYN, :SYN_REPORT)
|
52
|
+
```
|
53
|
+
|
54
|
+
Destroying the device:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
device.destroy
|
58
|
+
```
|
data/lib/uinput/device.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
+
require 'bundler/setup'
|
1
2
|
require 'uinput'
|
2
3
|
require_relative "device/version"
|
3
|
-
require_relative "device/
|
4
|
+
require_relative "device/system_initializer"
|
4
5
|
require_relative "device/error"
|
5
|
-
require 'ffi/libc'
|
6
6
|
|
7
7
|
module Uinput
|
8
8
|
class Device
|
@@ -20,16 +20,13 @@ module Uinput
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def send_event(type, code, value = 0)
|
23
|
-
event = InputEvent.new
|
24
|
-
|
25
|
-
event[:
|
26
|
-
event[:
|
23
|
+
event = LinuxInput::InputEvent.new
|
24
|
+
event[:time] = LinuxInput::Timeval.new
|
25
|
+
event[:time][:tv_sec] = Time.now.to_i
|
26
|
+
event[:type] = type.is_a?(Symbol) ? LinuxInput.const_get(type) : type
|
27
|
+
event[:code] = code.is_a?(Symbol) ? LinuxInput.const_get(code) : code
|
27
28
|
event[:value] = value
|
28
29
|
@file.syswrite(event.pointer.read_bytes(event.size))
|
29
30
|
end
|
30
|
-
|
31
|
-
def send_syn_event
|
32
|
-
send_event(EV_SYN, SYN_REPORT)
|
33
|
-
end
|
34
31
|
end
|
35
32
|
end
|
@@ -3,18 +3,16 @@ module Uinput
|
|
3
3
|
class SystemInitializer
|
4
4
|
FILE = '/dev/uinput'
|
5
5
|
|
6
|
-
def initialize(&block)
|
6
|
+
def initialize(device, &block)
|
7
7
|
@file = File.open(FILE, Fcntl::O_WRONLY | Fcntl::O_NDELAY)
|
8
8
|
@device = UinputUserDev.new
|
9
9
|
|
10
10
|
self.name = "Virtual Ruby Device"
|
11
|
-
self.type = BUS_VIRTUAL
|
11
|
+
self.type = LinuxInput::BUS_VIRTUAL
|
12
12
|
self.vendor = 0
|
13
13
|
self.product = 0
|
14
14
|
self.version = 0
|
15
15
|
|
16
|
-
receive_syn_events
|
17
|
-
|
18
16
|
instance_exec &block if block
|
19
17
|
end
|
20
18
|
|
@@ -23,7 +21,7 @@ module Uinput
|
|
23
21
|
end
|
24
22
|
|
25
23
|
def type=(type)
|
26
|
-
@device[:id][:bustype] = type
|
24
|
+
@device[:id][:bustype] = type.is_a?(Symbol) ? LinuxInput.const_get(type) : type
|
27
25
|
end
|
28
26
|
|
29
27
|
def vendor=(vendor)
|
@@ -39,20 +37,12 @@ module Uinput
|
|
39
37
|
end
|
40
38
|
|
41
39
|
def add_key(key)
|
42
|
-
@file.ioctl(UI_SET_KEYBIT, key)
|
40
|
+
@file.ioctl(UI_SET_KEYBIT, key.is_a?(Symbol) ? LinuxInput.const_get(key) : key)
|
43
41
|
end
|
44
42
|
alias_method :add_button, :add_key
|
45
43
|
|
46
44
|
def add_event(event)
|
47
|
-
@file.ioctl(UI_SET_EVBIT, event)
|
48
|
-
end
|
49
|
-
|
50
|
-
def receive_key_events
|
51
|
-
add_event(EV_KEY)
|
52
|
-
end
|
53
|
-
|
54
|
-
def receive_syn_events
|
55
|
-
add_event(EV_SYN)
|
45
|
+
@file.ioctl(UI_SET_EVBIT, event.is_a?(Symbol) ? LinuxInput.const_get(event) : event)
|
56
46
|
end
|
57
47
|
|
58
48
|
def create
|
data/uinput-device.gemspec
CHANGED
@@ -16,8 +16,7 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
17
|
spec.require_paths = ["lib"]
|
18
18
|
|
19
|
-
spec.add_runtime_dependency "uinput", "~> 1.
|
20
|
-
spec.add_runtime_dependency 'ffi-libc', '~> 0.1.0'
|
19
|
+
spec.add_runtime_dependency "uinput", "~> 1.1"
|
21
20
|
spec.add_development_dependency "bundler", "~> 1.8"
|
22
21
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
22
|
end
|
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.
|
4
|
+
version: 0.2.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: 2015-08-
|
11
|
+
date: 2015-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: uinput
|
@@ -16,28 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: ffi-libc
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 0.1.0
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 0.1.0
|
26
|
+
version: '1.1'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: bundler
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,7 +68,7 @@ files:
|
|
82
68
|
- Rakefile
|
83
69
|
- lib/uinput/device.rb
|
84
70
|
- lib/uinput/device/error.rb
|
85
|
-
- lib/uinput/device/
|
71
|
+
- lib/uinput/device/system_initializer.rb
|
86
72
|
- lib/uinput/device/version.rb
|
87
73
|
- uinput-device.gemspec
|
88
74
|
homepage: https://github.com/christopheraue/ruby-uinput-device
|