rum 0.0.1-x86-mswin32-60 → 0.0.3-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/CHANGELOG +9 -0
  2. data/README.md +35 -0
  3. data/Rakefile +22 -19
  4. data/bin/rum-client +4 -4
  5. data/doc/basic.rb +1 -1
  6. data/doc/doc.html +619 -602
  7. data/doc/example.rb +1 -1
  8. data/doc/reference.rb +29 -16
  9. data/doc/resources/build.rb +14 -12
  10. data/doc/resources/doc.haml +8 -3
  11. data/ext/mac/keyboard_hook/EventTap.h +1 -1
  12. data/ext/mac/keyboard_hook/EventTap.m +9 -9
  13. data/ext/mac/keyboard_hook/KeyboardHook.xcodeproj/project.pbxproj +12 -9
  14. data/ext/windows/keyboard_hook/keyboard_hook.c +3 -3
  15. data/ext/windows/system/autohotkey_stuff.c +12 -10
  16. data/ext/windows/system/clipboard_watcher.c +2 -2
  17. data/ext/windows/system/extconf.rb +1 -0
  18. data/ext/windows/system/input_box.c +9 -9
  19. data/ext/windows/system/system.c +51 -46
  20. data/lib/rum/barrel.rb +46 -16
  21. data/lib/rum/barrel/emacs.rb +1 -1
  22. data/lib/rum/barrel/emacs_client.rb +32 -5
  23. data/lib/rum/core.rb +24 -22
  24. data/lib/rum/dsl.rb +15 -16
  25. data/lib/rum/gui.rb +3 -3
  26. data/lib/rum/help.rb +10 -8
  27. data/lib/rum/hotkey_core.rb +35 -25
  28. data/lib/rum/mac.rb +1 -1
  29. data/lib/rum/mac/gui.rb +1 -1
  30. data/lib/rum/mac/gui/growl.rb +3 -3
  31. data/lib/rum/mac/irb/completion.rb +13 -13
  32. data/lib/rum/mac/keyboard_hook.rb +8 -5
  33. data/lib/rum/mac/layouts.rb +4 -4
  34. data/lib/rum/mac/system.rb +2 -2
  35. data/lib/rum/remote.rb +3 -3
  36. data/lib/rum/server.rb +2 -3
  37. data/lib/rum/windows.rb +2 -1
  38. data/lib/rum/windows/app.rb +12 -7
  39. data/lib/rum/windows/apps.rb +3 -8
  40. data/lib/rum/windows/gui.rb +8 -8
  41. data/lib/rum/windows/keyboard.rb +34 -9
  42. data/lib/rum/windows/keyboard_hook.so +0 -0
  43. data/lib/rum/windows/layouts.rb +6 -6
  44. data/lib/rum/windows/system.rb +71 -28
  45. data/lib/rum/windows/system.so +0 -0
  46. data/lib/rum/windows/system_foreign_functions.rb +44 -20
  47. data/rum.gemspec +2 -2
  48. metadata +19 -21
  49. data/README +0 -30
@@ -7,7 +7,7 @@ module Rum
7
7
  def default_layout
8
8
  us
9
9
  end
10
-
10
+
11
11
  def core
12
12
  # http://msdn.microsoft.com/en-us/library/dd375731%28VS.85%29.aspx
13
13
  core = Layout.new
@@ -133,12 +133,12 @@ module Rum
133
133
 
134
134
  def basic
135
135
  basic = core
136
-
136
+
137
137
  basic.remap 'lcontrol', 'rcontrol', 'control'
138
138
  basic.remap 'rmenu', 'lmenu'
139
139
  basic.remap 'lshift', 'rshift', 'shift'
140
140
  basic.remap 'rwin', 'lwin'
141
-
141
+
142
142
  basic.alias 'control', 'ctrl'
143
143
  basic.alias 'control', 'c'
144
144
  basic.rename 'lmenu', 'alt'
@@ -152,8 +152,8 @@ module Rum
152
152
  basic.rename 'prior', 'pageup'
153
153
  basic.rename 'next', 'pagedown'
154
154
  basic.rename 'snapshot', 'print'
155
-
156
-
155
+
156
+
157
157
  %w{shift control alt win}.each { |key| basic.core_modifier key }
158
158
 
159
159
  basic.action_modifier 'alt'
@@ -205,7 +205,7 @@ END
205
205
  german.rename 'oem_6', '´'
206
206
  german.rename 'oem_7', 'ä'
207
207
  german.rename 'oem_102', '<'
208
-
208
+
209
209
  shift_translations = <<END.scan(/(\S) (\S)/)
