xdrp 0.1.1 → 0.2.2

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 +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/xdrp.rb +103 -32
  4. data.tar.gz.sig +0 -0
  5. metadata +80 -39
  6. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 60fef7cc9878649488946fd3ddb5ccc9f694f7da66bf02eae3cf1fcc68d7b1e2
4
- data.tar.gz: 9dc84a8b21b189a8b2b46db61a59319e434a6f8e8cb19c0f3a1eafef2f873b5e
3
+ metadata.gz: 617fbc32a4b2adaf234769104583696286e5e9b76f4bf11a0f131e107362c6ca
4
+ data.tar.gz: 91f2f6c128055b9e895bfb64449d58e0869def96bccf288b81a872a919701119
5
5
  SHA512:
6
- metadata.gz: 221037558fcef999cad7c8b90511037d65d46b9088d2a28ab7dbeb3ac843e9e36341e0124dd77014e8ed11295d3084ad51ee53b000c6bb69dede5d8f938b564d
7
- data.tar.gz: a4594ddfbacd16feefc9ba1f6de2c51db7342394469f1a5476d38f06104a1f03fd8dbc38da4bf8d308a22d6b13d4a27456f826b3cd2c6c076b14ad6261a571bb
6
+ metadata.gz: 1eaec277d3c3929b9b1b978510e1357d63125f41ae3138f03f77f1793147df35efc8bfacfd66f19b7fadabf34c9982669e5b79334a9d925f182e92c6edf6f4ba
7
+ data.tar.gz: d58741546686f94390594a42a8ca0b11fc5e2bac1827392252ac2ca108df7f86e54ed610a0e7ba2ef525fefd0941e587cc74b018e17582bddcbfd6badd3bec8e
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/xdrp.rb CHANGED
@@ -5,13 +5,16 @@
5
5
  # description: A basic macro recorder for GNU/Linux which uses
6
6
  # program xinput to capture input events.
7
7
 
8
+ require 'wmctrl'
8
9
  require 'rxfhelper'
10
+ require 'keystroker'
9
11
  require "xdo/mouse"
10
12
  require "xdo/xwindow"
11
13
  require "xdo/keyboard"
12
14
  require 'xinput_wrapper'
13
15
 
14
16
 
17
+
15
18
  MOUSE = 1
16
19
  KEYBOARD = 2
17
20
  KEYBOARD_MOUSE = 3
@@ -22,18 +25,16 @@ module Xdrp
22
25
  class Recorder
23
26
 
24
27
  attr_reader :xml
25
-
28
+
26
29
  # level:
27
30
  # 1 = mouse
28
31
  # 2 = keyboard
29
32
  # 3 = keyboard + mouse
30
33
 
31
34
  def initialize(levelx=KEYBOARD_MOUSE, level: levelx, debug: false)
32
-
33
- @xiw = XInputWrapper.new(verbose: true, debug: debug, callback: self)
34
35
 
35
36
  @mouse, @keyboard = false, false
36
-
37
+
37
38
  case level
38
39
  when 1
39
40
  @mouse = true
@@ -42,9 +43,16 @@ module Xdrp
42
43
  when 3
43
44
  @mouse, @keyboard = true, true
44
45
  end
46
+
47
+
48
+ @xiw = XInputWrapper.new(verbose: true, debug: debug, callback: self)
49
+
50
+ @wm = WMCtrl.display
51
+ @win_title = ''
52
+
45
53
  end
46
54
 
47
- def on_keypress(key, keycode, modifier=nil)
55
+ def on_keypress(key, keycode, modifier=nil)
48
56
 
49
57
  if @debug then
50
58
  puts 'key: ' + key.inspect
@@ -53,21 +61,48 @@ module Xdrp
53
61
  end
54
62
 
55
63
  stop() if modifier and modifier[0] == :alt and key == :z
56
-
57
- return unless @keyboard
64
+
65
+ return unless @keyboard
58
66
 
59
67
  add_sleep() if Time.now > (@t1 + 2)
60
-
68
+
61
69
 
62
70
  if @a.length >= 1 and @a[-1][0] == :type then
63
71
 
64
72
  if modifier.nil? or (modifier and modifier.empty?) then
