fusuma-plugin-sendkey 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/fusuma-plugin-sendkey.gemspec +2 -0
- data/lib/fusuma/plugin/executors/sendkey_executor.rb +1 -13
- data/lib/fusuma/plugin/sendkey/keyboard.rb +24 -16
- data/lib/fusuma/plugin/sendkey/version.rb +1 -1
- data/spec/fusuma/plugin/executors/sendkey_executor_spec.rb +16 -29
- data/spec/fusuma/plugin/sendkey/keyboard_spec.rb +38 -43
- data/spec/helpers/config_helper.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cf085cf00f878f5262bd4ef48d3e8ab49354bea02823c85c11e6edea79e9854
|
4
|
+
data.tar.gz: 718effb43a443bbb46852c851bf4716688a3e5bab413fa8a13ddda0f1cca1058
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea348132422cb7bab174e93eccabcd6df2ab358e5d282b619bd380e1a50452bc9c17021e046881cb256f9cb7ea3b30b2c752ba60f7e9be8b5bbe263ed9af7f04
|
7
|
+
data.tar.gz: 2a0e4eed20e056eff6708a7ce67c7015fd16ab85626c4729321328baaf7d6e27b25cc6509263a5c98630d37b41bb8a7a2d3c4a2e47f6225cfdf1bd2982030b6b
|
@@ -21,6 +21,8 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.bindir = 'exe'
|
22
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
23
|
spec.require_paths = ['lib']
|
24
|
+
spec.required_ruby_version = '>= 2.5.1' # https://packages.ubuntu.com/search?keywords=ruby&searchon=names&exact=1&suite=all§ion=main
|
25
|
+
# support bionic (18.04LTS) 2.5.1
|
24
26
|
|
25
27
|
spec.add_dependency 'fusuma', '~> 2.0.0'
|
26
28
|
spec.add_dependency 'revdev'
|
@@ -34,10 +34,7 @@ module Fusuma
|
|
34
34
|
# @param event [Event]
|
35
35
|
# @return [nil]
|
36
36
|
def _execute(event)
|
37
|
-
keyboard.type(
|
38
|
-
param: search_param(event),
|
39
|
-
keep: search_keypress(event)
|
40
|
-
)
|
37
|
+
keyboard.type(param: search_param(event))
|
41
38
|
end
|
42
39
|
|
43
40
|
# check executable
|
@@ -62,15 +59,6 @@ module Fusuma
|
|
62
59
|
index = Config::Index.new([*event.record.index.keys, :sendkey])
|
63
60
|
Config.search(index)
|
64
61
|
end
|
65
|
-
|
66
|
-
# @param event [Event]
|
67
|
-
# @return [String]
|
68
|
-
def search_keypress(event)
|
69
|
-
keys = event.record.index.keys
|
70
|
-
keypress_index = keys.find_index { |k| k.symbol == :keypress }
|
71
|
-
code = keypress_index && keys[keypress_index + 1].symbol
|
72
|
-
code.to_s
|
73
|
-
end
|
74
62
|
end
|
75
63
|
end
|
76
64
|
end
|
@@ -10,9 +10,25 @@ module Fusuma
|
|
10
10
|
module Sendkey
|
11
11
|
# Emulate Keyboard
|
12
12
|
class Keyboard
|
13
|
+
MODIFIER_KEY_CODES = %w[
|
14
|
+
KEY_CAPSLOCK
|
15
|
+
KEY_LEFTALT
|
16
|
+
KEY_LEFTCTRL
|
17
|
+
KEY_LEFTMETA
|
18
|
+
KEY_LEFTSHIFT
|
19
|
+
KEY_RIGHTALT
|
20
|
+
KEY_RIGHTCTRL
|
21
|
+
KEY_RIGHTSHIFT
|
22
|
+
KEY_RIGHTMETA
|
23
|
+
].freeze
|
24
|
+
|
25
|
+
def self.find_device(name_pattern:)
|
26
|
+
Fusuma::Device.all.find { |d| d.name.match(/#{name_pattern}/) }
|
27
|
+
end
|
28
|
+
|
13
29
|
def initialize(name_pattern: nil)
|
14
30
|
name_pattern ||= 'keyboard|Keyboard|KEYBOARD'
|
15
|
-
device = find_device(name_pattern: name_pattern)
|
31
|
+
device = Keyboard.find_device(name_pattern: name_pattern)
|
16
32
|
|
17
33
|
if device.nil?
|
18
34
|
warn "sendkey: Keyboard: /#{name_pattern}/ is not found"
|
@@ -26,16 +42,14 @@ module Fusuma
|
|
26
42
|
|
27
43
|
# @param param [String]
|
28
44
|
# @param keep [String]
|
29
|
-
def type(param
|
45
|
+
def type(param:)
|
30
46
|
return unless param.is_a?(String)
|
31
47
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
clear_modifiers(keep_keycodes)
|
36
|
-
keycodes.each { |keycode| key_event(keycode: keycode, press: true) }
|
48
|
+
param_keycodes = split_param(param)
|
49
|
+
clear_modifiers(MODIFIER_KEY_CODES - param_keycodes)
|
50
|
+
param_keycodes.each { |keycode| key_event(keycode: keycode, press: true) }
|
37
51
|
key_sync(press: true)
|
38
|
-
|
52
|
+
param_keycodes.reverse.each { |keycode| key_event(keycode: keycode, press: false) }
|
39
53
|
key_sync(press: false)
|
40
54
|
end
|
41
55
|
|
@@ -101,19 +115,13 @@ module Fusuma
|
|
101
115
|
Object.const_get "LinuxInput::#{keycode}"
|
102
116
|
end
|
103
117
|
|
118
|
+
# @param [Array<String>] keycodes to be released
|
104
119
|
def clear_modifiers(keycodes)
|
105
|
-
|
106
|
-
LEFTSHIFT RIGHTALT RIGHTCTRL RIGHTSHIFT ]
|
107
|
-
.map { |code| key_prefix(code) }
|
108
|
-
(modifiers - keycodes).each { |code| key_event(keycode: code, press: false) }
|
120
|
+
keycodes.each { |code| key_event(keycode: code, press: false) }
|
109
121
|
end
|
110
122
|
|
111
123
|
private
|
112
124
|
|
113
|
-
def find_device(name_pattern:)
|
114
|
-
Fusuma::Device.all.find { |d| d.name.match(/#{name_pattern}/) }
|
115
|
-
end
|
116
|
-
|
117
125
|
def split_param(param)
|
118
126
|
param.split('+').map { |code| key_prefix(code) }
|
119
127
|
end
|
@@ -18,9 +18,6 @@ module Fusuma
|
|
18
18
|
1:
|
19
19
|
direction:
|
20
20
|
sendkey: KEY_CODE
|
21
|
-
keypress:
|
22
|
-
LEFTSHIFT:
|
23
|
-
sendkey: KEY_CODE_WITH_KEYPRESS
|
24
21
|
|
25
22
|
plugin:
|
26
23
|
executors:
|
@@ -37,9 +34,9 @@ module Fusuma
|
|
37
34
|
index = Config::Index.new([:dummy, 1, :direction])
|
38
35
|
record = Events::Records::IndexRecord.new(index: index)
|
39
36
|
@event = Events::Event.new(tag: 'dummy_detector', record: record)
|
40
|
-
@executor =
|
37
|
+
@executor = described_class.new
|
41
38
|
|
42
|
-
@keyboard =
|
39
|
+
@keyboard = instance_double(Sendkey::Keyboard)
|
43
40
|
|
44
41
|
allow(@executor).to receive(:keyboard).and_return @keyboard
|
45
42
|
end
|
@@ -49,6 +46,7 @@ module Fusuma
|
|
49
46
|
allow(Process).to receive(:daemon).with(true)
|
50
47
|
allow(Process).to receive(:detach).with(anything)
|
51
48
|
end
|
49
|
+
|
52
50
|
it 'fork' do
|
53
51
|
expect(@executor).to receive(:fork).and_yield do |block_context|
|
54
52
|
expect(block_context).to receive(:_execute).with(@event)
|
@@ -59,27 +57,10 @@ module Fusuma
|
|
59
57
|
end
|
60
58
|
|
61
59
|
describe '#_execute' do
|
62
|
-
after do
|
63
|
-
@executor._execute(@event)
|
64
|
-
end
|
65
60
|
it 'send KEY_CODE message to keybard' do
|
66
|
-
|
67
|
-
expect(@
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
context 'with keypress' do
|
72
|
-
before do
|
73
|
-
index_with_keypress = Config::Index.new(
|
74
|
-
[:dummy, 1, :direction, :keypress, :LEFTSHIFT]
|
75
|
-
)
|
76
|
-
record = Events::Records::IndexRecord.new(index: index_with_keypress)
|
77
|
-
@event = Events::Event.new(tag: 'dummy_detector', record: record)
|
78
|
-
end
|
79
|
-
it 'send KEY_CODE_WITH_KEYPRESS message to keybard' do
|
80
|
-
expect(@keyboard).to receive(:type)
|
81
|
-
.with(param: 'KEY_CODE_WITH_KEYPRESS', keep: 'LEFTSHIFT')
|
82
|
-
end
|
61
|
+
allow(@executor).to receive(:search_param).with(@event).and_return('KEY_CODE')
|
62
|
+
expect(@keyboard).to receive(:type).with(param: 'KEY_CODE')
|
63
|
+
@executor._execute(@event)
|
83
64
|
end
|
84
65
|
end
|
85
66
|
|
@@ -92,15 +73,17 @@ module Fusuma
|
|
92
73
|
allow(@keyboard).to receive(:valid?).with(param: 'INVALID_CODE')
|
93
74
|
.and_return false
|
94
75
|
end
|
76
|
+
|
95
77
|
context 'when given valid event tagged as xxxx_detector' do
|
96
|
-
it { expect(@executor.
|
78
|
+
it { expect(@executor).to be_executable(@event) }
|
97
79
|
end
|
98
80
|
|
99
81
|
context 'when given INVALID event tagged as invalid_tag' do
|
100
82
|
before do
|
101
83
|
@event.tag = 'invalid_tag'
|
102
84
|
end
|
103
|
-
|
85
|
+
|
86
|
+
it { expect(@executor).not_to be_executable(@event) }
|
104
87
|
end
|
105
88
|
|
106
89
|
context "when sendkey: 'MODIFIER_CODE+KEY_CODE'" do
|
@@ -121,8 +104,8 @@ module Fusuma
|
|
121
104
|
Config.custom_path = nil
|
122
105
|
end
|
123
106
|
|
124
|
-
it '
|
125
|
-
expect(@executor.
|
107
|
+
it 'returns true' do
|
108
|
+
expect(@executor).to be_executable(@event)
|
126
109
|
end
|
127
110
|
end
|
128
111
|
|
@@ -143,6 +126,10 @@ module Fusuma
|
|
143
126
|
|
144
127
|
Config.custom_path = nil
|
145
128
|
end
|
129
|
+
|
130
|
+
it 'returns true' do
|
131
|
+
expect(@executor).not_to be_executable(@event)
|
132
|
+
end
|
146
133
|
end
|
147
134
|
end
|
148
135
|
end
|
@@ -9,62 +9,62 @@ module Fusuma
|
|
9
9
|
module Sendkey
|
10
10
|
RSpec.describe Keyboard do
|
11
11
|
describe '#new' do
|
12
|
-
context 'keyboard is found' do
|
12
|
+
context 'when keyboard is found' do
|
13
13
|
before do
|
14
14
|
dummy_keyboard = Fusuma::Device.new(name: 'dummy keyboard')
|
15
|
-
|
15
|
+
allow(described_class)
|
16
16
|
.to receive(:find_device)
|
17
17
|
.and_return(dummy_keyboard)
|
18
18
|
allow(Sendkey::Device).to receive(:new).and_return('dummy')
|
19
19
|
end
|
20
20
|
|
21
|
-
it '
|
22
|
-
expect {
|
21
|
+
it 'does not raise error' do
|
22
|
+
expect { described_class.new }.not_to raise_error
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
context 'keyboard is not found' do
|
26
|
+
context 'when keyboard is not found' do
|
27
27
|
before do
|
28
|
-
|
28
|
+
allow(described_class)
|
29
29
|
.to receive(:find_device)
|
30
30
|
.and_return(nil)
|
31
31
|
end
|
32
32
|
|
33
|
-
it '
|
34
|
-
expect {
|
33
|
+
it 'does not raise error' do
|
34
|
+
expect { described_class.new }.to raise_error SystemExit
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
context 'detected device name is Keyboard (Capitarized)' do
|
38
|
+
context 'when detected device name is Keyboard (Capitarized)' do
|
39
39
|
before do
|
40
40
|
other_device = Fusuma::Device.new(name: 'Keyboard', id: 'dummy')
|
41
41
|
|
42
|
-
|
42
|
+
allow(described_class)
|
43
43
|
.to receive(:find_device)
|
44
44
|
.and_return(other_device)
|
45
45
|
allow(Sendkey::Device).to receive(:new).and_return('dummy')
|
46
46
|
end
|
47
47
|
|
48
|
-
it '
|
49
|
-
expect {
|
48
|
+
it 'does not raise error' do
|
49
|
+
expect { described_class.new }.not_to raise_error
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
context 'detected device name is KEYBOARD (Upper case)' do
|
53
|
+
context 'when detected device name is KEYBOARD (Upper case)' do
|
54
54
|
before do
|
55
55
|
other_device = Fusuma::Device.new(name: 'KEYBOARD', id: 'dummy')
|
56
|
-
|
56
|
+
allow(described_class)
|
57
57
|
.to receive(:find_device)
|
58
58
|
.and_return(other_device)
|
59
59
|
allow(Sendkey::Device).to receive(:new).and_return('dummy')
|
60
60
|
end
|
61
61
|
|
62
|
-
it '
|
63
|
-
expect {
|
62
|
+
it 'does not raise error' do
|
63
|
+
expect { described_class.new }.not_to raise_error
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
context 'given name pattern' do
|
67
|
+
context 'with given name pattern' do
|
68
68
|
before do
|
69
69
|
specified_device = Fusuma::Device.new(
|
70
70
|
name: 'Awesome KEY/BOARD input device',
|
@@ -74,18 +74,19 @@ module Fusuma
|
|
74
74
|
allow(Sendkey::Device).to receive(:new).and_return('dummy')
|
75
75
|
end
|
76
76
|
|
77
|
-
it '
|
78
|
-
expect {
|
77
|
+
it 'does not raise error' do
|
78
|
+
expect { described_class.new(name_pattern: 'Awesome KEY/BOARD') }.not_to raise_error
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
context '
|
83
|
-
subject { -> {
|
82
|
+
context 'when name pattern (use default) is not given' do
|
83
|
+
subject { -> { described_class.new(name_pattern: nil) } }
|
84
|
+
|
84
85
|
before do
|
85
86
|
allow(Sendkey::Device).to receive(:new).and_return('dummy')
|
86
87
|
end
|
87
88
|
|
88
|
-
context 'exist device named keyboard' do
|
89
|
+
context 'when exist device named keyboard(lower-case)' do
|
89
90
|
before do
|
90
91
|
specified_device = Fusuma::Device.new(
|
91
92
|
name: 'keyboard',
|
@@ -97,7 +98,7 @@ module Fusuma
|
|
97
98
|
it { is_expected.not_to raise_error }
|
98
99
|
end
|
99
100
|
|
100
|
-
context 'exist device named Keyboard' do
|
101
|
+
context 'when exist device named Keyboard(Capital-case)' do
|
101
102
|
before do
|
102
103
|
specified_device = Fusuma::Device.new(
|
103
104
|
name: 'Keyboard',
|
@@ -109,7 +110,7 @@ module Fusuma
|
|
109
110
|
it { is_expected.not_to raise_error }
|
110
111
|
end
|
111
112
|
|
112
|
-
context 'exist device named KEYBOARD' do
|
113
|
+
context 'when exist device named KEYBOARD(UPPER case)' do
|
113
114
|
before do
|
114
115
|
specified_device = Fusuma::Device.new(
|
115
116
|
name: 'KEYBOARD',
|
@@ -121,7 +122,7 @@ module Fusuma
|
|
121
122
|
it { is_expected.not_to raise_error }
|
122
123
|
end
|
123
124
|
|
124
|
-
context 'exist no device named keyboard|Keyboard|KEYBOARD' do
|
125
|
+
context 'when exist no device named keyboard|Keyboard|KEYBOARD' do
|
125
126
|
before do
|
126
127
|
specified_device = Fusuma::Device.new(
|
127
128
|
name: 'KEY-BOARD',
|
@@ -137,20 +138,20 @@ module Fusuma
|
|
137
138
|
|
138
139
|
describe '#type' do
|
139
140
|
before do
|
140
|
-
|
141
|
+
allow(described_class)
|
141
142
|
.to receive(:find_device)
|
142
143
|
.and_return(Fusuma::Device.new(name: 'dummy keyboard'))
|
143
144
|
|
144
|
-
@device =
|
145
|
+
@device = instance_double(Sendkey::Device)
|
145
146
|
allow(@device).to receive(:write_event).with(anything)
|
146
147
|
# allow(@device).to receive(:valid?).with(param: 'KEY_A')
|
147
148
|
|
148
149
|
allow(Sendkey::Device).to receive(:new).and_return(@device)
|
149
150
|
|
150
|
-
@keyboard =
|
151
|
+
@keyboard = described_class.new
|
151
152
|
end
|
152
153
|
|
153
|
-
it '
|
154
|
+
it 'presses key KEY_A and release KEY_A' do
|
154
155
|
expect(@keyboard).to receive(:clear_modifiers).ordered
|
155
156
|
expect(@keyboard).to receive(:key_event).with(keycode: 'KEY_A', press: true).ordered
|
156
157
|
expect(@keyboard).to receive(:key_event).with(keycode: 'KEY_A', press: false).ordered
|
@@ -162,7 +163,12 @@ module Fusuma
|
|
162
163
|
@keys = 'LEFTSHIFT+A'
|
163
164
|
end
|
164
165
|
|
165
|
-
it '
|
166
|
+
it 'clear all modifier keys except parameter of sendkey' do
|
167
|
+
expect(@keyboard).to receive(:clear_modifiers).with(Keyboard::MODIFIER_KEY_CODES - ['KEY_LEFTSHIFT']).ordered
|
168
|
+
@keyboard.type(param: @keys)
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'types (Shift)A' do
|
166
172
|
expect(@keyboard).to receive(:clear_modifiers).ordered
|
167
173
|
expect(@keyboard).to receive(:key_event).with(keycode: 'KEY_LEFTSHIFT', press: true).ordered
|
168
174
|
expect(@keyboard).to receive(:key_event).with(keycode: 'KEY_A', press: true).ordered
|
@@ -171,12 +177,13 @@ module Fusuma
|
|
171
177
|
@keyboard.type(param: @keys)
|
172
178
|
end
|
173
179
|
end
|
180
|
+
|
174
181
|
context 'with multiple keys' do
|
175
182
|
before do
|
176
183
|
@keys = 'A+B'
|
177
184
|
end
|
178
185
|
|
179
|
-
it '
|
186
|
+
it 'types AB' do
|
180
187
|
expect(@keyboard).to receive(:clear_modifiers).ordered
|
181
188
|
expect(@keyboard).to receive(:key_event).with(keycode: 'KEY_A', press: true).ordered
|
182
189
|
expect(@keyboard).to receive(:key_event).with(keycode: 'KEY_B', press: true).ordered
|
@@ -185,18 +192,6 @@ module Fusuma
|
|
185
192
|
@keyboard.type(param: @keys)
|
186
193
|
end
|
187
194
|
end
|
188
|
-
context 'with keypress' do
|
189
|
-
before do
|
190
|
-
@keys = 'LEFTSHIFT+A'
|
191
|
-
@keypress_keys = 'LEFTSHIFT'
|
192
|
-
end
|
193
|
-
it 'should type A (without LEFTSHIFT key pressing by user)' do
|
194
|
-
expect(@keyboard).to receive(:clear_modifiers).ordered
|
195
|
-
expect(@keyboard).to receive(:key_event).with(keycode: 'KEY_A', press: true).ordered
|
196
|
-
expect(@keyboard).to receive(:key_event).with(keycode: 'KEY_A', press: false).ordered
|
197
|
-
@keyboard.type(param: @keys, keep: @keypress_keys)
|
198
|
-
end
|
199
|
-
end
|
200
195
|
end
|
201
196
|
end
|
202
197
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fusuma-plugin-sendkey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- iberianpig
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fusuma
|
@@ -74,7 +74,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
74
74
|
requirements:
|
75
75
|
- - ">="
|
76
76
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
77
|
+
version: 2.5.1
|
78
78
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ">="
|