210
210
  ° ^ $ 4 ( 8 ` ´ ; ,
211
211
  ! 1 % 5 ) 9 * + : .
@@ -3,9 +3,13 @@ require_relative 'system_foreign_functions'
3
3
  module Rum
4
4
  module System
5
5
  extend self
6
-
6
+
7
7
  def send_key_event key, down
8
- extended, id = key.id.divmod 2**9
8
+ send_key_event_for_id key.id, down
9
+ end
10
+
11
+ def send_key_event_for_id id, down
12
+ extended, id = id.divmod 2**9
9
13
  extended = (extended == 1)
10
14
  keybd_event id, down, 0, extended
11
15
  end
@@ -15,6 +19,10 @@ module Rum
15
19
  send_key_event key, false
16
20
  end
17
21
 
22
+ def send_unicode_char char
23
+ send_unicode_char_internal(char.encode(Encoding::UTF_16LE))
24
+ end
25
+
18
26
  def active_window_handles
19
27
  Enumerator.new(self, :enum_windows)
20
28
  end
@@ -28,7 +36,7 @@ module Rum
28
36
  def active_window
29
37
  Window.new get_foreground_window
30
38
  end
31
-
39
+
32
40
  def terminal_window
33
41
  Window.new get_console_window
34
42
  end
@@ -51,7 +59,7 @@ module Rum
51
59
  # returns a copy
52
60
  def c_string obj
53
61
  str = obj.to_s + "\0"
54
- str.encode(Encoding::UTF_16LE)
62
+ str.encode(Encoding::UTF_16LE)
55
63
  end
56
64
 
57
65
  def message_box message, title=''
@@ -81,11 +89,15 @@ module Rum
81
89
  Clipboard.preserve { Clipboard.get_selection }
82
90
  end
83
91
 
84
- class Window
92
+ def kill_task exe_name
93
+ system("taskkill /F /IM #{exe_name}.exe")
94
+ end
95
+
96
+ class Window
85
97
  include System
86
-
98
+
87
99
  attr_reader :handle
88
-
100
+
89
101
  def initialize(handle)
90
102
  @handle = handle
91
103
  end
@@ -94,7 +106,7 @@ module Rum
94
106
  return false unless other.respond_to? :handle
95
107
  @handle == other.handle
96
108
  end
97
-
109
+
98
110
  def active?
99
111
  self.handle == get_foreground_window
100
112
  end
@@ -118,7 +130,7 @@ module Rum
118
130
  def maximize
119
131
  post_message @handle, WM_SYSCOMMAND, SC_MAXIMIZE, 0
120
132
  end
121
-
133
+
122
134
  def minimize
123
135
  post_message @handle, WM_SYSCOMMAND, SC_MINIMIZE, 0
124
136
  end
@@ -127,6 +139,15 @@ module Rum
127
139
  post_message @handle, WM_SYSCOMMAND, SC_RESTORE, 0
128
140
  end
129
141
 
142
+ # Don't underestimate the Force
143
+ def force_show
144
+ 100.times do
145
+ show
146
+ sleep 0.02
147
+ return true if active_window == self
148
+ end
149
+ end
150
+
130
151
  def file_dialog?
131
152
  class_name == '#32770'
132
153
  end
@@ -150,7 +171,7 @@ module Rum
150
171
  restore if zoomed?
151
172
  move_window(@handle, x, y, width, height, 1)
152
173
  end
153
-
174
+
154
175
  def title(max_length = 1024)
155
176
  buffer = "\0" * (max_length * 2)
156
177
  length = get_window_text_w(@handle, buffer, buffer.length)
@@ -158,13 +179,13 @@ module Rum
158
179
  result.force_encoding(Encoding::UTF_16LE)
159
180
  result.encode(Encoding::UTF_8, invalid: :replace)
160
181
  end
161
-
182
+
162
183
  def class_name(max_length = 2048)
163
184
  buffer = "\0" * max_length
164
185
  length = get_class_name(@handle, buffer, buffer.length)
165
186
  length == 0 ? '' : buffer[0..length - 1]
166
187
  end
167
-
188
+
168
189
  def text(max_length = 2048)
169
190
  buffer = '\0' * max_length
170
191
  length = send_with_buffer @handle, WM_GETTEXT, buffer.length, buffer
@@ -182,19 +203,44 @@ module Rum
182
203
  else
183
204
  0
184
205
  end
185
-
206
+
186
207
  raise "Control '#{id}' not found" if result == 0
187
208
  Window.new result
188
209
  end
189
210
 
211
+ def child_window class_name
212
+ if class_name.is_a? Regexp
213
+ child_windows.find { |child| child.class_name =~ class_name }
214
+ else
215
+ child_windows.find { |child| child.class_name == class_name }
216
+ end
217
+ end
218
+
219
+ def child_windows
220
+ Enumerator.new do |yielder|
221
+ enum_child_windows { |handle| yielder.yield Window.new(handle) }
222
+ end
223
+ end
224
+
190
225
  def kill_task
191
- system("taskkill /F /IM #{exe_name}.exe")
226
+ System.kill_task exe_name
192
227
  end
193
-
228
+
194
229
  def report
195
230
  "Title: #{title}\nClass: #{class_name}"
196
231
  end
197
232
 
233
+ def exe_path
234
+ exe_path_internal.
235
+ force_encoding(Encoding::UTF_16LE).
236
+ encode(Encoding::UTF_8).
237
+ gsub('\\', '/')
238
+ end
239
+
240
+ def exe_name
241
+ File.basename(exe_path, '.exe')
242
+ end
243
+
198
244
  def self.[] arg, class_name=nil
199
245
  if arg.is_a? Hash
200
246
  WindowMatcher.new(arg[:title], arg[:class_name])
@@ -207,7 +253,7 @@ module Rum
207
253
  class WindowMatcher
208
254
  include System
209
255
  attr_reader :specs
210
-
256
+
211
257
  def initialize title=nil, class_name=nil
212
258
  @specs = { title: title, class_name: class_name }
213
259
  raise 'No specifications given.' unless @specs.values.any?
@@ -221,7 +267,7 @@ module Rum
221
267
  def comparison_method obj
222
268
  if obj.is_a? Regexp then :=~ else :== end
223
269
  end
224
-
270
+
225
271
  def matches? window
226
272
  @specs.all? do |spec, value|
227
273
  not value or value.send(comparison_method(value), window.send(spec))
@@ -249,14 +295,18 @@ module Rum
249
295
  end
250
296
  end
251
297
  end
252
-
298
+
253
299
  module Clipboard
254
300
  extend self
255
-
301
+
256
302
  def get
257
303
  Win32::Clipboard.get
258
304
  end
259
-
305
+
306
+ def get_html
307
+ Win32::Clipboard.get_html
308
+ end
309
+
260
310
  def set str
261
311
  Win32::Clipboard.set str
262
312
  end
@@ -268,12 +318,6 @@ module Rum
268
318
  set old_content
269
319
  end
270
320
 
271
- # def copy
272
- # watcher = install_watcher
273
- # Keyboard.type '(ctrl c)'
274
- # evaluate_watcher(watcher, 400) # Timeout: 400 msec
275
- # end
276
-
277
321
  def wait_for_change
278
322
  watcher = install_watcher
279
323
  begin
@@ -291,7 +335,7 @@ module Rum
291
335
  def paste
292
336
  Keyboard.type '(ctrl v)'
293
337
  end
294
-
338
+
295
339
  def get_selection
296
340
  Clipboard.get if Clipboard.copy
297
341
  end
@@ -307,4 +351,3 @@ module Rum
307
351
  end
308
352
  end
309
353
  end
310
-
Binary file
@@ -41,14 +41,14 @@ module Rum
41
41
  def_api 'SendMessage', 'LLLP', 'L', :send_with_buffer
42
42
  def_api 'SendMessage', 'LLLL', 'L'
43
43
  def_api 'PostMessage', 'LLLL', 'L'
44
- def_api 'GetDlgItem', 'LL', 'L'
44
+ def_api 'GetDlgItem', 'LL', 'L'
45
45
  def_api 'GetWindowRect', 'LP', 'I'
46
- def_api 'SetCursorPos', 'LL', 'I'
46
+ def_api 'SetCursorPos', 'LL', 'I'
47
47
  def_api 'mouse_event', 'LLLLL', 'V'
48
48
  def_api 'IsWindow', 'L', 'L'
49
49
  def_api 'IsWindowVisible', 'L', 'L'
50
50
  def_api 'SetForegroundWindow', 'L', 'L'
51
-
51
+
52
52
  def_api 'GetWindowLong', 'LI', 'L'
53
53
  def_api 'GetForegroundWindow', 'V', 'L'
54
54
  def_api 'GetClassName', 'LPI', 'I'
@@ -60,15 +60,17 @@ module Rum
60
60
  def_api 'IsZoomed', 'L', 'L'
61
61
  def_api 'SetWindowPos', 'LLIIIII', 'I'
62
62
  def_api 'MoveWindow', 'LIIIIB', 'L'
63
-
63
+
64
64
  ShellExecute = Win32::API.new('ShellExecute', 'LPPPPI', 'L', 'shell32')
65
65
  def start command, parameters=0
66
+ command.encode!(Encoding::WINDOWS_1252)
67
+ parameters.encode!(Encoding::WINDOWS_1252) if parameters != 0
66
68
  ShellExecute.call(0, 'open', command, parameters, 0, 1)
67
69
  end
68
-
69
- WM_COMMAND = 0x0111
70
+
71
+ WM_COMMAND = 0x0111
70
72
  WM_SYSCOMMAND = 0x0112
71
-
73
+
72
74
  SC_CLOSE = 0xF060
73
75
  SC_RESTORE = 0xF120;
74
76
  SC_MAXIMIZE = 0xF030;
@@ -105,19 +107,17 @@ end
105
107
  module Win32
106
108
  class Clipboard
107
109
  def self.get
108
- begin
109
- self.open
110
- return '' unless IsClipboardFormatAvailable(UNICODETEXT)
111
- handle = GetClipboardData(UNICODETEXT)
112
- clip_data = 0.chr * GlobalSize(handle)
113
- memcpy(clip_data, handle, clip_data.size)
114
- clip_data.force_encoding(Encoding::UTF_16LE)
115
- clip_data.encode!(Encoding::UTF_8, invalid: :replace, replace: '', \
116
- universal_newline: true)
117
- clip_data[ /^[^\0]*/ ]
118
- ensure
119
- self.close
120
- end
110
+ self.open
111
+ return '' unless IsClipboardFormatAvailable(UNICODETEXT)
112
+ handle = GetClipboardData(UNICODETEXT)
113
+ clip_data = 0.chr * GlobalSize(handle)
114
+ memcpy(clip_data, handle, clip_data.size)
115
+ clip_data.force_encoding(Encoding::UTF_16LE)
116
+ clip_data.encode!(Encoding::UTF_8, invalid: :replace, replace: '', \
117
+ universal_newline: true)
118
+ clip_data[ /^[^\0]*/ ]
119
+ ensure
120
+ self.close
121
121
  end
122
122
 
123
123
  def self.set str
@@ -125,5 +125,29 @@ module Win32
125
125
  data.force_encoding Encoding::BINARY
126
126
  set_data(data, UNICODETEXT)
127
127
  end
128
+
129
+ def self.html_format
130
+ @html_format ||= register_format('HTML Format')
131
+ end
132
+
133
+ def self.get_html
134
+ html = html_format
135
+ self.open
136
+ if IsClipboardFormatAvailable(html)
137
+ handle = GetClipboardData(html)
138
+ clip_data = 0.chr * GlobalSize(handle)
139
+ memcpy(clip_data, handle, clip_data.size)
140
+ clip_data.force_encoding(Encoding::UTF_8)
141
+ clip_data = clip_data[ /^[^\0]*/ ]
142
+ end
143
+ ensure
144
+ self.close
145
+ end
146
+
147
+ def self.set_html str
148
+ data = str + "\0"
149
+ data.force_encoding Encoding::BINARY
150
+ set_data(data, html_format)
151
+ end
128
152
  end
129
153
  end
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'rum'
5
- spec.version = '0.0.1'
5
+ spec.version = '0.0.3'
6
6
  spec.author = 'nonsequitur'
7
7
  spec.license = 'MIT'
8
8
  spec.homepage = 'http://nonsequitur.github.com/rum'
@@ -10,5 +10,5 @@ Gem::Specification.new do |spec|
10
10
  spec.required_ruby_version = '>= 1.9.1'
11
11
 
12
12
  spec.executables << 'rum-client'
13
- spec.extra_rdoc_files = ['README']
13
+ spec.extra_rdoc_files = ['README.md']
14
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: x86-mswin32-60
7
7
  authors:
@@ -9,12 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-06-04 00:00:00.000000000 +02:00
13
- default_executable:
12
+ date: 2012-11-24 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: ruby_gntp
17
- requirement: &7843836 !ruby/object:Gem::Requirement
16
+ requirement: &20331588 !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ! '>='
@@ -22,10 +21,10 @@ dependencies:
22
21
  version: 0.3.4
23
22
  type: :runtime
24
23
  prerelease: false
25
- version_requirements: *7843836
24
+ version_requirements: *20331588
26
25
  - !ruby/object:Gem::Dependency
27
26
  name: win32-api
28
- requirement: &7842480 !ruby/object:Gem::Requirement
27
+ requirement: &20330556 !ruby/object:Gem::Requirement
29
28
  none: false
30
29
  requirements:
31
30
  - - ! '>='
@@ -33,10 +32,10 @@ dependencies:
33
32
  version: 1.4.8
34
33
  type: :runtime
35
34
  prerelease: false
36
- version_requirements: *7842480
35
+ version_requirements: *20330556
37
36
  - !ruby/object:Gem::Dependency
38
37
  name: win32-clipboard
39
- requirement: &7841448 !ruby/object:Gem::Requirement
38
+ requirement: &20329356 !ruby/object:Gem::Requirement
40
39
  none: false
41
40
  requirements:
42
41
  - - ! '>='
@@ -44,17 +43,19 @@ dependencies:
44
43
  version: 0.5.2
45
44
  type: :runtime
46
45
  prerelease: false
47
- version_requirements: *7841448
46
+ version_requirements: *20329356
48
47
  description:
49
48
  email:
50
49
  executables:
51
50
  - rum-client
52
51
  extensions: []
53
52
  extra_rdoc_files:
54
- - README
53
+ - README.md
55
54
  files:
56
- - bin/rum-client
57
55
  - CHANGELOG
56
+ - README.md
57
+ - Rakefile
58
+ - bin/rum-client
58
59
  - doc/basic.rb
59
60
  - doc/doc.html
60
61
  - doc/example.rb
@@ -78,8 +79,8 @@ files:
78
79
  - ext/mac/keyboard_hook/EventTap.h
79
80
  - ext/mac/keyboard_hook/EventTap.m
80
81
  - ext/mac/keyboard_hook/Info.plist
81
- - ext/mac/keyboard_hook/KeyboardHook.xcodeproj/project.pbxproj
82
82
  - ext/mac/keyboard_hook/KeyboardHook.xcodeproj/TemplateIcon.icns
83
+ - ext/mac/keyboard_hook/KeyboardHook.xcodeproj/project.pbxproj
83
84
  - ext/mac/keyboard_hook/KeyboardHook_Prefix.pch
84
85
  - ext/mac/keyboard_hook/version.plist
85
86
  - ext/windows/keyboard_hook/extconf.rb
@@ -92,26 +93,28 @@ files:
92
93
  - ext/windows/system/input_box.c
93
94
  - ext/windows/system/input_box.h
94
95
  - ext/windows/system/system.c
96
+ - lib/rum.rb
95
97
  - lib/rum/apps.rb
98
+ - lib/rum/barrel.rb
96
99
  - lib/rum/barrel/emacs.rb
97
100
  - lib/rum/barrel/emacs_client.rb
98
- - lib/rum/barrel.rb
99
101
  - lib/rum/core.rb
100
102
  - lib/rum/dsl.rb
101
103
  - lib/rum/gui.rb
102
104
  - lib/rum/help.rb
103
105
  - lib/rum/hotkey_core.rb
106
+ - lib/rum/mac.rb
104
107
  - lib/rum/mac/app.rb
105
108
  - lib/rum/mac/apps.rb
106
- - lib/rum/mac/gui/growl.rb
107
109
  - lib/rum/mac/gui.rb
110
+ - lib/rum/mac/gui/growl.rb
108
111
  - lib/rum/mac/irb/completion.rb
109
112
  - lib/rum/mac/keyboard_hook.rb
110
113
  - lib/rum/mac/layouts.rb
111
114
  - lib/rum/mac/system.rb
112
- - lib/rum/mac.rb
113
115
  - lib/rum/remote.rb
114
116
  - lib/rum/server.rb
117
+ - lib/rum/windows.rb
115
118
  - lib/rum/windows/app.rb
116
119
  - lib/rum/windows/apps.rb
117
120
  - lib/rum/windows/gui.rb
@@ -122,12 +125,7 @@ files:
122
125
  - lib/rum/windows/system.rb
123
126
  - lib/rum/windows/system.so
124
127
  - lib/rum/windows/system_foreign_functions.rb
125
- - lib/rum/windows.rb
126
- - lib/rum.rb
127
- - Rakefile
128
- - README
129
128
  - rum.gemspec
130
- has_rdoc: true
131
129
  homepage: http://nonsequitur.github.com/rum
132
130
  licenses:
133
131
  - MIT
@@ -149,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
147
  version: '0'
150
148
  requirements: []
151
149
  rubyforge_project:
152
- rubygems_version: 1.5.2
150
+ rubygems_version: 1.8.11
153
151
  signing_key:
154
152
  specification_version: 3
155
153
  summary: A cross-platform Hotkey and Macro utility, running on Windows and Mac OS.