Module: AutoClickMethods

Defined in:
lib/auto_click.rb

Constant Summary collapse

@@rightdown =
InputStructure.mouse_input(0,0,0,0x0008)
@@rightup =
InputStructure.mouse_input(0,0,0,0x0010)
@@leftdown =
InputStructure.mouse_input(0,0,0,0x0002)
@@leftup =
InputStructure.mouse_input(0,0,0,0x0004)
@@middledown =
InputStructure.mouse_input(0,0,0,0x0020)
@@middleup =
InputStructure.mouse_input(0,0,0,0x0040)
@@rightdown32 =
InputStructure.mouse_input_32(0,0,0,0x0008)
@@rightup32 =
InputStructure.mouse_input_32(0,0,0,0x0010)
@@leftdown32 =
InputStructure.mouse_input_32(0,0,0,0x0002)
@@leftup32 =
InputStructure.mouse_input_32(0,0,0,0x0004)
@@middledown32 =
InputStructure.mouse_input_32(0,0,0,0x0020)
@@middleup32 =
InputStructure.mouse_input_32(0,0,0,0x0040)

Instance Method Summary collapse

Instance Method Details

#cursor_positionObject

END TEMP #####################



165
166
167
168
169
# File 'lib/auto_click.rb', line 165

def cursor_position
  point = " " * 8
  User32.GetCursorPos(point)
  point.unpack('LL')  
end

#double_clickObject



69
70
71
72
# File 'lib/auto_click.rb', line 69

def double_click
  left_click
  left_click
end

#double_click_32Object



119
120
121
122
# File 'lib/auto_click.rb', line 119

def double_click_32
  left_click_32
  left_click_32
end

#get_key_state(key_name) ⇒ Object



349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'lib/auto_click.rb', line 349

def get_key_state(key_name)
  code=VirtualKey.code_from_name(key_name)
  User32.GetKeyState(code)
  # For normal keys (such as a)
  # When the key is down the value is -128
  # When the key is up the value is 0
   
  # For toggle keys (such as capslock)  
  # When the cap key is down and the caplock is on the value is -127
  # When the cap key is down and the caplock is off the value is -128
  # When the cap key is Up and the caplock is on the value is 1
  # When the cap key is Up and the caplock is off the value is 0 
end

#get_screen_resolutionObject



21
22
23
# File 'lib/auto_click.rb', line 21

def get_screen_resolution
  [User32.GetSystemMetrics(0), User32.GetSystemMetrics(1)]
end

#key_down(key_name) ⇒ Object



205
206
207
208
# File 'lib/auto_click.rb', line 205

def key_down(key_name)
  code=VirtualKey.code_from_name(key_name)
  send_input([InputStructure.keyboard_input(code,0x0000)])
end

#key_down_32(key_name) ⇒ Object



153
154
155
156
# File 'lib/auto_click.rb', line 153

def key_down_32(key_name)
  code=VirtualKey.code_from_name(key_name)
  send_input([InputStructure.keyboard_input_32(code,0x0000)])
end

#key_stroke(key_name) ⇒ Object



199
200
201
202
203
# File 'lib/auto_click.rb', line 199

def key_stroke(key_name)
  code=VirtualKey.code_from_name(key_name)
  send_input([InputStructure.keyboard_input(code,0x0000),
              InputStructure.keyboard_input(code,0x0002)])
end

#key_stroke_32(key_name) ⇒ Object



147
148
149
150
151
# File 'lib/auto_click.rb', line 147

def key_stroke_32(key_name)
  code=VirtualKey.code_from_name(key_name)
  send_input([InputStructure.keyboard_input_32(code,0x0000),
              InputStructure.keyboard_input_32(code,0x0002)])
end

#key_up(key_name) ⇒ Object



210
211
212
213
# File 'lib/auto_click.rb', line 210

def key_up(key_name)
  code=VirtualKey.code_from_name(key_name)
  send_input([InputStructure.keyboard_input(code,0x0002)])
end

#key_up_32(key_name) ⇒ Object



158
159
160
161
# File 'lib/auto_click.rb', line 158

def key_up_32(key_name)
  code=VirtualKey.code_from_name(key_name)
  send_input([InputStructure.keyboard_input_32(code,0x0002)])
end

#left_clickObject



39
40
41
# File 'lib/auto_click.rb', line 39

def left_click
  send_input( [@@leftdown, @@leftup] )
