auto_click 0.1.9 → 0.1.12
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.
- data/CHANGELOG +6 -0
- data/README.rdoc +54 -29
- data/auto_click.gemspec +6 -4
- data/lib/auto_click.rb +151 -17
- data/lib/auto_click/user32.rb +1 -0
- data/lib/auto_click/version.rb +1 -1
- data/lib/auto_click/virtual_key.rb +14 -13
- metadata +6 -6
data/CHANGELOG
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
0.1.11
|
|
2
|
+
super ugly implementation of that method type (need refactoring or even rewite later)
|
|
3
|
+
|
|
4
|
+
0.1.10
|
|
5
|
+
implement get_key_state method
|
|
6
|
+
refine the key_stroke, key_down and key_up method
|
|
1
7
|
|
|
2
8
|
0.1.9
|
|
3
9
|
Add support for keybaord region specific keys using US-keyboard standard
|
data/README.rdoc
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
= AutoClick
|
|
2
2
|
|
|
3
|
+
|
|
3
4
|
Smulating mouse click, cursor movement and keystrokes
|
|
4
5
|
|
|
5
6
|
== Install
|
|
@@ -7,7 +8,31 @@ Smulating mouse click, cursor movement and keystrokes
|
|
|
7
8
|
To install auto_click:
|
|
8
9
|
|
|
9
10
|
gem install auto_click
|
|
10
|
-
|
|
11
|
+
|
|
12
|
+
== Method List
|
|
13
|
+
|
|
14
|
+
- left_click
|
|
15
|
+
|
|
16
|
+
- right_click
|
|
17
|
+
|
|
18
|
+
- cursor_position
|
|
19
|
+
|
|
20
|
+
- mouse_move(x,y)
|
|
21
|
+
|
|
22
|
+
- mouse_scroll(step)
|
|
23
|
+
|
|
24
|
+
- left_drag(sx,sy,ex,ey)
|
|
25
|
+
|
|
26
|
+
- right_drag(sx,sy,ex,ey)
|
|
27
|
+
|
|
28
|
+
- type(string)
|
|
29
|
+
|
|
30
|
+
- key_stroke(key_name)
|
|
31
|
+
|
|
32
|
+
- key_down(key_name)
|
|
33
|
+
|
|
34
|
+
- key_up(key_name)
|
|
35
|
+
|
|
11
36
|
== Usage
|
|
12
37
|
|
|
13
38
|
To use the methods provided by auto_click. You need to require it.
|
|
@@ -36,6 +61,24 @@ To drag the icon on (50,50) to (200,300):
|
|
|
36
61
|
|
|
37
62
|
left_drag(50,50,200,300)
|
|
38
63
|
|
|
64
|
+
Suppose the notepad window on the top left corner of the screen, to type "Auto Click" in notepad. (Methods like get_windows("notepad") will be implemented in future release. So that you do not need to use this left click things to get focus on the notepad window......in later release......)
|
|
65
|
+
|
|
66
|
+
mouse_move(100,100)
|
|
67
|
+
leftclick
|
|
68
|
+
type('Auto Click')
|
|
69
|
+
|
|
70
|
+
The type method will Send keystroke for every characters of the strings. It will ensure that the capslock is off and hold shift when it is typing a capital character.
|
|
71
|
+
Notice that you need to escape the character \ and ' in single quote string, and you need to escape \ " and # in double quote string.
|
|
72
|
+
For example, to type #''\ , you can either do:
|
|
73
|
+
|
|
74
|
+
type('#\'\'\\')
|
|
75
|
+
|
|
76
|
+
or
|
|
77
|
+
|
|
78
|
+
type("\#''\\)
|
|
79
|
+
|
|
80
|
+
To get more refine control of key stroke simulation, you can use the method key_stroke, key_up and key_down methods
|
|
81
|
+
|
|
39
82
|
To send keystroke 'a':
|
|
40
83
|
|
|
41
84
|
key_stroke('a')
|
|
@@ -43,11 +86,9 @@ To send keystroke 'a':
|
|
|
43
86
|
To send keystroke tab:
|
|
44
87
|
|
|
45
88
|
key_stroke('tab')
|
|
46
|
-
|
|
47
|
-
Suppose the notepad window on the top left corner of the screen, to type "Auto Click" in notepad (assume that the capslock is off):
|
|
48
89
|
|
|
49
|
-
|
|
50
|
-
|
|
90
|
+
Therefore, to type "Auto Click" , you can either use the type method stated before, or you can do:
|
|
91
|
+
|
|
51
92
|
key_down('shift')
|
|
52
93
|
key_stroke('a')
|
|
53
94
|
key_up('shift')
|
|
@@ -61,8 +102,8 @@ Suppose the notepad window on the top left corner of the screen, to type "Auto C
|
|
|
61
102
|
key_stroke('c')
|
|
62
103
|
key_stroke('k')
|
|
63
104
|
|
|
64
|
-
|
|
65
|
-
Notice that 'a' means the key 'a' instead of the letter 'a'. Therefore key_stroke('a') and key_stroke('A')
|
|
105
|
+
|
|
106
|
+
Notice that 'a' means the key 'a' instead of the letter 'a'. Therefore key_stroke('a') and key_stroke('A') are basically the same. If the capslock is off but you want to type the capitalized A, you need to:
|
|
66
107
|
|
|
67
108
|
key_down('shift')
|
|
68
109
|
key_stroke('a')
|
|
@@ -79,30 +120,14 @@ is the same as
|
|
|
79
120
|
key_stroke('a')
|
|
80
121
|
|
|
81
122
|
|
|
82
|
-
== Method List
|
|
83
|
-
|
|
84
|
-
- left_click
|
|
85
|
-
|
|
86
|
-
- right_click
|
|
87
|
-
|
|
88
|
-
- cursor_position
|
|
89
|
-
|
|
90
|
-
- mouse_move(x,y)
|
|
91
|
-
|
|
92
|
-
- mouse_scroll(step)
|
|
93
|
-
|
|
94
|
-
- left_drag(sx,sy,ex,ey)
|
|
95
|
-
|
|
96
|
-
- right_drag(sx,sy,ex,ey)
|
|
97
|
-
|
|
98
|
-
- key_stroke(key_name)
|
|
99
|
-
|
|
100
|
-
- key_down(key_name)
|
|
101
|
-
|
|
102
|
-
- key_up(key_name)
|
|
103
123
|
|
|
104
124
|
|
|
105
|
-
== Change log
|
|
125
|
+
== Change log
|
|
126
|
+
(for full change log please refer to the CHANGELOG file in the repository)
|
|
127
|
+
|
|
128
|
+
- 0.1.11 Super ugly implementation of that method type (need refactoring or even rewite later)
|
|
129
|
+
|
|
130
|
+
- 0.1.10 Implement get_key_state method. Refine the key_stroke, key_down and key_up method
|
|
106
131
|
|
|
107
132
|
- 0.1.9 Add support for keybaord region specific keys using US-keyboard standard
|
|
108
133
|
|
data/auto_click.gemspec
CHANGED
|
@@ -8,16 +8,18 @@ Gem::Specification.new do |s|
|
|
|
8
8
|
s.platform = Gem::Platform::RUBY
|
|
9
9
|
s.authors = ["erinata"]
|
|
10
10
|
s.email = ["erinata@gmail.com"]
|
|
11
|
-
s.homepage = ""
|
|
11
|
+
s.homepage = "https://github.com/erinata/auto_click"
|
|
12
12
|
s.summary = %q{Smulating mouse click, cursor movement and keystrokes}
|
|
13
13
|
s.description = %q{Provide several Ruby methods for simulating mouse click, cursor movement and keystrokes in Windows.
|
|
14
14
|
This gem use DL library and SendInput method so there is no dependency on FFI, AutoIt or Win32-api.
|
|
15
|
-
Methods include mouse_move(x,y), left_click, right_click,
|
|
16
|
-
See https://github.com/erinata/auto_click for more details.
|
|
15
|
+
Methods include mouse_move(x,y), left_click, right_click, mouse_scroll, type, key_up, key_down...etc.
|
|
16
|
+
See https://github.com/erinata/auto_click for more details about instalation and usage.
|
|
17
17
|
(More control over mouse movement such as speed or locus will be implemented in future releases)}
|
|
18
18
|
|
|
19
19
|
s.required_ruby_version = '>= 1.9.0'
|
|
20
|
-
|
|
20
|
+
|
|
21
|
+
s.executables << 'testing'
|
|
22
|
+
|
|
21
23
|
s.files = `git ls-files`.split("\n")
|
|
22
24
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
23
25
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
data/lib/auto_click.rb
CHANGED
|
@@ -85,37 +85,171 @@ module AutoClick
|
|
|
85
85
|
sleep 0.1
|
|
86
86
|
end
|
|
87
87
|
|
|
88
|
-
def key_stroke(
|
|
89
|
-
code=VirtualKey.
|
|
88
|
+
def key_stroke(key_name)
|
|
89
|
+
code=VirtualKey.code_from_name(key_name)
|
|
90
90
|
send_input([InputStructure.keyboard_input(code,0x0000),
|
|
91
91
|
InputStructure.keyboard_input(code,0x0002)])
|
|
92
92
|
end
|
|
93
93
|
|
|
94
|
-
def key_down(
|
|
95
|
-
code=VirtualKey.
|
|
94
|
+
def key_down(key_name)
|
|
95
|
+
code=VirtualKey.code_from_name(key_name)
|
|
96
96
|
send_input([InputStructure.keyboard_input(code,0x0000)])
|
|
97
97
|
end
|
|
98
98
|
|
|
99
|
-
def key_up(
|
|
100
|
-
code=VirtualKey.
|
|
99
|
+
def key_up(key_name)
|
|
100
|
+
code=VirtualKey.code_from_name(key_name)
|
|
101
101
|
send_input([InputStructure.keyboard_input(code,0x0002)])
|
|
102
102
|
end
|
|
103
103
|
|
|
104
104
|
def type(string)
|
|
105
|
-
|
|
105
|
+
key_stroke(:capslock) if get_key_state(:capslock)==1
|
|
106
|
+
string=string.to_s
|
|
107
|
+
string.each_char do |c|
|
|
108
|
+
if ('a'..'z').include? c
|
|
109
|
+
key_stroke(c.to_sym)
|
|
110
|
+
elsif ('A'..'Z').include? c
|
|
111
|
+
key_down(:leftshift)
|
|
112
|
+
key_stroke(c.to_sym)
|
|
113
|
+
key_up(:leftshift)
|
|
114
|
+
elsif ('0'..'9').include? c
|
|
115
|
+
key_stroke(('num'+c).to_sym)
|
|
116
|
+
else
|
|
117
|
+
case c
|
|
118
|
+
when ' '
|
|
119
|
+
key_stroke(:space)
|
|
120
|
+
when ';'
|
|
121
|
+
key_stroke(:semicolon)
|
|
122
|
+
when ':'
|
|
123
|
+
key_down(:leftshift)
|
|
124
|
+
key_stroke(:semicolon)
|
|
125
|
+
key_up(:leftshift)
|
|
126
|
+
when '='
|
|
127
|
+
key_stroke(:equal)
|
|
128
|
+
when '+'
|
|
129
|
+
key_down(:leftshift)
|
|
130
|
+
key_stroke(:plus)
|
|
131
|
+
key_up(:leftshift)
|
|
132
|
+
when ','
|
|
133
|
+
key_stroke(:comma)
|
|
134
|
+
when '<'
|
|
135
|
+
key_down(:leftshift)
|
|
136
|
+
key_stroke(:smallerthan)
|
|
137
|
+
key_up(:leftshift)
|
|
138
|
+
when '-'
|
|
139
|
+
key_stroke(:hyphen)
|
|
140
|
+
when '_'
|
|
141
|
+
key_down(:leftshift)
|
|
142
|
+
key_stroke(:underscore)
|
|
143
|
+
key_up(:leftshift)
|
|
144
|
+
when '.'
|
|
145
|
+
key_stroke(:period)
|
|
146
|
+
when '>'
|
|
147
|
+
key_down(:leftshift)
|
|
148
|
+
key_stroke(:greaterthan)
|
|
149
|
+
key_up(:leftshift)
|
|
150
|
+
when '/'
|
|
151
|
+
key_stroke(:slash)
|
|
152
|
+
when '?'
|
|
153
|
+
key_down(:leftshift)
|
|
154
|
+
key_stroke(:question)
|
|
155
|
+
key_up(:leftshift)
|
|
156
|
+
when '`'
|
|
157
|
+
key_stroke(:grave)
|
|
158
|
+
when '~'
|
|
159
|
+
key_down(:leftshift)
|
|
160
|
+
key_stroke(:tilde)
|
|
161
|
+
key_up(:leftshift)
|
|
162
|
+
when '/'
|
|
163
|
+
key_stroke(:slash)
|
|
164
|
+
when '?'
|
|
165
|
+
key_down(:leftshift)
|
|
166
|
+
key_stroke(:question)
|
|
167
|
+
key_up(:leftshift)
|
|
168
|
+
when '['
|
|
169
|
+
key_stroke(:branket)
|
|
170
|
+
when '{'
|
|
171
|
+
key_down(:leftshift)
|
|
172
|
+
key_stroke(:branket)
|
|
173
|
+
key_up(:leftshift)
|
|
174
|
+
when ']'
|
|
175
|
+
key_stroke(:closebranket)
|
|
176
|
+
when '}'
|
|
177
|
+
key_down(:leftshift)
|
|
178
|
+
key_stroke(:closebranket)
|
|
179
|
+
key_up(:leftshift)
|
|
180
|
+
when '\\' # You need to esapce \ in the parameter string
|
|
181
|
+
key_stroke(:backslash)
|
|
182
|
+
when '|'
|
|
183
|
+
key_down(:leftshift)
|
|
184
|
+
key_stroke(:pipe)
|
|
185
|
+
key_up(:leftshift)
|
|
186
|
+
when '\'' # escape ' only for single quote string
|
|
187
|
+
key_stroke(:quote)
|
|
188
|
+
when '"' # escape " only for double quote string
|
|
189
|
+
key_down(:leftshift)
|
|
190
|
+
key_stroke(:doublequote)
|
|
191
|
+
key_up(:leftshift)
|
|
192
|
+
when '!'
|
|
193
|
+
key_down(:leftshift)
|
|
194
|
+
key_stroke(:num1)
|
|
195
|
+
key_up(:leftshift)
|
|
196
|
+
when '@'
|
|
197
|
+
key_down(:leftshift)
|
|
198
|
+
key_stroke(:num2)
|
|
199
|
+
key_up(:leftshift)
|
|
200
|
+
when '#' # The sharp sign need to be escape in single quote string
|
|
201
|
+
key_down(:leftshift)
|
|
202
|
+
key_stroke(:num3)
|
|
203
|
+
key_up(:leftshift)
|
|
204
|
+
when '$'
|
|
205
|
+
key_down(:leftshift)
|
|
206
|
+
key_stroke(:num4)
|
|
207
|
+
key_up(:leftshift)
|
|
208
|
+
when '%'
|
|
209
|
+
key_down(:leftshift)
|
|
210
|
+
key_stroke(:num5)
|
|
211
|
+
key_up(:leftshift)
|
|
212
|
+
when '^'
|
|
213
|
+
key_down(:leftshift)
|
|
214
|
+
key_stroke(:num6)
|
|
215
|
+
key_up(:leftshift)
|
|
216
|
+
when '&'
|
|
217
|
+
key_down(:leftshift)
|
|
218
|
+
key_stroke(:num7)
|
|
219
|
+
key_up(:leftshift)
|
|
220
|
+
when '*'
|
|
221
|
+
key_down(:leftshift)
|
|
222
|
+
key_stroke(:num8)
|
|
223
|
+
key_up(:leftshift)
|
|
224
|
+
when '('
|
|
225
|
+
key_down(:leftshift)
|
|
226
|
+
key_stroke(:num9)
|
|
227
|
+
key_up(:leftshift)
|
|
228
|
+
when ')'
|
|
229
|
+
key_down(:leftshift)
|
|
230
|
+
key_stroke(:num0)
|
|
231
|
+
key_up(:leftshift)
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
def get_key_state(key_name)
|
|
239
|
+
code=VirtualKey.code_from_name(key_name)
|
|
240
|
+
User32.GetKeyState(code)
|
|
241
|
+
# For normal keys (such as a)
|
|
242
|
+
# When the key is down the value is -128
|
|
243
|
+
# When the key is up the value is 0
|
|
244
|
+
|
|
245
|
+
# For toggle keys (such as capslock)
|
|
246
|
+
# When the cap key is down and the caplock is on the value is -127
|
|
247
|
+
# When the cap key is down and the caplock is off the value is -128
|
|
248
|
+
# When the cap key is Up and the caplock is on the value is 1
|
|
249
|
+
# When the cap key is Up and the caplock is off the value is 0
|
|
106
250
|
end
|
|
107
|
-
|
|
108
251
|
end
|
|
109
252
|
|
|
110
253
|
|
|
111
254
|
include AutoClick # This line allow auto include when the user require the gem
|
|
112
255
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
data/lib/auto_click/user32.rb
CHANGED
data/lib/auto_click/version.rb
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
module VirtualKey
|
|
2
|
-
def self.
|
|
2
|
+
def self.code_from_name(name)
|
|
3
3
|
|
|
4
|
-
if
|
|
5
|
-
return
|
|
6
|
-
elsif
|
|
7
|
-
|
|
4
|
+
if name.kind_of? Fixnum
|
|
5
|
+
return name
|
|
6
|
+
elsif name.kind_of? String
|
|
7
|
+
name=name.delete('_').delete('-').delete(' ')
|
|
8
8
|
end
|
|
9
|
-
|
|
10
|
-
case
|
|
9
|
+
name = name.to_sym.downcase
|
|
10
|
+
case name
|
|
11
11
|
#when
|
|
12
12
|
# 0x00S
|
|
13
13
|
#when
|
|
@@ -446,13 +446,13 @@ module VirtualKey
|
|
|
446
446
|
# 0xD9
|
|
447
447
|
#when
|
|
448
448
|
# 0xDA
|
|
449
|
-
when :openbranket, :leftbranket, :opensquarebranket, :leftsquarebranket, :squarebranket
|
|
449
|
+
when :branket, :openbranket, :leftbranket, :opensquarebranket, :leftsquarebranket, :squarebranket, :curlybranket, :opencurlybranket, :leftcurlybranket
|
|
450
450
|
0xDB
|
|
451
451
|
when :pipe, :pipes, :bar, :brokenbar, :backslash
|
|
452
452
|
0xDC
|
|
453
|
-
when :closebranket, :closesquarebranket, :rightbranket, :rightsquarebranket
|
|
453
|
+
when :closebranket, :closesquarebranket, :rightbranket, :rightsquarebranket, :closecurlybranket, :rightcurlybranket
|
|
454
454
|
0xDD
|
|
455
|
-
when :quote,:singlequote,:doublequote, :rightquote
|
|
455
|
+
when :quote,:singlequote,:doublequote, :rightquote, :acute, :acuteaccent
|
|
456
456
|
0xDE
|
|
457
457
|
#when
|
|
458
458
|
# 0xDF
|
|
@@ -520,10 +520,11 @@ module VirtualKey
|
|
|
520
520
|
# 0xFE
|
|
521
521
|
#when
|
|
522
522
|
# 0xFF
|
|
523
|
-
else
|
|
523
|
+
else
|
|
524
|
+
0
|
|
524
525
|
end
|
|
525
|
-
|
|
526
|
-
|
|
527
526
|
end
|
|
527
|
+
|
|
528
|
+
|
|
528
529
|
|
|
529
530
|
end
|
metadata
CHANGED
|
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
|
5
5
|
segments:
|
|
6
6
|
- 0
|
|
7
7
|
- 1
|
|
8
|
-
-
|
|
9
|
-
version: 0.1.
|
|
8
|
+
- 12
|
|
9
|
+
version: 0.1.12
|
|
10
10
|
platform: ruby
|
|
11
11
|
authors:
|
|
12
12
|
- erinata
|
|
@@ -14,15 +14,15 @@ autorequire:
|
|
|
14
14
|
bindir: bin
|
|
15
15
|
cert_chain: []
|
|
16
16
|
|
|
17
|
-
date: 2011-01-
|
|
17
|
+
date: 2011-01-04 00:00:00 -06:00
|
|
18
18
|
default_executable:
|
|
19
19
|
dependencies: []
|
|
20
20
|
|
|
21
21
|
description: |-
|
|
22
22
|
Provide several Ruby methods for simulating mouse click, cursor movement and keystrokes in Windows.
|
|
23
23
|
This gem use DL library and SendInput method so there is no dependency on FFI, AutoIt or Win32-api.
|
|
24
|
-
Methods include mouse_move(x,y), left_click, right_click,
|
|
25
|
-
See https://github.com/erinata/auto_click for more details.
|
|
24
|
+
Methods include mouse_move(x,y), left_click, right_click, mouse_scroll, type, key_up, key_down...etc.
|
|
25
|
+
See https://github.com/erinata/auto_click for more details about instalation and usage.
|
|
26
26
|
(More control over mouse movement such as speed or locus will be implemented in future releases)
|
|
27
27
|
email:
|
|
28
28
|
- erinata@gmail.com
|
|
@@ -46,7 +46,7 @@ files:
|
|
|
46
46
|
- lib/auto_click/version.rb
|
|
47
47
|
- lib/auto_click/virtual_key.rb
|
|
48
48
|
has_rdoc: true
|
|
49
|
-
homepage:
|
|
49
|
+
homepage: https://github.com/erinata/auto_click
|
|
50
50
|
licenses: []
|
|
51
51
|
|
|
52
52
|
post_install_message:
|