fusuma-plugin-sendkey 0.6.3 → 0.7.1
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 +17 -18
- data/lib/fusuma/plugin/executors/sendkey_executor.rb +15 -3
- data/lib/fusuma/plugin/sendkey/device.rb +1 -1
- data/lib/fusuma/plugin/sendkey/keyboard.rb +48 -36
- data/lib/fusuma/plugin/sendkey/version.rb +1 -1
- data/lib/fusuma/plugin/sendkey.rb +2 -2
- metadata +4 -14
- data/spec/fusuma/plugin/executors/sendkey_executor_spec.rb +0 -138
- data/spec/fusuma/plugin/sendkey/keyboard_spec.rb +0 -199
- data/spec/fusuma/plugin/sendkey_spec.rb +0 -7
- data/spec/helpers/config_helper.rb +0 -16
- data/spec/spec_helper.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 863f4caf17a75bd03010d34cc01a493ad7dfc327a4e4c9c05ed3ecae91f57286
|
4
|
+
data.tar.gz: 6a64a753da83d4561c5d7384366d3596aac6b4d8c7aaad082187d943f4771d91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e016af2afb00bc864a57dc0c5cc36935e6d35d132cb268de9c18e1aa8062c896fcc8febc952f7a1b823f055bb7eb51b2e4e81bbef1a8002807dfc136cc938884
|
7
|
+
data.tar.gz: 896772bbd1dc67818cff10a3d8bacc1d582370b5075af0df0e9d4a6f32f497a2024c5cf80d5794367d69547b334d95202dfa50ef5888576b26f4e3fd84b1d105
|
@@ -1,29 +1,28 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
lib = File.expand_path(
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require
|
5
|
+
require "fusuma/plugin/sendkey/version"
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
|
-
spec.name
|
9
|
-
spec.version
|
10
|
-
spec.authors
|
11
|
-
spec.email
|
8
|
+
spec.name = "fusuma-plugin-sendkey"
|
9
|
+
spec.version = Fusuma::Plugin::Sendkey::VERSION
|
10
|
+
spec.authors = ["iberianpig"]
|
11
|
+
spec.email = ["yhkyky@gmail.com"]
|
12
12
|
|
13
|
-
spec.summary
|
14
|
-
spec.description
|
15
|
-
spec.homepage
|
16
|
-
spec.license
|
13
|
+
spec.summary = "Fusuma plugin to send keyboard events"
|
14
|
+
spec.description = "Fusuma::Plugin::Sendkey emulate keyboard events with evdev"
|
15
|
+
spec.homepage = "https://github.com/iberianpig/fusuma-plugin-sendkey"
|
16
|
+
spec.license = "MIT"
|
17
17
|
|
18
18
|
# Specify which files should be added to the gem when it is released.
|
19
|
-
spec.files
|
20
|
-
spec.
|
21
|
-
spec.
|
22
|
-
spec.
|
23
|
-
spec.
|
24
|
-
spec.required_ruby_version = '>= 2.5.1' # https://packages.ubuntu.com/search?keywords=ruby&searchon=names&exact=1&suite=all§ion=main
|
19
|
+
spec.files = Dir["{bin,lib,exe}/**/*", "LICENSE*", "README*", "*.gemspec"]
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
spec.required_ruby_version = ">= 2.5.1" # https://packages.ubuntu.com/search?keywords=ruby&searchon=names&exact=1&suite=all§ion=main
|
25
24
|
# support bionic (18.04LTS) 2.5.1
|
26
25
|
|
27
|
-
spec.add_dependency
|
28
|
-
spec.add_dependency
|
26
|
+
spec.add_dependency "fusuma", "~> 2.0"
|
27
|
+
spec.add_dependency "revdev"
|
29
28
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "../sendkey/keyboard"
|
4
4
|
|
5
5
|
module Fusuma
|
6
6
|
module Plugin
|
@@ -34,14 +34,17 @@ module Fusuma
|
|
34
34
|
# @param event [Event]
|
35
35
|
# @return [nil]
|
36
36
|
def _execute(event)
|
37
|
-
keyboard.type(
|
37
|
+
keyboard.type(
|
38
|
+
param: search_param(event),
|
39
|
+
keep: search_keypress(event)
|
40
|
+
)
|
38
41
|
end
|
39
42
|
|
40
43
|
# check executable
|
41
44
|
# @param event [Event]
|
42
45
|
# @return [TrueClass, FalseClass]
|
43
46
|
def executable?(event)
|
44
|
-
event.tag.end_with?(
|
47
|
+
event.tag.end_with?("_detector") &&
|
45
48
|
event.record.type == :index &&
|
46
49
|
keyboard.valid?(param: search_param(event))
|
47
50
|
end
|
@@ -59,6 +62,15 @@ module Fusuma
|
|
59
62
|
index = Config::Index.new([*event.record.index.keys, :sendkey])
|
60
63
|
Config.search(index)
|
61
64
|
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
|
62
74
|
end
|
63
75
|
end
|
64
76
|
end
|
@@ -1,15 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "revdev"
|
4
|
+
require "fusuma/device"
|
5
5
|
|
6
|
-
require_relative
|
6
|
+
require_relative "./device"
|
7
7
|
|
8
8
|
module Fusuma
|
9
9
|
module Plugin
|
10
10
|
module Sendkey
|
11
11
|
# Emulate Keyboard
|
12
12
|
class Keyboard
|
13
|
+
INTERVAL = 0.01
|
14
|
+
|
13
15
|
MODIFIER_KEY_CODES = %w[
|
14
16
|
KEY_CAPSLOCK
|
15
17
|
KEY_LEFTALT
|
@@ -27,7 +29,7 @@ module Fusuma
|
|
27
29
|
end
|
28
30
|
|
29
31
|
def initialize(name_pattern: nil)
|
30
|
-
name_pattern ||=
|
32
|
+
name_pattern ||= "keyboard|Keyboard|KEYBOARD"
|
31
33
|
device = Keyboard.find_device(name_pattern: name_pattern)
|
32
34
|
|
33
35
|
if device.nil?
|
@@ -38,77 +40,85 @@ module Fusuma
|
|
38
40
|
@device = Device.new(path: "/dev/input/#{device.id}")
|
39
41
|
end
|
40
42
|
|
41
|
-
attr_reader :device
|
42
|
-
|
43
43
|
# @param param [String]
|
44
44
|
# @param keep [String]
|
45
|
-
def type(param:)
|
45
|
+
def type(param:, keep: "")
|
46
46
|
return unless param.is_a?(String)
|
47
47
|
|
48
|
-
param_keycodes =
|
48
|
+
param_keycodes = param_to_keycodes(param)
|
49
|
+
keep_keycodes = param_to_keycodes(keep)
|
50
|
+
|
51
|
+
type_keycodes = param_keycodes - keep_keycodes
|
52
|
+
# release other modifier keys before sending key
|
49
53
|
clear_modifiers(MODIFIER_KEY_CODES - param_keycodes)
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
+
type_keycodes.each { |keycode| keydown(keycode) && key_sync }
|
55
|
+
type_keycodes.reverse_each { |keycode| keyup(keycode) && key_sync }
|
56
|
+
end
|
57
|
+
|
58
|
+
def keydown(keycode)
|
59
|
+
send_event(code: keycode, press: true)
|
60
|
+
end
|
61
|
+
|
62
|
+
def keyup(keycode)
|
63
|
+
send_event(code: keycode, press: false)
|
54
64
|
end
|
55
65
|
|
56
66
|
# @param param [String]
|
57
67
|
def valid?(param:)
|
58
68
|
return unless param.is_a?(String)
|
59
69
|
|
60
|
-
keycodes =
|
70
|
+
keycodes = param_to_keycodes(param)
|
61
71
|
keycodes.all? { |keycode| support?(keycode) }
|
62
72
|
end
|
63
73
|
|
64
|
-
def
|
74
|
+
def send_event(code:, press: true)
|
65
75
|
event = Revdev::InputEvent.new(
|
66
76
|
nil,
|
67
77
|
Revdev.const_get(:EV_KEY),
|
68
|
-
Revdev.const_get(
|
78
|
+
Revdev.const_get(code),
|
69
79
|
press ? 1 : 0
|
70
80
|
)
|
71
81
|
@device.write_event(event)
|
72
82
|
end
|
73
83
|
|
74
|
-
def key_sync
|
84
|
+
def key_sync
|
75
85
|
event = Revdev::InputEvent.new(
|
76
86
|
nil,
|
77
87
|
Revdev.const_get(:EV_SYN),
|
78
88
|
Revdev.const_get(:SYN_REPORT),
|
79
|
-
|
89
|
+
0
|
80
90
|
)
|
81
91
|
@device.write_event(event)
|
92
|
+
sleep(INTERVAL)
|
82
93
|
end
|
83
94
|
|
84
95
|
def support?(keycode)
|
85
96
|
@supported_code ||= {}
|
86
|
-
@supported_code[keycode] ||=
|
87
|
-
true
|
88
|
-
else
|
89
|
-
search_candidates(keycode: keycode)
|
90
|
-
end
|
97
|
+
@supported_code[keycode] ||= find_code(keycode: keycode)
|
91
98
|
end
|
92
99
|
|
93
|
-
def
|
94
|
-
query = keycode&.upcase&.gsub(
|
100
|
+
def warn_undefined_codes(keycode:)
|
101
|
+
query = keycode&.upcase&.gsub("KEY_", "")
|
95
102
|
|
96
103
|
candidates = search_codes(query: query)
|
97
104
|
|
98
|
-
warn "Did you mean? #{candidates.join(
|
105
|
+
warn "Did you mean? #{candidates.join(" / ")}" unless candidates.empty?
|
99
106
|
warn "sendkey: #{remove_prefix(keycode)} is unsupported."
|
100
107
|
end
|
101
108
|
|
102
109
|
def search_codes(query: nil)
|
103
110
|
Revdev.constants
|
104
|
-
|
105
|
-
|
111
|
+
.select { |c| c[/KEY_.*#{query}.*/] }
|
112
|
+
.map { |c| c.to_s.gsub("KEY_", "") }
|
106
113
|
end
|
107
114
|
|
108
115
|
def find_code(keycode: nil)
|
109
|
-
query = keycode&.upcase&.gsub(
|
116
|
+
query = keycode&.upcase&.gsub("KEY_", "")
|
117
|
+
|
118
|
+
result = Revdev.constants.find { |c| c == "KEY_#{query}".to_sym }
|
110
119
|
|
111
|
-
|
120
|
+
warn_undefined_codes(keycode: keycode) unless result
|
121
|
+
result
|
112
122
|
end
|
113
123
|
|
114
124
|
def keycode_const(keycode)
|
@@ -117,21 +127,23 @@ module Fusuma
|
|
117
127
|
|
118
128
|
# @param [Array<String>] keycodes to be released
|
119
129
|
def clear_modifiers(keycodes)
|
120
|
-
keycodes.each { |code|
|
130
|
+
keycodes.each { |code| send_event(code: code, press: false) }
|
121
131
|
end
|
122
132
|
|
123
|
-
|
124
|
-
|
125
|
-
def
|
126
|
-
param.split(
|
133
|
+
# @param [String]
|
134
|
+
# @return [Array<String>]
|
135
|
+
def param_to_keycodes(param)
|
136
|
+
param.split("+").map { |keyname| add_key_prefix(keyname) }
|
127
137
|
end
|
128
138
|
|
129
|
-
|
139
|
+
private
|
140
|
+
|
141
|
+
def add_key_prefix(code)
|
130
142
|
"KEY_#{code.upcase}"
|
131
143
|
end
|
132
144
|
|
133
145
|
def remove_prefix(keycode)
|
134
|
-
keycode.gsub(
|
146
|
+
keycode.gsub("KEY_", "")
|
135
147
|
end
|
136
148
|
end
|
137
149
|
end
|
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.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- iberianpig
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fusuma
|
@@ -57,11 +57,6 @@ files:
|
|
57
57
|
- lib/fusuma/plugin/sendkey/device.rb
|
58
58
|
- lib/fusuma/plugin/sendkey/keyboard.rb
|
59
59
|
- lib/fusuma/plugin/sendkey/version.rb
|
60
|
-
- spec/fusuma/plugin/executors/sendkey_executor_spec.rb
|
61
|
-
- spec/fusuma/plugin/sendkey/keyboard_spec.rb
|
62
|
-
- spec/fusuma/plugin/sendkey_spec.rb
|
63
|
-
- spec/helpers/config_helper.rb
|
64
|
-
- spec/spec_helper.rb
|
65
60
|
homepage: https://github.com/iberianpig/fusuma-plugin-sendkey
|
66
61
|
licenses:
|
67
62
|
- MIT
|
@@ -81,13 +76,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
76
|
- !ruby/object:Gem::Version
|
82
77
|
version: '0'
|
83
78
|
requirements: []
|
84
|
-
rubygems_version: 3.
|
79
|
+
rubygems_version: 3.3.26
|
85
80
|
signing_key:
|
86
81
|
specification_version: 4
|
87
82
|
summary: Fusuma plugin to send keyboard events
|
88
|
-
test_files:
|
89
|
-
- spec/fusuma/plugin/sendkey_spec.rb
|
90
|
-
- spec/fusuma/plugin/sendkey/keyboard_spec.rb
|
91
|
-
- spec/fusuma/plugin/executors/sendkey_executor_spec.rb
|
92
|
-
- spec/helpers/config_helper.rb
|
93
|
-
- spec/spec_helper.rb
|
83
|
+
test_files: []
|
@@ -1,138 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
require 'fusuma/plugin/executors/executor'
|
6
|
-
require 'fusuma/plugin/events/event'
|
7
|
-
require 'fusuma/plugin/events/records/index_record'
|
8
|
-
|
9
|
-
require './lib/fusuma/plugin/executors/sendkey_executor'
|
10
|
-
|
11
|
-
module Fusuma
|
12
|
-
module Plugin
|
13
|
-
module Executors
|
14
|
-
RSpec.describe SendkeyExecutor do
|
15
|
-
around do |example|
|
16
|
-
ConfigHelper.load_config_yml = <<~CONFIG
|
17
|
-
dummy:
|
18
|
-
1:
|
19
|
-
direction:
|
20
|
-
sendkey: KEY_CODE
|
21
|
-
|
22
|
-
plugin:
|
23
|
-
executors:
|
24
|
-
sendkey_executor:
|
25
|
-
device_name: dummy
|
26
|
-
CONFIG
|
27
|
-
|
28
|
-
example.run
|
29
|
-
|
30
|
-
Config.custom_path = nil
|
31
|
-
end
|
32
|
-
|
33
|
-
before do
|
34
|
-
index = Config::Index.new([:dummy, 1, :direction])
|
35
|
-
record = Events::Records::IndexRecord.new(index: index)
|
36
|
-
@event = Events::Event.new(tag: 'dummy_detector', record: record)
|
37
|
-
@executor = described_class.new
|
38
|
-
|
39
|
-
@keyboard = instance_double(Sendkey::Keyboard)
|
40
|
-
|
41
|
-
allow(@executor).to receive(:keyboard).and_return @keyboard
|
42
|
-
end
|
43
|
-
|
44
|
-
describe '#execute' do
|
45
|
-
before do
|
46
|
-
allow(Process).to receive(:daemon).with(true)
|
47
|
-
allow(Process).to receive(:detach).with(anything)
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'fork' do
|
51
|
-
expect(@executor).to receive(:fork).and_yield do |block_context|
|
52
|
-
expect(block_context).to receive(:_execute).with(@event)
|
53
|
-
end
|
54
|
-
|
55
|
-
@executor.execute(@event)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe '#_execute' do
|
60
|
-
it 'send KEY_CODE message to keybard' do
|
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)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe '#executable?' do
|
68
|
-
before do
|
69
|
-
allow(@keyboard).to receive(:valid?).with(param: 'MODIFIER_CODE+KEY_CODE')
|
70
|
-
.and_return true
|
71
|
-
allow(@keyboard).to receive(:valid?).with(param: 'KEY_CODE')
|
72
|
-
.and_return true
|
73
|
-
allow(@keyboard).to receive(:valid?).with(param: 'INVALID_CODE')
|
74
|
-
.and_return false
|
75
|
-
end
|
76
|
-
|
77
|
-
context 'when given valid event tagged as xxxx_detector' do
|
78
|
-
it { expect(@executor).to be_executable(@event) }
|
79
|
-
end
|
80
|
-
|
81
|
-
context 'when given INVALID event tagged as invalid_tag' do
|
82
|
-
before do
|
83
|
-
@event.tag = 'invalid_tag'
|
84
|
-
end
|
85
|
-
|
86
|
-
it { expect(@executor).not_to be_executable(@event) }
|
87
|
-
end
|
88
|
-
|
89
|
-
context "when sendkey: 'MODIFIER_CODE+KEY_CODE'" do
|
90
|
-
around do |example|
|
91
|
-
ConfigHelper.load_config_yml = <<~CONFIG
|
92
|
-
dummy:
|
93
|
-
1:
|
94
|
-
direction:
|
95
|
-
sendkey: 'MODIFIER_CODE+KEY_CODE'
|
96
|
-
plugin:
|
97
|
-
executors:
|
98
|
-
sendkey_executor:
|
99
|
-
device_name: dummy
|
100
|
-
CONFIG
|
101
|
-
|
102
|
-
example.run
|
103
|
-
|
104
|
-
Config.custom_path = nil
|
105
|
-
end
|
106
|
-
|
107
|
-
it 'returns true' do
|
108
|
-
expect(@executor).to be_executable(@event)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
context "when sendkey: 'INVALID_CODE'" do
|
113
|
-
around do |example|
|
114
|
-
ConfigHelper.load_config_yml = <<~CONFIG
|
115
|
-
dummy:
|
116
|
-
1:
|
117
|
-
direction:
|
118
|
-
sendkey: 'INVALID_CODE'
|
119
|
-
plugin:
|
120
|
-
executors:
|
121
|
-
sendkey_executor:
|
122
|
-
device_name: dummy
|
123
|
-
CONFIG
|
124
|
-
|
125
|
-
example.run
|
126
|
-
|
127
|
-
Config.custom_path = nil
|
128
|
-
end
|
129
|
-
|
130
|
-
it 'returns true' do
|
131
|
-
expect(@executor).not_to be_executable(@event)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
@@ -1,199 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
require './lib/fusuma/plugin/sendkey/keyboard'
|
6
|
-
|
7
|
-
module Fusuma
|
8
|
-
module Plugin
|
9
|
-
module Sendkey
|
10
|
-
RSpec.describe Keyboard do
|
11
|
-
describe '#new' do
|
12
|
-
context 'when keyboard is found' do
|
13
|
-
before do
|
14
|
-
dummy_keyboard = Fusuma::Device.new(name: 'dummy keyboard')
|
15
|
-
allow(described_class)
|
16
|
-
.to receive(:find_device)
|
17
|
-
.and_return(dummy_keyboard)
|
18
|
-
allow(Sendkey::Device).to receive(:new).and_return('dummy')
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'does not raise error' do
|
22
|
-
expect { described_class.new }.not_to raise_error
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'when keyboard is not found' do
|
27
|
-
before do
|
28
|
-
allow(described_class)
|
29
|
-
.to receive(:find_device)
|
30
|
-
.and_return(nil)
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'does not raise error' do
|
34
|
-
expect { described_class.new }.to raise_error SystemExit
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context 'when detected device name is Keyboard (Capitarized)' do
|
39
|
-
before do
|
40
|
-
other_device = Fusuma::Device.new(name: 'Keyboard', id: 'dummy')
|
41
|
-
|
42
|
-
allow(described_class)
|
43
|
-
.to receive(:find_device)
|
44
|
-
.and_return(other_device)
|
45
|
-
allow(Sendkey::Device).to receive(:new).and_return('dummy')
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'does not raise error' do
|
49
|
-
expect { described_class.new }.not_to raise_error
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context 'when detected device name is KEYBOARD (Upper case)' do
|
54
|
-
before do
|
55
|
-
other_device = Fusuma::Device.new(name: 'KEYBOARD', id: 'dummy')
|
56
|
-
allow(described_class)
|
57
|
-
.to receive(:find_device)
|
58
|
-
.and_return(other_device)
|
59
|
-
allow(Sendkey::Device).to receive(:new).and_return('dummy')
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'does not raise error' do
|
63
|
-
expect { described_class.new }.not_to raise_error
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context 'with given name pattern' do
|
68
|
-
before do
|
69
|
-
specified_device = Fusuma::Device.new(
|
70
|
-
name: 'Awesome KEY/BOARD input device',
|
71
|
-
id: 'dummy'
|
72
|
-
)
|
73
|
-
allow(Fusuma::Device).to receive(:all).and_return([specified_device])
|
74
|
-
allow(Sendkey::Device).to receive(:new).and_return('dummy')
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'does not raise error' do
|
78
|
-
expect { described_class.new(name_pattern: 'Awesome KEY/BOARD') }.not_to raise_error
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
context 'when name pattern (use default) is not given' do
|
83
|
-
subject { -> { described_class.new(name_pattern: nil) } }
|
84
|
-
|
85
|
-
before do
|
86
|
-
allow(Sendkey::Device).to receive(:new).and_return('dummy')
|
87
|
-
end
|
88
|
-
|
89
|
-
context 'when exist device named keyboard(lower-case)' do
|
90
|
-
before do
|
91
|
-
specified_device = Fusuma::Device.new(
|
92
|
-
name: 'keyboard',
|
93
|
-
id: 'dummy'
|
94
|
-
)
|
95
|
-
allow(Fusuma::Device).to receive(:all).and_return([specified_device])
|
96
|
-
end
|
97
|
-
|
98
|
-
it { is_expected.not_to raise_error }
|
99
|
-
end
|
100
|
-
|
101
|
-
context 'when exist device named Keyboard(Capital-case)' do
|
102
|
-
before do
|
103
|
-
specified_device = Fusuma::Device.new(
|
104
|
-
name: 'Keyboard',
|
105
|
-
id: 'dummy'
|
106
|
-
)
|
107
|
-
allow(Fusuma::Device).to receive(:all).and_return([specified_device])
|
108
|
-
end
|
109
|
-
|
110
|
-
it { is_expected.not_to raise_error }
|
111
|
-
end
|
112
|
-
|
113
|
-
context 'when exist device named KEYBOARD(UPPER case)' do
|
114
|
-
before do
|
115
|
-
specified_device = Fusuma::Device.new(
|
116
|
-
name: 'KEYBOARD',
|
117
|
-
id: 'dummy'
|
118
|
-
)
|
119
|
-
allow(Fusuma::Device).to receive(:all).and_return([specified_device])
|
120
|
-
end
|
121
|
-
|
122
|
-
it { is_expected.not_to raise_error }
|
123
|
-
end
|
124
|
-
|
125
|
-
context 'when exist no device named keyboard|Keyboard|KEYBOARD' do
|
126
|
-
before do
|
127
|
-
specified_device = Fusuma::Device.new(
|
128
|
-
name: 'KEY-BOARD',
|
129
|
-
id: 'dummy'
|
130
|
-
)
|
131
|
-
allow(Fusuma::Device).to receive(:all).and_return([specified_device])
|
132
|
-
end
|
133
|
-
|
134
|
-
it { is_expected.to raise_error(SystemExit) }
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
describe '#type' do
|
140
|
-
before do
|
141
|
-
allow(described_class)
|
142
|
-
.to receive(:find_device)
|
143
|
-
.and_return(Fusuma::Device.new(name: 'dummy keyboard'))
|
144
|
-
|
145
|
-
@device = instance_double(Sendkey::Device)
|
146
|
-
allow(@device).to receive(:write_event).with(anything)
|
147
|
-
# allow(@device).to receive(:valid?).with(param: 'KEY_A')
|
148
|
-
|
149
|
-
allow(Sendkey::Device).to receive(:new).and_return(@device)
|
150
|
-
|
151
|
-
@keyboard = described_class.new
|
152
|
-
end
|
153
|
-
|
154
|
-
it 'presses key KEY_A and release KEY_A' do
|
155
|
-
expect(@keyboard).to receive(:clear_modifiers).ordered
|
156
|
-
expect(@keyboard).to receive(:key_event).with(keycode: 'KEY_A', press: true).ordered
|
157
|
-
expect(@keyboard).to receive(:key_event).with(keycode: 'KEY_A', press: false).ordered
|
158
|
-
@keyboard.type(param: 'A')
|
159
|
-
end
|
160
|
-
|
161
|
-
context 'with modifier keys' do
|
162
|
-
before do
|
163
|
-
@keys = 'LEFTSHIFT+A'
|
164
|
-
end
|
165
|
-
|
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
|
172
|
-
expect(@keyboard).to receive(:clear_modifiers).ordered
|
173
|
-
expect(@keyboard).to receive(:key_event).with(keycode: 'KEY_LEFTSHIFT', press: true).ordered
|
174
|
-
expect(@keyboard).to receive(:key_event).with(keycode: 'KEY_A', press: true).ordered
|
175
|
-
expect(@keyboard).to receive(:key_event).with(keycode: 'KEY_A', press: false).ordered
|
176
|
-
expect(@keyboard).to receive(:key_event).with(keycode: 'KEY_LEFTSHIFT', press: false).ordered
|
177
|
-
@keyboard.type(param: @keys)
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
context 'with multiple keys' do
|
182
|
-
before do
|
183
|
-
@keys = 'A+B'
|
184
|
-
end
|
185
|
-
|
186
|
-
it 'types AB' do
|
187
|
-
expect(@keyboard).to receive(:clear_modifiers).ordered
|
188
|
-
expect(@keyboard).to receive(:key_event).with(keycode: 'KEY_A', press: true).ordered
|
189
|
-
expect(@keyboard).to receive(:key_event).with(keycode: 'KEY_B', press: true).ordered
|
190
|
-
expect(@keyboard).to receive(:key_event).with(keycode: 'KEY_B', press: false).ordered
|
191
|
-
expect(@keyboard).to receive(:key_event).with(keycode: 'KEY_A', press: false).ordered
|
192
|
-
@keyboard.type(param: @keys)
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|
198
|
-
end
|
199
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'tempfile'
|
4
|
-
require 'fusuma/config'
|
5
|
-
|
6
|
-
module Fusuma
|
7
|
-
module ConfigHelper
|
8
|
-
module_function
|
9
|
-
|
10
|
-
def load_config_yml=(string)
|
11
|
-
Config.custom_path = Tempfile.open do |temp_file|
|
12
|
-
temp_file.tap { |f| f.write(string) }
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'helpers/config_helper'
|
5
|
-
|
6
|
-
RSpec.configure do |config|
|
7
|
-
# Enable flags like --only-failures and --next-failure
|
8
|
-
config.example_status_persistence_file_path = '.rspec_status'
|
9
|
-
|
10
|
-
# Disable RSpec exposing methods globally on `Module` and `main`
|
11
|
-
config.disable_monkey_patching!
|
12
|
-
|
13
|
-
config.expect_with :rspec do |c|
|
14
|
-
c.syntax = :expect
|
15
|
-
end
|
16
|
-
|
17
|
-
config.include(Fusuma::ConfigHelper)
|
18
|
-
end
|