end

#left_click_32Object



89
90
91
# File 'lib/auto_click.rb', line 89

def left_click_32
  send_input( [@@leftdown32, @@leftup32] )
end

#left_drag(sx, sy, ex, ey) ⇒ Object



177
178
179
180
181
182
183
184
185
186
# File 'lib/auto_click.rb', line 177

def left_drag(sx,sy,ex,ey)
  mouse_move sx,sy
  sleep 0.1
  send_input( [@@leftdown] )
  sleep 0.1
  mouse_move ex,ey
  sleep 0.1
  send_input( [@@leftup] )
  sleep 0.1
end

#left_drag_32(sx, sy, ex, ey) ⇒ Object



125
126
127
128
129
130
131
132
133
134
# File 'lib/auto_click.rb', line 125

def left_drag_32(sx,sy,ex,ey)
  mouse_move sx,sy
  sleep 0.1
  send_input( [@@leftdown32] )
  sleep 0.1
  mouse_move ex,ey
  sleep 0.1
  send_input( [@@leftup32] )
  sleep 0.1
end

#middle_clickObject



43
44
45
# File 'lib/auto_click.rb', line 43

def middle_click
  send_input( [@@middledown, @@middleup] )
end

#middle_click_32Object



93
94
95
# File 'lib/auto_click.rb', line 93

def middle_click_32
  send_input( [@@middledown32, @@middleup32] )
end

#mouse_down(button_name) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/auto_click.rb', line 47

def mouse_down(button_name)
  case button_name
  when :right
    send_input( [@@rightdown] )
  when :middle
    send_input( [@@middledown] )  
  else
    send_input( [@@leftdown] )
  end
end

#mouse_down_32(button_name) ⇒ Object



97
98
99
100
101
102
103
104
105
106
# File 'lib/auto_click.rb', line 97

def mouse_down_32(button_name)
  case button_name
  when :right
    send_input( [@@rightdown32] )
  when :middle
    send_input( [@@middledown32] )  
  else
    send_input( [@@leftdown32] )
  end
end

#mouse_move(x, y) ⇒ Object



25
26
27
# File 'lib/auto_click.rb', line 25

def mouse_move(x,y)
  User32.SetCursorPos(x,y)
end

#mouse_move_percentage(x, y) ⇒ Object



29
30
31
32
# File 'lib/auto_click.rb', line 29

def mouse_move_percentage(x,y)
  screen_resolution = get_screen_resolution()
  User32.SetCursorPos(get_screen_resolution[0]*x,get_screen_resolution[1]*y)
end

#mouse_scroll(d) ⇒ Object



171
172
173
174
# File 'lib/auto_click.rb', line 171

def mouse_scroll(d) 
  scroll = InputStructure.mouse_input(0,0,d*120,0x0800)
  send_input( [scroll])
end

#mouse_up(button_name) ⇒ Object



58
59
60
61
62
63
64
65
66
67
# File 'lib/auto_click.rb', line 58

def mouse_up(button_name)
  case button_name
  when :right
    send_input( [@@rightup] )
  when :middle
    send_input( [@@middleup] )  
  else
    send_input( [@@leftup] )
  end
end

#mouse_up_32(button_name) ⇒ Object



108
109
110
111
112
113
114
115
116
117
# File 'lib/auto_click.rb', line 108

def mouse_up_32(button_name)
  case button_name
  when :right
    send_input( [@@rightup32] )
  when :middle
    send_input( [@@middleup32] )  
  else
    send_input( [@@leftup32] )
  end
end

#right_clickObject



35
36
37
# File 'lib/auto_click.rb', line 35

def right_click
  send_input( [@@rightdown, @@rightup] )
end

#right_click_32Object



85
86
87
# File 'lib/auto_click.rb', line 85

def right_click_32
  send_input( [@@rightdown32, @@rightup32] )
end

#right_drag(sx, sy, ex, ey) ⇒ Object



188
189
190
191
192
193
194
195
196
197
# File 'lib/auto_click.rb', line 188

def right_drag(sx,sy,ex,ey)
  mouse_move sx,sy
  sleep 0.1
  send_input( [@@rightdown] )
  sleep 0.1
  mouse_move ex,ey
  sleep 0.1
  send_input( [@@rightup] )
  sleep 0.1
end

#right_drag_32(sx, sy, ex, ey) ⇒ Object



