au3 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/AutoItX3/au3.rb +291 -0
- data/lib/AutoItX3/control.rb +545 -0
- data/lib/AutoItX3/filedir.rb +99 -0
- data/lib/AutoItX3/graphic.rb +32 -0
- data/lib/AutoItX3/keyboard.rb +166 -0
- data/lib/AutoItX3/misc.rb +105 -0
- data/lib/AutoItX3/mouse.rb +130 -0
- data/lib/AutoItX3/process.rb +152 -0
- data/lib/AutoItX3/window.rb +411 -0
- data/lib/HISTORY.rdoc +19 -0
- data/lib/README.rdoc +71 -0
- data/lib/au3.rb +2 -0
- data/test/test_clipboard.rb +19 -0
- data/test/test_ini.rb +48 -0
- data/test/test_keyboard.rb +61 -0
- data/test/test_mouse.rb +43 -0
- data/test/test_process.rb +50 -0
- data/test/test_tray.rb +29 -0
- data/test/test_window.rb +104 -0
- metadata +101 -0
@@ -0,0 +1,99 @@
|
|
1
|
+
#Encoding: UTF-8
|
2
|
+
#This file is part of au3.
|
3
|
+
#Copyright © 2009 Marvin Gülker
|
4
|
+
#
|
5
|
+
#au3 is published under the same terms as Ruby.
|
6
|
+
#See http://www.ruby-lang.org/en/LICENSE.txt
|
7
|
+
|
8
|
+
module AutoItX3
|
9
|
+
|
10
|
+
class << self
|
11
|
+
|
12
|
+
#====Arguments
|
13
|
+
#Every | is ment to be a backslash.
|
14
|
+
#- device: The device letter to map the drive to, in the form <tt>"X:"</tt>. If this is an asterisk *, the next available letter will be used.
|
15
|
+
#- remote_share: The address of the network drive, in the form <tt>"||Server|Drive"</tt> or <tt>"||Server|Share"</tt>.
|
16
|
+
#- flags (0): A combination (via +) of 1 (PersistantMapping) and 8 (Show authentification dialog if neccessary).
|
17
|
+
#- username (""): The username, of the form <tt>"username"</tt> or <tt>"Domain|username"</tt>.
|
18
|
+
#- password (""): The login password.
|
19
|
+
#====Description
|
20
|
+
#Maps a network drive and raises an Au3Error if the action is not successful.
|
21
|
+
def add_drive_map(device, remote_share, flags = 0, username = "", password = "")
|
22
|
+
@functions[__method__] ||= AU3_Function.new("DriveMapAdd", 'SSLSSPI')
|
23
|
+
buffer = " " * BUFFER_SIZE
|
24
|
+
buffer.wide!
|
25
|
+
@functions[__method__].call(device, remote_share, flags, username, password, buffer, buffer.size - 1)
|
26
|
+
|
27
|
+
case last_error
|
28
|
+
when 1 then raise(Au3Error, "Unknown error occured while mapping network drive!")
|
29
|
+
when 2 then raise(Au3Error, "Access denied!")
|
30
|
+
when 3 then raise(Au3Error, "Device '#{device}' is already assigned!")
|
31
|
+
when 4 then raise(Au3Error, "Invalid device name '#{device}'!")
|
32
|
+
when 5 then raise(Au3Error, "Invalid remote share '#{remote_share}'!")
|
33
|
+
when 6 then raise(Au3Error, "The password is incorrect!")
|
34
|
+
else return buffer.normal.strip
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
#Disconnects a network drive. +device+ can be either of form <tt>"X:"</tt> or
|
39
|
+
#<tt>"||Server|share"</tt> (imagine every | to be a backslash).
|
40
|
+
#Raises an Au3Error if the disconnection was unsucsessful.
|
41
|
+
def delete_drive_map(device)
|
42
|
+
@functions[__method__] ||= AU3_Function.new("DriveMapDel", 'S', 'L')
|
43
|
+
result = @functions[__method__].call(device)
|
44
|
+
if result == 0
|
45
|
+
raise(Au3Error, "Failed to remove remote device '#{device}'!")
|
46
|
+
end
|
47
|
+
true
|
48
|
+
end
|
49
|
+
|
50
|
+
#Gets the server of the network drive named by +device+ or raises an Au3Error if it
|
51
|
+
#can't access the device for some reason. The returned string will be of form
|
52
|
+
#<tt>"||Server|drive"</tt> (every | is ment to be a backslash).
|
53
|
+
def get_drive_map(device)
|
54
|
+
@functions[__method__] ||= AU3_Function.new("DriveMapGet", 'SPI')
|
55
|
+
buffer = " " * BUFFER_SIZE
|
56
|
+
buffer.wide!
|
57
|
+
ret = @functions[__method__].call(device, buffer, buffer.size - 1)
|
58
|
+
|
59
|
+
if last_error == 1
|
60
|
+
raise(Au3Error, "Failed to retrieve information about device '#{device}'")
|
61
|
+
end
|
62
|
+
buffer.normal.strip
|
63
|
+
end
|
64
|
+
|
65
|
+
#Deletes a key-value pair in a standard <tt>.ini</tt> file.
|
66
|
+
def delete_ini_entry(filename, section, key)
|
67
|
+
@functions[__method__] ||= AU3_Function.new("IniDelete", 'SSS', 'L')
|
68
|
+
if @functions[__method__].call(filename.wide, section.wide, key.wide) == 0
|
69
|
+
false
|
70
|
+
else
|
71
|
+
true
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
#Reads a value from a standard <tt>.ini</tt> file or returns the string given by +default+
|
76
|
+
#if it can't find the key. The returned string will have a maximum length of 99,999 characters.
|
77
|
+
def read_ini_entry(filename, section, key, default = nil)
|
78
|
+
@functions[__method__] ||= AU3_Function.new("IniRead", 'SSSSPI')
|
79
|
+
buffer = " " * BUFFER_SIZE
|
80
|
+
buffer.wide!
|
81
|
+
@functions[__method__].call(filename.wide, section.wide, key.wide, default.to_s.wide, buffer, buffer.size - 1)
|
82
|
+
buffer.normal.strip
|
83
|
+
end
|
84
|
+
|
85
|
+
#Writes the specified key-value pair in a <tt>.ini</tt> file. Existing key-value pairs are overwritten.
|
86
|
+
#A non-existing file will be created. Raises an Au3Error if +filename+ is read-only.
|
87
|
+
def write_ini_entry(filename, section, key_value, value)
|
88
|
+
@functions[__method__] ||= AU3_Function.new("IniWrite", 'SSSS', 'L')
|
89
|
+
|
90
|
+
if @functions[__method__].call(filename.wide, section.wide, key_value.wide, value.wide) == 0
|
91
|
+
raise(Au3Error, "Cannot open file for write access!")
|
92
|
+
else
|
93
|
+
value
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end #au3single
|
98
|
+
|
99
|
+
end #AutoItX3
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#Encoding: UTF-8
|
2
|
+
#This file is part of au3.
|
3
|
+
#Copyright © 2009 Marvin Gülker
|
4
|
+
#
|
5
|
+
#au3 is published under the same terms as Ruby.
|
6
|
+
#See http://www.ruby-lang.org/en/LICENSE.txt
|
7
|
+
|
8
|
+
module AutoItX3
|
9
|
+
|
10
|
+
class << self
|
11
|
+
|
12
|
+
#Computes a checksum of the pixels in the specified region. If the checksum
|
13
|
+
#changes, that only indidcates that *something* has changed, not *what*.
|
14
|
+
#Note that this method may be very time-consuming, so think about increasing the
|
15
|
+
#+step+ parameter (but bear in mind that that will generate more inaccurate checksums).
|
16
|
+
def pixel_checksum(x1, y1, x2, y2, step = 1)
|
17
|
+
@functions[__method__] ||= AU3_Function.new("PixelChecksum", 'LLLLL', 'L')
|
18
|
+
@functions[__method__].call(x1, y1, x2, y2, step)
|
19
|
+
end
|
20
|
+
|
21
|
+
#Retrieves the *decimal* color value of a pixel. If you want the hexadecimal,
|
22
|
+
#pass in true as a third parameter.
|
23
|
+
def get_pixel_color(x, y, hex = false)
|
24
|
+
@functions[__method__] ||= AU3_Function.new("PixelGetColor", 'LL', 'L')
|
25
|
+
res = @functions[__method__].call(x, y)
|
26
|
+
return "#" + res.to_s(16).upcase if hex
|
27
|
+
res
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
#Encoding: UTF-8
|
2
|
+
#This file is part of au3.
|
3
|
+
#Copyright © 2009 Marvin Gülker
|
4
|
+
#
|
5
|
+
#au3 is published under the same terms as Ruby.
|
6
|
+
#See http://www.ruby-lang.org/en/LICENSE.txt
|
7
|
+
|
8
|
+
module AutoItX3
|
9
|
+
|
10
|
+
class << self
|
11
|
+
|
12
|
+
#Simulates the given keystrokes. If you don't
|
13
|
+
#set +flag+ to true (which disables escape sequences), you may
|
14
|
+
#use some of the follwing escape sequences in braces { and }
|
15
|
+
#(copied from the AutoItX3 help):
|
16
|
+
# Escape sequence | Resulting keypress
|
17
|
+
# ====================+============================================================
|
18
|
+
# ! | !
|
19
|
+
# --------------------+------------------------------------------------------------
|
20
|
+
# # | #
|
21
|
+
# --------------------+------------------------------------------------------------
|
22
|
+
# + | +
|
23
|
+
# --------------------+------------------------------------------------------------
|
24
|
+
# ^ | ^
|
25
|
+
# --------------------+------------------------------------------------------------
|
26
|
+
# { | {
|
27
|
+
# --------------------+------------------------------------------------------------
|
28
|
+
# } | }
|
29
|
+
# --------------------+------------------------------------------------------------
|
30
|
+
# SPACE | SPACE
|
31
|
+
# --------------------+------------------------------------------------------------
|
32
|
+
# ENTER | Return on the main keyboard
|
33
|
+
# --------------------+------------------------------------------------------------
|
34
|
+
# ALT | Alt
|
35
|
+
# --------------------+------------------------------------------------------------
|
36
|
+
# BACKSPACE or BS | Backspace
|
37
|
+
# --------------------+------------------------------------------------------------
|
38
|
+
# DELETE or DEL | Del
|
39
|
+
# --------------------+------------------------------------------------------------
|
40
|
+
# UP | Up arrow
|
41
|
+
# --------------------+------------------------------------------------------------
|
42
|
+
# DOWN | Down arrow
|
43
|
+
# --------------------+------------------------------------------------------------
|
44
|
+
# LEFT | Left arrow
|
45
|
+
# --------------------+------------------------------------------------------------
|
46
|
+
# RIGHT | Right arrow
|
47
|
+
# --------------------+------------------------------------------------------------
|
48
|
+
# HOME | Home
|
49
|
+
# --------------------+------------------------------------------------------------
|
50
|
+
# END | End
|
51
|
+
# --------------------+------------------------------------------------------------
|
52
|
+
# ESCAPE or ESC | ESC
|
53
|
+
# --------------------+------------------------------------------------------------
|
54
|
+
# INSERT or INS | Ins
|
55
|
+
# --------------------+------------------------------------------------------------
|
56
|
+
# PGUP | Page Up
|
57
|
+
# --------------------+------------------------------------------------------------
|
58
|
+
# PGDN | Page Down
|
59
|
+
# --------------------+------------------------------------------------------------
|
60
|
+
# F1 - F12 | Function keys 1 to 12
|
61
|
+
# --------------------+------------------------------------------------------------
|
62
|
+
# TAB | Tab
|
63
|
+
# --------------------+------------------------------------------------------------
|
64
|
+
# PRINTSCREEN | Printscreen
|
65
|
+
# --------------------+------------------------------------------------------------
|
66
|
+
# LWIN | Left Windows key
|
67
|
+
# --------------------+------------------------------------------------------------
|
68
|
+
# RWIN | Right Windows key
|
69
|
+
# --------------------+------------------------------------------------------------
|
70
|
+
# NUMLOCK on | NumLock on
|
71
|
+
# --------------------+------------------------------------------------------------
|
72
|
+
# CAPSLOCK off | CapsLock off
|
73
|
+
# --------------------+------------------------------------------------------------
|
74
|
+
# SCROLLLOCK toggle | ScrollLock toggle
|
75
|
+
# --------------------+------------------------------------------------------------
|
76
|
+
# BREAK | For CTRL-Break processing
|
77
|
+
# --------------------+------------------------------------------------------------
|
78
|
+
# PAUSE | Pause
|
79
|
+
# --------------------+------------------------------------------------------------
|
80
|
+
# NUMPAD0 - NUMPAD9 | Numpad number keys.
|
81
|
+
# --------------------+------------------------------------------------------------
|
82
|
+
# NUMPADMUTLT | Numpad Multipy
|
83
|
+
# --------------------+------------------------------------------------------------
|
84
|
+
# NUMPADADD | Numpad Add
|
85
|
+
# --------------------+------------------------------------------------------------
|
86
|
+
# NUMPADSUBT | Numpad Subtract
|
87
|
+
# --------------------+------------------------------------------------------------
|
88
|
+
# NUMPADDIV | Numpad Division
|
89
|
+
# --------------------+------------------------------------------------------------
|
90
|
+
# NUMPADDOT | Numpad dot
|
91
|
+
# --------------------+------------------------------------------------------------
|
92
|
+
# NUMPADENTER | Numpad return key
|
93
|
+
# --------------------+------------------------------------------------------------
|
94
|
+
# APPSKEY | Windows App key
|
95
|
+
# --------------------+------------------------------------------------------------
|
96
|
+
# LALT | Left Alt key
|
97
|
+
# --------------------+------------------------------------------------------------
|
98
|
+
# RALT | Right Alt key
|
99
|
+
# --------------------+------------------------------------------------------------
|
100
|
+
# LCTRL | Left control key
|
101
|
+
# --------------------+------------------------------------------------------------
|
102
|
+
# LSHIFT | Left Shift key
|
103
|
+
# --------------------+------------------------------------------------------------
|
104
|
+
# RSHIFT | Right Shift key
|
105
|
+
# --------------------+------------------------------------------------------------
|
106
|
+
# SLEEP | Computer Sleep key
|
107
|
+
# --------------------+------------------------------------------------------------
|
108
|
+
# ALTDOWN | Hold Alt down until ALTUP is sent
|
109
|
+
# --------------------+------------------------------------------------------------
|
110
|
+
# SHIFTDOWN | Hold Shift down until SHIFTUP is sent
|
111
|
+
# --------------------+------------------------------------------------------------
|
112
|
+
# CTRLDOWN | Hold CTRL down until CTRLUP is sent
|
113
|
+
# --------------------+------------------------------------------------------------
|
114
|
+
# LWINDOWN | Hold the left Windows key down until LWDINUP is sent
|
115
|
+
# --------------------+------------------------------------------------------------
|
116
|
+
# RWINDOWN | Hold the right Windows key down until RWINUP is sent
|
117
|
+
# --------------------+------------------------------------------------------------
|
118
|
+
# ASC nnnn | Send the kombination Alt+nnnn on numpad
|
119
|
+
# --------------------+------------------------------------------------------------
|
120
|
+
# BROWSER_BACK | 2000/XP Only: Select the browser "back" button
|
121
|
+
# --------------------+------------------------------------------------------------
|
122
|
+
# BROWSER_FORWARD | 2000/XP Only: Select the browser "forward" button
|
123
|
+
# --------------------+------------------------------------------------------------
|
124
|
+
# BROWSER_REFRESH | 2000/XP Only: Select the browser "refresh" button
|
125
|
+
# --------------------+------------------------------------------------------------
|
126
|
+
# BROWSER_STOP | 2000/XP Only: Select the browser "stop" button
|
127
|
+
# --------------------+------------------------------------------------------------
|
128
|
+
# BROWSER_SEARCH | 2000/XP Only: Select the browser "search" button
|
129
|
+
# --------------------+------------------------------------------------------------
|
130
|
+
# BROWSER_FAVORITES | 2000/XP Only: Select the browser "favorites" button
|
131
|
+
# --------------------+------------------------------------------------------------
|
132
|
+
# BROWSER_HOME | 2000/XP Only: Launch the browser and go to the home page
|
133
|
+
# --------------------+------------------------------------------------------------
|
134
|
+
# VOLUME_MUTE | 2000/XP Only: Mute the volume
|
135
|
+
# --------------------+------------------------------------------------------------
|
136
|
+
# VOLUME_DOWN | 2000/XP Only: Reduce the volume
|
137
|
+
# --------------------+------------------------------------------------------------
|
138
|
+
# VOLUME_UP | 2000/XP Only: Increase the volume
|
139
|
+
# --------------------+------------------------------------------------------------
|
140
|
+
# MEDIA_NEXT | 2000/XP Only: Select next track in media player
|
141
|
+
# --------------------+------------------------------------------------------------
|
142
|
+
# MEDIA_PREV | 2000/XP Only: Select previous track in media player
|
143
|
+
# --------------------+------------------------------------------------------------
|
144
|
+
# MEDIA_STOP | 2000/XP Only: Stop media player
|
145
|
+
# --------------------+------------------------------------------------------------
|
146
|
+
# MEDIA_PLAY_PAUSE | 2000/XP Only: Play/pause media player
|
147
|
+
# --------------------+------------------------------------------------------------
|
148
|
+
# LAUNCH_MAIL | 2000/XP Only: Launch the email application
|
149
|
+
# --------------------+------------------------------------------------------------
|
150
|
+
# LAUNCH_MEDIA | 2000/XP Only: Launch media player
|
151
|
+
# --------------------+------------------------------------------------------------
|
152
|
+
# LAUNCH_APP1 | 2000/XP Only: Launch user app1
|
153
|
+
# --------------------+------------------------------------------------------------
|
154
|
+
# LAUNCH_APP2 | 2000/XP Only: Launch user app2
|
155
|
+
#
|
156
|
+
#A "!" in +keys+ indicates an ALT keystroke,
|
157
|
+
#the "+" means SHIFT, "^" CTRL
|
158
|
+
#and "#" is the Windows key.
|
159
|
+
def send_keys(keys, flag = false)
|
160
|
+
@functions[__method__] ||= AU3_Function.new("Send", 'SL')
|
161
|
+
@functions[__method__].call(keys.wide, flag)
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
#Encoding: UTF-8
|
2
|
+
#This file is part of au3.
|
3
|
+
#Copyright © 2009 Marvin Gülker
|
4
|
+
#
|
5
|
+
#au3 is published under the same terms as Ruby.
|
6
|
+
#See http://www.ruby-lang.org/en/LICENSE.txt
|
7
|
+
|
8
|
+
module AutoItX3
|
9
|
+
|
10
|
+
class << self
|
11
|
+
|
12
|
+
#Blocks user input or enables it (but the user can gain back control by
|
13
|
+
#pressing [CTRL] + [ALT] + [DEL]). In older versions of Windows,
|
14
|
+
#AutoIt may also be blocked. Does not work with Windows Vista.
|
15
|
+
def block_input=(val)
|
16
|
+
@functions[__method__] ||= AU3_Function.new("BlockInput", 'L')
|
17
|
+
@functions[__method__].call(!!val)
|
18
|
+
@input_blocked = !!val
|
19
|
+
end
|
20
|
+
|
21
|
+
#Returns wheather or not input is blocked by AutoItX3.
|
22
|
+
def input_blocked?
|
23
|
+
@input_blocked ||= false
|
24
|
+
end
|
25
|
+
|
26
|
+
#Opens the cd drive named in +drive+. +drive+ should be of form
|
27
|
+
#<tt>"X:"</tt>. The cd tray must be local at this computer, remote drives
|
28
|
+
#cannot be accessed.
|
29
|
+
def open_cd_tray(tray)
|
30
|
+
@functions[__method__] ||= AU3_Function.new("CDTray", 'SS', 'L')
|
31
|
+
raise(ArgumentError, "The drive name has to be of form 'X:'!") unless tray =~ /^\w:$/
|
32
|
+
if @functions[__method__].call(tray.wide, "open".wide) == 0
|
33
|
+
return false
|
34
|
+
else
|
35
|
+
return true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
#Closes a cd tray. +drive+ should be of form <tt>"X:"</tt>. The cd tray must
|
40
|
+
#be local at this computer, remote drives cannot be accessed.
|
41
|
+
#The method may return true if +drive+ is a laptop drive which can only be
|
42
|
+
#closed manually.
|
43
|
+
def close_cd_tray(tray)
|
44
|
+
@functions[__method__] ||= AU3_Function.new("CDTray", 'SS', 'L')
|
45
|
+
raise(ArgumentError, "The drive name has to be of form 'X:'!") unless tray =~ /^\w:$/
|
46
|
+
if @functions[__method__].call(tray.wide, "closed".wide) == 0
|
47
|
+
return false
|
48
|
+
else
|
49
|
+
return true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
#Determines wheather the current user has administrator privileges.
|
54
|
+
def is_admin?
|
55
|
+
@functions[__method__] ||= AU3_Function.new("IsAdmin", 'V', 'L')
|
56
|
+
return false if @functions[__method__].call == 0
|
57
|
+
true
|
58
|
+
end
|
59
|
+
|
60
|
+
#Writes +text+ to the Windows clipboard.
|
61
|
+
#You can't write NUL characters to the clipboard, the text will
|
62
|
+
#be terminated.
|
63
|
+
def cliptext=(text)
|
64
|
+
@functions[__method__] ||= AU3_Function.new("ClipPut", 'S')
|
65
|
+
@functions[__method__].call(text.wide)
|
66
|
+
text
|
67
|
+
end
|
68
|
+
|
69
|
+
#Returns the text saved in the clipboard. It will be truncated at the 99,999th character or
|
70
|
+
#at a NUL char.
|
71
|
+
def cliptext
|
72
|
+
@functions[__method__] ||= AU3_Function.new("ClipGet", 'PL')
|
73
|
+
cliptext = " " * BUFFER_SIZE
|
74
|
+
cliptext.wide!
|
75
|
+
@functions[__method__].call(cliptext, cliptext.size - 1)
|
76
|
+
cliptext.normal.strip
|
77
|
+
end
|
78
|
+
|
79
|
+
#call-seq:
|
80
|
+
# tool_tip( text [, x = INTDEFAULT [, y = INTDEFAULT ] ] ) ==> nil
|
81
|
+
# tooltip( text [, x = INTDEFAULT [, y = INTDEFAULT ] ] ) ==> nil
|
82
|
+
#
|
83
|
+
#Displays a tooltip at the given position. If +x+ and +y+ are ommited,
|
84
|
+
#the tooltip will be displayed at the current cursor position. Coordinates
|
85
|
+
#out of range are automatically corrected.
|
86
|
+
#The tooltip will be deleted when the program ends, or after a system-dependent
|
87
|
+
#timeout.
|
88
|
+
def tool_tip(text, x = INTDEFAULT, y = INTDEFAULT)
|
89
|
+
@functions[__method__] ||= AU3_Function.new("ToolTip", 'SLL')
|
90
|
+
@functions[__method__].call(text.wide, x, y)
|
91
|
+
end
|
92
|
+
alias tooltip tool_tip
|
93
|
+
|
94
|
+
#Wait for the specified amount of milliseconds. In AutoIt, this function is named
|
95
|
+
#"Sleep", but to avoid compatibility issues with Ruby's own sleep I decided to
|
96
|
+
#name the function "msleep" (the "m" indicates "milli"). If you wish to name it
|
97
|
+
#"sleep", simply define an alias.
|
98
|
+
def msleep(msecs)
|
99
|
+
@functions[__method__] ||= AU3_Function.new("Sleep", 'L')
|
100
|
+
@functions[__method__].call(msecs)
|
101
|
+
end
|
102
|
+
|
103
|
+
end #au3single
|
104
|
+
|
105
|
+
end #AutoItX3
|
@@ -0,0 +1,130 @@
|
|
1
|
+
#Encoding: UTF-8
|
2
|
+
#This file is part of au3.
|
3
|
+
#Copyright © 2009 Marvin Gülker
|
4
|
+
#
|
5
|
+
#au3 is published under the same terms as Ruby.
|
6
|
+
#See http://www.ruby-lang.org/en/LICENSE.txt
|
7
|
+
|
8
|
+
module AutoItX3
|
9
|
+
|
10
|
+
#Unknown cursor icon
|
11
|
+
UNKNOWN_CURSOR = 0
|
12
|
+
#Application starting cursor (arrow with a hourglass next to it)
|
13
|
+
APP_STARTING_CURSOR = 1
|
14
|
+
#The normal cursor
|
15
|
+
ARROW_CURSOR = 2
|
16
|
+
#Cross cursor
|
17
|
+
CROSS_CURSOR = 3
|
18
|
+
#Cursor with a question mark next to it
|
19
|
+
HELP_CURSOR = 4
|
20
|
+
#Cursor for editing lines of text
|
21
|
+
IBEAM_CURSOR = 5
|
22
|
+
ICON_CURSOR = 6
|
23
|
+
#Cursor for forbidden actions (a circle with a strike through it)
|
24
|
+
NO_CURSOR = 7
|
25
|
+
SIZE_CURSOR = 8
|
26
|
+
SIZE_ALL_CURSOR = 9
|
27
|
+
SIZE_NESW_CURSOR = 10
|
28
|
+
SIZE_NS_CURSOR = 11
|
29
|
+
SIZE_NWSE_CURSOR = 12
|
30
|
+
SIZE_WE_CURSOR = 13
|
31
|
+
UP_ARROW_CURSOR = 14
|
32
|
+
#Wait (the well-known "hourglass")
|
33
|
+
WAIT_CURSOR = 15
|
34
|
+
|
35
|
+
class << self
|
36
|
+
|
37
|
+
#====Arguments
|
38
|
+
#- x (INTDEFAULT): The X position. The cursor's current X if not specified.
|
39
|
+
#- y (INTDEFAULT): The Y position. The cursor's current Y if not specified.
|
40
|
+
#- button("Primary"): The mouse button to click width. On a mouse for left-handed people the right, for right-handed people the left mouse button.
|
41
|
+
#- clicks(1): The number of times to click.
|
42
|
+
#- speed(10): The speed the mouse cursor will move with. If set to 0, the cursor is set immediatly.
|
43
|
+
#
|
44
|
+
#Clicks the mouse.
|
45
|
+
def mouse_click(x = INTDEFAULT, y = INTDEFAULT, button = "Primary", clicks = 1, speed = 10)
|
46
|
+
@functions[__method__] ||= AU3_Function.new("MouseClick", 'SLLLL', 'L')
|
47
|
+
@functions[__method__].call(button.wide, x, y, clicks, speed)
|
48
|
+
|
49
|
+
raise(Au3Error, "Invalid button '#{button}'!") if last_error == 1
|
50
|
+
nil
|
51
|
+
end
|
52
|
+
|
53
|
+
#Performes a drag & drop operation with the given parameters.
|
54
|
+
def drag_mouse(x1, y1, x2, y2, button = "Primary", speed = 10)
|
55
|
+
@functions[__method__] ||= AU3_Function.new("MouseClickDrag", 'SLLLLL', 'L')
|
56
|
+
@functions[__method__].call(button.wide, x1, y1, x2, y2, speed)
|
57
|
+
|
58
|
+
raise(Au3Error, "Invalid button '#{button}'!") if last_error == 1
|
59
|
+
nil
|
60
|
+
end
|
61
|
+
|
62
|
+
#call-seq:
|
63
|
+
# hold_mouse_down( [ button = "Primary" ] ) ==> nil
|
64
|
+
# mouse_down( [ button = "Primary" ] ) ==> nil
|
65
|
+
#
|
66
|
+
#Holds a mouse button down (the left by default, or the right if mouse buttons are swapped).
|
67
|
+
#You should release the mouse button somewhen.
|
68
|
+
def hold_mouse_down(button = "Primary")
|
69
|
+
@functions[__method__] ||= AU3_Function.new("MouseDown", 'S')
|
70
|
+
@functions[__method__].call(button.wide)
|
71
|
+
nil
|
72
|
+
end
|
73
|
+
|
74
|
+
#call-seq:
|
75
|
+
# cursor_id ==> aFixnum
|
76
|
+
# get_cursor_id ==> aFixnum
|
77
|
+
#
|
78
|
+
#Returns one of the *_CURSOR constants to indicate which cursor icon is actually shown.
|
79
|
+
def cursor_id
|
80
|
+
@functions[__method__] ||= AU3_Function.new("MouseGetCursor", '', 'L')
|
81
|
+
@functions[__method__].call
|
82
|
+
end
|
83
|
+
|
84
|
+
#call-seq:
|
85
|
+
# cursor_pos ==> anArray
|
86
|
+
# get_cursor_pos ==> anArray
|
87
|
+
#
|
88
|
+
#Returns the current cursor position in a two-element array of form <tt>[x, y]</tt>.
|
89
|
+
def cursor_pos
|
90
|
+
@functions[:cursor_pos_x] ||= AU3_Function.new("MouseGetPosX", 'V', 'L')
|
91
|
+
@functions[:cursor_pos_y] ||= AU3_Function.new("MouseGetPosY", 'V', 'L')
|
92
|
+
[@functions[:cursor_pos_x].call, @functions[:cursor_pos_y].call]
|
93
|
+
end
|
94
|
+
|
95
|
+
#call-seq:
|
96
|
+
# move_mouse( x , y [, speed = 10 ] ) ==> nil
|
97
|
+
# mouse_move( x , y [, speed = 10 ] ) ==> nil
|
98
|
+
#
|
99
|
+
#Moves the mouse cursor to the given position. If +speed+ is 0,
|
100
|
+
#it's set immediately.
|
101
|
+
def move_mouse(x, y, speed = 10)
|
102
|
+
@functions[__method__] ||= AU3_Function.new("MouseMove", 'LLL', 'L')
|
103
|
+
@functions[__method__].call(x, y, speed)
|
104
|
+
nil
|
105
|
+
end
|
106
|
+
|
107
|
+
#call-seq:
|
108
|
+
# release_mouse( [ button = "Primary" ] ) ==> nil
|
109
|
+
# mouse_up( [ button = "Primary" ] ) ==> nil
|
110
|
+
#
|
111
|
+
#Releases a mouse button hold down by #hold_mouse_down.
|
112
|
+
def release_mouse(button = "Primary")
|
113
|
+
@functions[__method__] ||= AU3_Function.new("MouseUp", 'S')
|
114
|
+
@functions[__method__].call(button.wide)
|
115
|
+
nil
|
116
|
+
end
|
117
|
+
|
118
|
+
#Scrolls up or down the mouse wheel +times+ times. Use
|
119
|
+
#ether "Up" or "Down" as the value for +direction+.
|
120
|
+
def mouse_wheel(direction, times = 5)
|
121
|
+
@functions[__method__] ||= AU3_Function.new("MouseWheel", 'SL')
|
122
|
+
@functions[__method__].call(direction.wide, times)
|
123
|
+
|
124
|
+
raise(Au3Error, "Undefined mouse wheel direction '#{direction}!") if last_error == 1
|
125
|
+
nil
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|