65
- @a[-1][2] += key.to_s
73
+ @a[-1][2] += key.to_s.sub('{space}', ' ')
66
74
  else
67
- @a << [modifier.first, {key: key}] if modifier.length < 2
75
+
76
+ if modifier.length < 2 then
77
+
78
+ if modifier.first == :shift and (keycode.between?(10,21) \
79
+ or keycode.between?(24,35) \
80
+ or keycode.between?(38,48)) then
81
+
82
+ char = if key.to_s =~ /[a-z]/ then
83
+ key.to_s.upcase
84
+ elsif key.to_s =~ /[0-9]/
85
+ %w[) ! " £ $ % ^ & * ( ][key.to_s.to_i]
86
+ else
87
+
88
+ lsym = %i(` - = [ ] ; ' # \ , . /)
89
+
90
+ if lsym.include? key then
91
+
92
+ usym = %w(¬ _ + { } : @ ~ | < > ?)
93
+ lsym.zip(usym).to_h[key]
94
+
95
+ end
96
+
97
+ end
98
+
99
+ @a[-1][2] += char
100
+
101
+ else
102
+ @a << [modifier.first, {key: key}]
103
+ end
104
+ end
68
105
  end
69
-
70
- @a.last.last.gsub!('{space}',' ')
71
106
 
72
107
  else
73
108
 
@@ -77,7 +112,7 @@ module Xdrp
77
112
  when 'tab'
78
113
  [:tab]
79
114
  else
80
- [:type, {}, key.to_s]
115
+ [:type, {}, key.to_s.sub(/\{space\}/, ' ')]
81
116
  end
82
117
 
83
118
  @a << a
@@ -89,7 +124,8 @@ module Xdrp
89
124
  def on_mousedown(button, x, y)
90
125
 
91
126
  return unless @mouse
92
-
127
+ monitor_app()
128
+
93
129
  puts "mouse %s button down at %s, %s" % [button, x, y] if @debug
94
130
  add_sleep() if Time.now > (@t1 + 2)
95
131
  @a << [:mouse, {click: button, x: x, y: y}]
@@ -97,16 +133,15 @@ module Xdrp
97
133
  end
98
134
 
99
135
  def on_mouseup(button, x, y)
100
-
136
+
101
137
  return unless @mouse
102
-
103
138
  puts "mouse %s button up at %s, %s" % [button, x, y] if @debug
104
139
  end
105
140
 
106
141
  def on_mousemove(x, y)
107
142
 
108
143
  return unless @mouse
109
-
144
+
110
145
  puts 'mouse is moving at ' + x.to_s + ' y ' + y.to_s if @debug
111
146
  add_sleep() if Time.now > (@t1 + 2)
112
147
  @a << [:mousemove, {x: x, y: y}]
@@ -116,7 +151,7 @@ module Xdrp
116
151
  def on_mouse_scrolldown()
117
152
 
118
153
  return unless @mouse
119
-
154
+
120
155
  puts 'mouse is scrolling down' if @debug
121
156
  add_sleep() if Time.now > (@t1 + 2)
122
157
  @a << [:mousewheel, {scroll: 'down'}]
@@ -126,32 +161,32 @@ module Xdrp
126
161
  def on_mouse_scrollup()
127
162
 
128
163
  return unless @mouse
129
-
164
+
130
165
  puts 'mouse is scrolling up ' if @debug
131
166
  add_sleep() if Time.now > (@t1 + 2)
132
167
  @a << [:mousewheel, {scroll: 'up'}]
133
168
 
134
169
  end
135
-
170
+
136
171
  def save(filepath)
137
172
  File.write filepath, xml()
138
173
  end
139
174
 
140
175
  def start()
141
-
176
+
142
177
  @a = []
143
178
  Thread.new { @xiw.listen }
144
179
  puts 'recording ...'
145
180
  @t1 = Time.now
146
-
181
+
147
182
  end
148
183
 
149
184
  def stop()
150
-
185
+
151
186
  @xiw.stop = true
152
187
  @doc = Rexle.new(['xdrp', {}, '', *@a])
153
188
  puts 'recording stopped'
154
-
189
+
155
190
  end
156
191
 
157
192
  def xml()
@@ -165,22 +200,44 @@ module Xdrp
165
200
  @t1 = Time.now
166
201
  end
167
202
 
203
+ def monitor_app()
204
+
205
+ win = @wm.windows.find {|x| x.active}
206
+
207
+ if win.title != @win_title then
208
+ @win_title = win.title
209
+ @a << [:window, {activate: win.title}]
210
+ end
211
+
212
+ end
213
+
168
214
  end
169
215
 
170
216
  class Player
217
+ using ColouredText
171
218
 
172
219
  def initialize(src, debug: false)
173
220
 
174
221
  @debug = debug
175
- @doc = Rexle.new(RXFHelper.read(src).first)
222
+ @doc = Keystroker.new(src, debug: debug).to_doc
223
+ puts '@doc.xml: ' + @doc.xml if @debug
176
224
 
177
225
  end
178
226
 
179
227
  def play()
180
228
 
181
229
  @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)
230
+
231
+ if @debug then
232
+ puts ('e: ' + e.xml.inspect).debug
233
+ puts 'e.class: ' + e.class.inspect.debug
234
+ end
235
+
236
+ if e.attributes.any? then
237
+ method('xdo_' + e.name.to_s).call(**(e.attributes))
238
+ else
239
+ method('xdo_' + e.name.to_s).call(e.text)
240
+ end
184
241
  end
185
242
 
186
243
  end
@@ -192,30 +249,44 @@ module Xdrp
192
249
  end
193
250
 
194
251
  def xdo_mouse(click: 'left', x: 0, y: 0)
195
- XDo::Mouse.click(x.to_i, y.to_i,
252
+ XDo::Mouse.click(x.to_i, y.to_i,
196
253
  Object.const_get('XDo::Mouse::' + click.upcase))
197
254
  end
198
255
 
199
256
  def xdo_mousemove(x: 0, y: 0)
200
257
  XDo::Mouse.move(x.to_i, y.to_i)
201
258
  end
202
-
259
+
203
260
  def xdo_mousewheel(scroll: 'down')
204
261
  XDo::Mouse.wheel(Object.const_get('XDo::Mouse::' + scroll.upcase, 4))
205
- end
262
+ end
206
263
 
207
264
  def xdo_sleep(duration: 0)
208
265
  sleep duration.to_f
209
266
  end
210
267
 
211
- def xdo_tab(h={})
212
- XDo::Keyboard.tab
268
+ def xdo_tab(times: 1)
269
+ times.to_i.times.each { XDo::Keyboard.tab }
213
270
  end
214
271
 
215
272
  def xdo_type(s)
216
273
  XDo::Keyboard.simulate(s.gsub('{enter}', "\n"))
217
274
  end
218
275
 
276
+ def xdo_window(activate: '')
277
+
278
+ if @debug then
279
+ puts 'inside xdo_window'
280
+ puts 'activate: ' + activate.inspect
281
+ end
282
+
283
+ wm = WMCtrl.display
284
+ window = wm.windows.find {|x| x.title == activate}
285
+ window.activate
286
+
287
+ end
288
+
289
+
219
290
  end
220
291
 
221
292
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xdrp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -11,31 +11,31 @@ cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
13
  MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDD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- MenyNICp3O9LfpXRSL4m8tF3d42IV0KxLtRHzO72YHyOCQJPWJ5nHXME9zFdYHyi
33
- P8eBkrKjbJ1wPQnSXMhuxYnwUnKPImDUfwfJFx/xNXVAY9Y8F2T+HajpD6Tm+K9V
34
- uYADR2lL52Rgbgbe3PCZ/oKTW1SjUgaC4MECdc3okdkxFWtysc0L+muLcjVFzUED
35
- Cqn27EoN8MQ4Dix2yFfGGMZBeer8GVOTtrIixZnGr7bSWglZWNDDy/x2ZTBU0jYB
36
- V66loB9HaeHxmtMl4Ylv2wvn
28
+ BgkqhkiG9w0BAQsFAAOCAYEAbmb/xDn+Tk7hG9j0sMNcRtS9F5TjTFCmoSGksHOw
29
+ WFGQwycJLPiS7N0djam52fOasrGw+WJS/CpoWaPL4SsSgXLqBwYKJx0efczzpIF0
30
+ i3gUx5vIp+NtMHsK+TbTeFN+xZRZa29BpBnJHShKDtXlAgyg5if9KGhs0yaRIw2o
31
+ NiV3epZmnh/l19xhvutTnVyKmLLIxMaYFiswTe3Ndz012OPssS1kBaIcvh6WGFTq
32
+ Yg5Hf1Ukm77+O5GQkPe2nide1wCC+4yxq0YN6dcKXo+cEy3ZsYHNHQcBdQSK5Z5O
33
+ 7xhvTr5OgQ5Mzf7c/1MPvbuGHnQUD+NrlrL+qf912M7V/LvjGiekfdOKfLEDIQXh
34
+ oLYMTazde9OcTI1yEfy+9EKOYzh/ss/nB7F56mvNVZUdSzKPUD2Q57UxdZsnEHEE
35
+ TiejpssCygWf9HFO3IZRrjH3OzSduilBf7oorCJZqxI5d7KbuK6ceM00aCBJibQO
36
+ K2bW5QcTuyp9GEliuroid41b
37
37
  -----END CERTIFICATE-----
38
- date: 2020-08-04 00:00:00.000000000 Z
38
+ date: 2021-11-16 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: xdo
@@ -61,44 +61,84 @@ dependencies:
61
61
  name: rxfhelper
62
62
  requirement: !ruby/object:Gem::Requirement
63
63
  requirements:
64
- - - ">="
65
- - !ruby/object:Gem::Version
66
- version: 1.0.0
67
64
  - - "~>"
68
65
  - !ruby/object:Gem::Version
69
- version: '1.0'
66
+ version: '1.1'
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 1.1.3
70
70
  type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- version: 1.0.0
77
74
  - - "~>"
78
75
  - !ruby/object:Gem::Version
79
- version: '1.0'
76
+ version: '1.1'
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 1.1.3
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: xinput_wrapper
82
82
  requirement: !ruby/object:Gem::Requirement
83
83
  requirements:
84
+ - - "~>"
85
+ - !ruby/object:Gem::Version
86
+ version: '0.8'
84
87
  - - ">="
85
88
  - !ruby/object:Gem::Version
86
- version: 0.7.0
89
+ version: 0.8.1
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.8'
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: 0.8.1
100
+ - !ruby/object:Gem::Dependency
101
+ name: ruby-wmctrl
102
+ requirement: !ruby/object:Gem::Requirement
103
+ requirements:
87
104
  - - "~>"
88
105
  - !ruby/object:Gem::Version
89
- version: '0.7'
106
+ version: '0.0'
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: 0.0.8
90
110
  type: :runtime
91
111
  prerelease: false
92
112
  version_requirements: !ruby/object:Gem::Requirement
93
113
  requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '0.0'
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: 0.0.8
120
+ - !ruby/object:Gem::Dependency
121
+ name: keystroker
122
+ requirement: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - "~>"
125
+ - !ruby/object:Gem::Version
126
+ version: '0.3'
94
127
  - - ">="
95
128
  - !ruby/object:Gem::Version
96
- version: 0.7.0
129
+ version: 0.3.1
130
+ type: :runtime
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
97
134
  - - "~>"
98
135
  - !ruby/object:Gem::Version
99
- version: '0.7'
136
+ version: '0.3'
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: 0.3.1
100
140
  description:
101
- email: james@jamesrobertson.eu
141
+ email: digital.robertson@gmail.com
102
142
  executables: []
103
143
  extensions: []
104
144
  extra_rdoc_files: []
@@ -116,14 +156,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
156
  requirements:
117
157
  - - ">="
118
158
  - !ruby/object:Gem::Version
119
- version: '0'
159
+ version: 3.0.2
120
160
  required_rubygems_version: !ruby/object:Gem::Requirement
121
161
  requirements:
122
162
  - - ">="
123
163
  - !ruby/object:Gem::Version
124
164
  version: '0'
125
165
  requirements: []
126
- rubygems_version: 3.0.3
166
+ rubyforge_project:
167
+ rubygems_version: 2.7.10
127
168
  signing_key:
128
169
  specification_version: 4
129
170
  summary: A basic macro recorder for GNU/Linux which uses program xinput to capture
metadata.gz.sig CHANGED
Binary file