136
137
138
139
140
141
142
143
144
145
# File 'lib/auto_click.rb', line 136

def right_drag_32(sx,sy,ex,ey)
  mouse_move sx,sy
  sleep 0.1
  send_input( [@@rightdown32] )
  sleep 0.1
  mouse_move ex,ey
  sleep 0.1
  send_input( [@@rightup32] )
  sleep 0.1
end

#send_input(inputs) ⇒ Object



15
16
17
18
19
# File 'lib/auto_click.rb', line 15

def send_input(inputs)
  n = inputs.size
  ptr = inputs.collect {|i| i.to_s}.join
  User32.SendInput(n, ptr, inputs[0].size)    
end

#type(string) ⇒ Object



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# File 'lib/auto_click.rb', line 215

def type(string)
  key_stroke(:capslock) if get_key_state(:capslock)==1
  string=string.to_s
  string.each_char do |c|
    if ('a'..'z').include? c
      key_stroke(c.to_sym)
    elsif ('A'..'Z').include? c
      key_down(:leftshift)
      key_stroke(c.to_sym)
      key_up(:leftshift)
    elsif ('0'..'9').include? c
      key_stroke(('num'+c).to_sym)
    else
      case c
      when ' '
        key_stroke(:space)
      when ';'
        key_stroke(:semicolon)
      when ':'
        key_down(:leftshift)
        key_stroke(:semicolon)
        key_up(:leftshift)
      when '='
        key_stroke(:equal)
      when '+'
        key_down(:leftshift)
        key_stroke(:plus)
        key_up(:leftshift)
      when ','
        key_stroke(:comma)
      when '<'
        key_down(:leftshift)
        key_stroke(:smallerthan)
        key_up(:leftshift)  
      when '-'
        key_stroke(:hyphen)
      when '_'
        key_down(:leftshift)
        key_stroke(:underscore)
        key_up(:leftshift)
      when '.'
        key_stroke(:period)
      when '>'
        key_down(:leftshift)
        key_stroke(:greaterthan)
        key_up(:leftshift)
      when '/'
        key_stroke(:slash)
      when '?'
        key_down(:leftshift)
        key_stroke(:question)
        key_up(:leftshift)
      when '`'
        key_stroke(:grave)
      when '~'
        key_down(:leftshift)
        key_stroke(:tilde)
        key_up(:leftshift)
      when '/'
        key_stroke(:slash)
      when '?'
        key_down(:leftshift)
        key_stroke(:question)
        key_up(:leftshift)  
      when '['
        key_stroke(:branket)
      when '{'
        key_down(:leftshift)
        key_stroke(:branket)
        key_up(:leftshift)
      when ']'
        key_stroke(:closebranket)
      when '}'
        key_down(:leftshift)
        key_stroke(:closebranket)
        key_up(:leftshift)
      when '\\'   # You need to esapce \ in the parameter string
        key_stroke(:backslash)
      when '|'
        key_down(:leftshift)
        key_stroke(:pipe)
        key_up(:leftshift)
      when '\''   # escape ' only for single quote string
        key_stroke(:quote)
      when '"'    # escape " only for double quote string
        key_down(:leftshift)
        key_stroke(:doublequote)
        key_up(:leftshift)
      when '!'
        key_down(:leftshift)
        key_stroke(:num1)
        key_up(:leftshift)
      when '@'
        key_down(:leftshift)
        key_stroke(:num2)
        key_up(:leftshift)  
      when '#'    # The sharp sign need to be escape in single quote string
        key_down(:leftshift)
        key_stroke(:num3)
        key_up(:leftshift)
      when '$'
        key_down(:leftshift)
        key_stroke(:num4)
        key_up(:leftshift)
      when '%'
        key_down(:leftshift)
        key_stroke(:num5)
        key_up(:leftshift)
      when '^'
        key_down(:leftshift)
        key_stroke(:num6)
        key_up(:leftshift)
      when '&'
        key_down(:leftshift)
        key_stroke(:num7)
        key_up(:leftshift)  
      when '*'
        key_down(:leftshift)
        key_stroke(:num8)
        key_up(:leftshift)
      when '('
        key_down(:leftshift)
        key_stroke(:num9)
        key_up(:leftshift)
      when ')'
        key_down(:leftshift)
        key_stroke(:num0)
        key_up(:leftshift)  
      end
      
    end
  end
end