fusuma-plugin-sendkey 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3087cd15e356a48d1f8fd2398daed7f6153d4e9c005db98ffad34627b357bc65
|
4
|
+
data.tar.gz: 0dd9da2ff1ef200d76691f9a3e72fe8efff68cea8e6eef1c448387df6154daf1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 830a41f20bfa018ceff548a8c660012947657fbd18b8e369a1033fb4f4d0e2f665ade047eeafa9d3ba3ade8ba5079a1c1044cc6401b4222da20847bced619a7b
|
7
|
+
data.tar.gz: 9f8ae60d5377799ed80844ba3a218049c1a736cf7ed0e733dea347067a30fc548f6aa5c82b2311858e2474f8ad0d1df8a3e8739730d9e301664a784d2a073b26
|
data/README.md
CHANGED
@@ -7,6 +7,12 @@ module Fusuma
|
|
7
7
|
module Executors
|
8
8
|
# Control Window or Workspaces by executing wctrl
|
9
9
|
class SendkeyExecutor < Executor
|
10
|
+
def config_param_types
|
11
|
+
{
|
12
|
+
'device_path': String
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
10
16
|
# execute sendkey command
|
11
17
|
# @param event [Event]
|
12
18
|
# @return [nil]
|
@@ -35,7 +41,10 @@ module Fusuma
|
|
35
41
|
# @return [String]
|
36
42
|
# @return [NilClass]
|
37
43
|
def search_command(event)
|
38
|
-
@keyboard ||=
|
44
|
+
@keyboard ||= begin
|
45
|
+
device = Sendkey::Device.new(path: config_params(:device_path))
|
46
|
+
Sendkey::Keyboard.new(device: device)
|
47
|
+
end
|
39
48
|
@keyboard.type_command(param: search_param(event))
|
40
49
|
end
|
41
50
|
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'evdev'
|
4
|
+
|
5
|
+
module Fusuma
|
6
|
+
module Plugin
|
7
|
+
module Sendkey
|
8
|
+
# handle Evdev device
|
9
|
+
class Device
|
10
|
+
attr_reader :device_id
|
11
|
+
def initialize(path: nil)
|
12
|
+
return if path && (@evdev = Evdev.new(path))
|
13
|
+
|
14
|
+
(0..99).lazy.find do |i|
|
15
|
+
begin
|
16
|
+
evdev = Evdev.new("/dev/input/event#{i}")
|
17
|
+
@evdev = evdev if evdev.supports_event?(convert_keycode('LEFTALT'))
|
18
|
+
rescue Errno::ENOENT # No such file or directory
|
19
|
+
false
|
20
|
+
# TODO: rescue Errno::EACCES
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def path
|
26
|
+
raise 'Keyboard is not found' if @evdev.nil?
|
27
|
+
|
28
|
+
@path ||= @evdev.file.path
|
29
|
+
end
|
30
|
+
|
31
|
+
def support?(code)
|
32
|
+
keycode = convert_keycode(code)
|
33
|
+
@evdev.supports_event?(keycode)
|
34
|
+
rescue NameError
|
35
|
+
candidates = search_codes(code: code)
|
36
|
+
|
37
|
+
warn "Did you mean? #{candidates.join(' / ')}" unless candidates.empty?
|
38
|
+
|
39
|
+
false
|
40
|
+
end
|
41
|
+
|
42
|
+
def search_codes(code: nil)
|
43
|
+
query = code&.upcase
|
44
|
+
LinuxInput.constants
|
45
|
+
.select { |c| c[/KEY_.*#{query}.*/] }
|
46
|
+
.select { |c| @evdev.supports_event?(c) }
|
47
|
+
.map { |c| c.to_s.gsub('KEY_', '') }
|
48
|
+
end
|
49
|
+
|
50
|
+
def emulate(code:, press: true)
|
51
|
+
keycode = convert_keycode(code)
|
52
|
+
v = press ? 1 : 0
|
53
|
+
"evemu-event #{path} --type EV_KEY --code #{keycode} --value #{v} --sync"
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def convert_keycode(code)
|
59
|
+
"KEY_#{code.upcase}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -1,101 +1,54 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
require_relative './device.rb'
|
4
|
+
|
5
|
+
module Fusuma
|
6
|
+
module Plugin
|
7
|
+
module Sendkey
|
8
|
+
# Emulate Keyboard
|
9
|
+
class Keyboard
|
10
|
+
def initialize(device: nil)
|
11
|
+
@device = device || Device.new
|
12
|
+
end
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
14
|
+
# @param param [String]
|
15
|
+
def type_command(param:)
|
16
|
+
return unless param.is_a?(String)
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
18
|
+
codes = param.split('+')
|
19
|
+
press_commands = codes.map { |code| press_command(code) }
|
20
|
+
release_commands = codes.reverse.map { |code| release_command(code) }
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
def press_command(code)
|
24
|
-
return unless support?(code)
|
22
|
+
(press_commands | release_commands).join(' && ')
|
23
|
+
end
|
25
24
|
|
26
|
-
|
27
|
-
|
25
|
+
def press_command(code)
|
26
|
+
return unless support?(code)
|
28
27
|
|
29
|
-
|
30
|
-
|
28
|
+
@device.emulate(code: code, press: true)
|
29
|
+
end
|
31
30
|
|
32
|
-
|
33
|
-
|
31
|
+
def release_command(code)
|
32
|
+
return unless support?(code)
|
34
33
|
|
35
|
-
|
36
|
-
|
37
|
-
@supported_code[code] ||= if @device.support?(code)
|
38
|
-
true
|
39
|
-
else
|
40
|
-
warn "sendkey: #{code} is unsupported."
|
41
|
-
warn 'Please check your config.yml.'
|
42
|
-
exit 1
|
43
|
-
end
|
44
|
-
end
|
34
|
+
@device.emulate(code: code, press: false)
|
35
|
+
end
|
45
36
|
|
46
|
-
|
47
|
-
|
48
|
-
|
37
|
+
def support?(code)
|
38
|
+
@supported_code ||= {}
|
39
|
+
@supported_code[code] ||= if @device.support?(code)
|
40
|
+
true
|
41
|
+
else
|
42
|
+
warn "sendkey: #{code} is unsupported."
|
43
|
+
warn 'Please check your config.yml.'
|
44
|
+
exit 1
|
45
|
+
end
|
46
|
+
end
|
49
47
|
|
50
|
-
|
51
|
-
|
52
|
-
attr_reader :device_id
|
53
|
-
def initialize
|
54
|
-
(0..99).lazy.find do |i|
|
55
|
-
begin
|
56
|
-
evdev = Evdev.new("/dev/input/event#{i}")
|
57
|
-
@evdev = evdev if evdev.supports_event?(convert_keycode('LEFTALT'))
|
58
|
-
rescue Errno::ENOENT
|
59
|
-
false
|
48
|
+
def available_codes
|
49
|
+
@device.search_codes
|
60
50
|
end
|
61
51
|
end
|
62
52
|
end
|
63
|
-
|
64
|
-
def path
|
65
|
-
raise 'Keyboard is not found' if @evdev.nil?
|
66
|
-
|
67
|
-
@path ||= @evdev.file.path
|
68
|
-
end
|
69
|
-
|
70
|
-
def support?(code)
|
71
|
-
keycode = convert_keycode(code)
|
72
|
-
@evdev.supports_event?(keycode)
|
73
|
-
rescue NameError
|
74
|
-
candidates = search_codes(code: code)
|
75
|
-
|
76
|
-
warn "Did you mean? #{candidates.join(' / ')}" unless candidates.empty?
|
77
|
-
|
78
|
-
false
|
79
|
-
end
|
80
|
-
|
81
|
-
def search_codes(code: nil)
|
82
|
-
query = code&.upcase
|
83
|
-
LinuxInput.constants
|
84
|
-
.select { |c| c[/KEY_.*#{query}.*/] }
|
85
|
-
.select { |c| @evdev.supports_event?(c) }
|
86
|
-
.map { |c| c.to_s.gsub('KEY_', '') }
|
87
|
-
end
|
88
|
-
|
89
|
-
def emulate(code:, press: true)
|
90
|
-
keycode = convert_keycode(code)
|
91
|
-
v = press ? 1 : 0
|
92
|
-
"evemu-event #{path} --type EV_KEY --code #{keycode} --value #{v} --sync"
|
93
|
-
end
|
94
|
-
|
95
|
-
private
|
96
|
-
|
97
|
-
def convert_keycode(code)
|
98
|
-
"KEY_#{code.upcase}"
|
99
|
-
end
|
100
53
|
end
|
101
54
|
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.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- iberianpig
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-03-
|
11
|
+
date: 2020-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: evdev
|
@@ -201,6 +201,7 @@ files:
|
|
201
201
|
- fusuma-plugin-sendkey.gemspec
|
202
202
|
- lib/fusuma/plugin/executors/sendkey_executor.rb
|
203
203
|
- lib/fusuma/plugin/sendkey.rb
|
204
|
+
- lib/fusuma/plugin/sendkey/device.rb
|
204
205
|
- lib/fusuma/plugin/sendkey/keyboard.rb
|
205
206
|
- lib/fusuma/plugin/sendkey/version.rb
|
206
207
|
homepage: https://github.com/iberianpig/fusuma-plugin-sendkey
|