xdrp 0.1.0

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.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +3 -0
  4. data/lib/xdrp.rb +221 -0
  5. metadata +131 -0
  6. metadata.gz.sig +0 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7a6300209a76178b4bffc1b5d3f319597aa206351e89a87b78bba23e41600a14
4
+ data.tar.gz: 8796a1037a75704e0dbd4741a1b33c27e54047c2817818be60e0160eb490f830
5
+ SHA512:
6
+ metadata.gz: a758de2052e2302be9506e381aa3fe48d3f26d2853efe8c3bcc64259e2f7ab368851f3b15ef347db0f21092e1a0f696507bff748d63391671ca6f854524f8639
7
+ data.tar.gz: 2b8e0d980c43f507ed25815aaafd22a13da09fd71d6bd5310defcf8c298fd8c514f5091112bff0a02a8fc1e18066e507fc9a8e92732afbc6f373a2118380ff09
Binary file
@@ -0,0 +1,3 @@
1
+ "��e����i+t��_=�!�4���Ӝ�Y��|K*t��<�@��� ^�qA,��2%�ގ�;6ϰ4����J��dmW#���n��O��0^�s���,��ܷ���(��cƫ�(w�����u(.l�}sɽwd�5�׾�{�����m_��%���
2
+ � �mq�_&'��Y�$���U ��K��� �%=���J���E�Y�9^s��W�Z3��_��(��+;�A����F������oG�Mq��aC�"��w�M� zJ
3
+ �bxz���Z��N�>����j���1������u$���shz��Hen!5c��xy��9�cP x�����hQԃ�Έ�e~��C
@@ -0,0 +1,221 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: xdrp.rb
4
+
5
+ # description: A basic macro recorder for GNU/Linux which uses
6
+ # program xinput to capture input events.
7
+
8
+ require 'rxfhelper'
9
+ require "xdo/mouse"
10
+ require "xdo/xwindow"
11
+ require "xdo/keyboard"
12
+ require 'xinput_wrapper'
13
+
14
+
15
+ MOUSE = 1
16
+ KEYBOARD = 2
17
+ KEYBOARD_MOUSE = 3
18
+
19
+
20
+ module Xdrp
21
+
22
+ class Recorder
23
+
24
+ attr_reader :xml
25
+
26
+ # level:
27
+ # 1 = mouse
28
+ # 2 = keyboard
29
+ # 3 = keyboard + mouse
30
+
31
+ def initialize(levelx=KEYBOARD_MOUSE, level: levelx, debug: false)
32
+
33
+ @xiw = XInputWrapper.new(verbose: true, debug: debug, callback: self)
34
+
35
+ @mouse, @keyboard = false, false
36
+
37
+ case level
38
+ when 1
39
+ @mouse = true
40
+ when 2
41
+ @keyboard = true
42
+ when 3
43
+ @mouse, @keyboard = true, true
44
+ end
45
+ end
46
+
47
+ def on_keypress(key, keycode, modifier=nil)
48
+
49
+ if @debug then
50
+ puts 'key: ' + key.inspect
51
+ puts 'keycode: ' + keycode.inspect
52
+ puts 'modifier: ' + modifier.inspect
53
+ end
54
+
55
+ stop() if modifier and modifier[0] == :alt and key == :z
56
+
57
+ return unless @keyboard
58
+
59
+ add_sleep() if Time.now > (@t1 + 2)
60
+
61
+
62
+ if @a.length >= 1 and @a[-1][0] == :type then
63
+
64
+ if modifier.nil? or (modifier and modifier.empty?) then
65
+ @a[-1][2] += key.to_s
66
+ else
67
+ @a << [modifier.first, {key: key}] if modifier.length < 2
68
+ end
69
+
70
+ @a.last.last.gsub('{space}',' ')
71
+
72
+ else
73
+
74
+ a = case key.to_s[/^\{(\w+)\}$/,1]
75
+ when 'enter'
76
+ [:enter]
77
+ when 'tab'
78
+ [:tab]
79
+ else
80
+ [:type, {}, key.to_s]
81
+ end
82
+
83
+ @a << a
84
+
85
+ end
86
+
87
+ end
88
+
89
+ def on_mousedown(button, x, y)
90
+
91
+ return unless @mouse
92
+
93
+ puts "mouse %s button down at %s, %s" % [button, x, y] if @debug
94
+ add_sleep() if Time.now > (@t1 + 2)
95
+ @a << [:mouse, {click: button, x: x, y: y}]
96
+
97
+ end
98
+
99
+ def on_mouseup(button, x, y)
100
+
101
+ return unless @mouse
102
+
103
+ puts "mouse %s button up at %s, %s" % [button, x, y] if @debug
104
+ end
105
+
106
+ def on_mousemove(x, y)
107
+
108
+ return unless @mouse
109
+
110
+ puts 'mouse is moving at ' + x.to_s + ' y ' + y.to_s if @debug
111
+ add_sleep() if Time.now > (@t1 + 2)
112
+ @a << [:mousemove, {x: x, y: y}]
113
+
114
+ end
115
+
116
+ def on_mouse_scrolldown()
117
+
118
+ return unless @mouse
119
+
120
+ puts 'mouse is scrolling down' if @debug
121
+ add_sleep() if Time.now > (@t1 + 2)
122
+ @a << [:mousewheel, {scroll: 'down'}]
123
+
124
+ end
125
+
126
+ def on_mouse_scrollup()
127
+
128
+ return unless @mouse
129
+
130
+ puts 'mouse is scrolling up ' if @debug
131
+ add_sleep() if Time.now > (@t1 + 2)
132
+ @a << [:mousewheel, {scroll: 'up'}]
133
+
134
+ end
135
+
136
+ def save(filepath)
137
+ File.write filepath, xml()
138
+ end
139
+
140
+ def start()
141
+
142
+ @a = []
143
+ Thread.new { @xiw.listen }
144
+ puts 'recording ...'
145
+ @t1 = Time.now
146
+
147
+ end
148
+
149
+ def stop()
150
+
151
+ @xiw.stop = true
152
+ @doc = Rexle.new(['xdrp', {}, '', *@a])
153
+ puts 'recording stopped'
154
+
155
+ end
156
+
157
+ def xml()
158
+ @doc.xml(pretty: true)
159
+ end
160
+
161
+ private
162
+
163
+ def add_sleep()
164
+ @a << [:sleep, {duration: (Time.now - @t1).round}]
165
+ @t1 = Time.now
166
+ end
167
+
168
+ end
169
+
170
+ class Player
171
+
172
+ def initialize(src, debug: false)
173
+
174
+ @debug = debug
175
+ @doc = Rexle.new(RXFHelper.read(src).first)
176
+
177
+ end
178
+
179
+ def play()
180
+
181
+ @doc.root.elements.each do |e|
182
+ puts 'e: ' + e.xml.inspect if @debug
183
+ method('xdo_' + e.name.to_s).call(e.text || e.attributes)
184
+ end
185
+
186
+ end
187
+
188
+ private
189
+
190
+ def xdo_enter(h={})
191
+ XDo::Keyboard.return
192
+ end
193
+
194
+ def xdo_mouse(click: 'left', x: 0, y: 0)
195
+ XDo::Mouse.click(x.to_i, y.to_i,
196
+ Object.const_get('XDo::Mouse::' + click.upcase))
197
+ end
198
+
199
+ def xdo_mousemove(x: 0, y: 0)
200
+ XDo::Mouse.move(x.to_i, y.to_i)
201
+ end
202
+
203
+ def xdo_mousewheel(scroll: 'down')
204
+ XDo::Mouse.wheel(Object.const_get('XDo::Mouse::' + scroll.upcase, 4))
205
+ end
206
+
207
+ def xdo_sleep(duration: 0)
208
+ sleep duration.to_f
209
+ end
210
+
211
+ def xdo_tab(h={})
212
+ XDo::Keyboard.tab
213
+ end
214
+
215
+ def xdo_type(s)
216
+ XDo::Keyboard.simulate(s.gsub('{enter}', "\n"))
217
+ end
218
+
219
+ end
220
+
221
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xdrp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
14
+ YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjAwODA0MTkxNzIzWhcN
15
+ MjEwODA0MTkxNzIzWjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
+ cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQC+0Nf7
17
+ 3r8/tK7O+C/D9z6Q8Dg8eMFjyC5LJIe1zsGoX3HaT7G6GHFlavar3XZ0UcEBOvdv
18
+ khojT/S2viTGUURzB3mQIVQnf2O9JDs9qXroyX6npMymN5XN4OlMiiriOdiFB9kk
19
+ y0L8S0Y+MUh0VOg5hN9vP9i2MrKIZKN3YD7G0eGku//a+nNYe3Q1Vq3+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2yFfGGMZBeer8GVOTtrIixZnGr7bSWglZWNDDy/x2ZTBU0jYB
36
+ V66loB9HaeHxmtMl4Ylv2wvn
37
+ -----END CERTIFICATE-----
38
+ date: 2020-08-04 00:00:00.000000000 Z
39
+ dependencies:
40
+ - !ruby/object:Gem::Dependency
41
+ name: xdo
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '0.0'
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.0.4
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '0.0'
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 0.0.4
60
+ - !ruby/object:Gem::Dependency
61
+ name: rxfhelper
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 1.0.0
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 1.0.0
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '1.0'
80
+ - !ruby/object:Gem::Dependency
81
+ name: xinput_wrapper
82
+ requirement: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: 0.7.0
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.7'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 0.7.0
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '0.7'
100
+ description:
101
+ email: james@jamesrobertson.eu
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - lib/xdrp.rb
107
+ homepage: https://github.com/jrobertson/xdrp
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubygems_version: 3.0.3
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: A basic macro recorder for GNU/Linux which uses program xinput to capture
130
+ input events.
131
+ test_files: []
Binary file