au3 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/HISTORY.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ =History of au3
2
+ Important changes are marked <b>bold</b>.
3
+ ==0.1.0
4
+ * <b>Changed the API to use win32-api now instead of a C extension</b>
5
+ * <b>Added wide, wide!, normal and normal! to Ruby's String class</b>
6
+ * Added the AutoItX3::AU3_Function class
7
+ * <b>Added a block form to set_opt and opt that resets the options after executing the code block</b>
8
+ * <b>Added an optional third parameter to AutoItX3.get_pixel_color for returning hexadecimal strings</b>
9
+ * Changed the default value of the second parameter of send_keys from 0 to false, according to Ruby's style
10
+ * Changed the return value of run_as_set to nil instead of true
11
+ * Added Window.functions and Window.functions= to avoid multiple AU3_Function objects for different instances of Window
12
+ * <b>Added Window#valid? as an alias for Window#exists?</b>
13
+ * Changed the return value of Control#click to nil instead of true
14
+ * Changed the return value of Control#disable to nil instead of true
15
+ * Changed the return value of Control#enable to nil instead of true
16
+ * Changed the return value of Control#focus to nil instead of true
17
+ * Changed the return value of Control#hide to nil instead of true
18
+ * Changed the return value of Control#move to nil instead of true
19
+ * Added Control.from_control to allow Controls to be transformed into a subclass
data/lib/README.rdoc ADDED
@@ -0,0 +1,71 @@
1
+ =au3
2
+ <tt>.au3</tt> is the usual file extension for {AutoIt version 3}[http://www.autoitscript.com/autoit3/index.shtml]
3
+ scripts. That this library uses it as its name, tells a lot about
4
+ its features. Basically, the +au3+ library can do everything
5
+ you can do with the <tt>.au3</tt> files:
6
+ * Automate the mouse
7
+ * Automate the keyboard
8
+ * Manipulate Windows
9
+ * etc.
10
+ However, there a a few exceptions, since +au3+ doesn't use
11
+ the AutoIt v3 interpreter behind the scenes. Instead, +au3+ is wrapped
12
+ around the DLL interface of AutoIt3, known as AutoItX3.
13
+ ==DLL problems: So to use this
14
+ As said, au3 is wrapped around AutoItX3. To get au3 working, you have
15
+ to have the file "AutoItX3.dll" somewhere in your PATH. The simplest way
16
+ to get this is just to download AutoIt from http://www.autoitscript.com
17
+ and copy the AutoItX3.dll file (I don't guarantee for the 64-bit version)
18
+ from the AutoItX subdirectory into the directory your script resides in.
19
+ Or, if you don't want to copy the file over and over again, put it in your Ruby's
20
+ bin directory. If you want to deploy your program, the final recipient need not
21
+ to have AutoIt installed - it's enough if you just include the AutoItX3.dll in your
22
+ application (and make sure you've read the AutoItX3 license - it's quite short).
23
+ ==Usage
24
+ The majority of +au3+'s methods is bundled the AutoItX3 module
25
+ and accessable via it's module methods. In order to get them,
26
+ just require +au3+:
27
+ require "au3"
28
+
29
+ AutoItX3.move_mouse(100, 100)
30
+ The window-related methods are put together in the
31
+ AutoItX3::Window class. That allows you to create
32
+ Rubyish Window objects rather than using the procedural
33
+ function interface of AutoItX3. You needn't have to require them
34
+ extra.
35
+ require "au3"
36
+
37
+ window = AutoItX3::Window.new("au3") #The beginning of a window's title is enough
38
+ window.close
39
+ Version 3 of AutoIt is known for its capabilities of direct
40
+ interaction with a window's controls. You will find this methods
41
+ wrapped in the AutoItX3::Control class.
42
+ require "au3"
43
+
44
+ #Run notepad
45
+ AutoItX3.run("notepad.exe")
46
+ #Wait for the window to exist
47
+ AutoItX3::Window.wait("Un") #The start of the title is enough to find it
48
+ #Get a reference to it
49
+ window = AutoItX3::Window.new("Un")
50
+ #Bring it to the front
51
+ window.activate
52
+ #Get the text control
53
+ edit = window.focused_control
54
+ #Set the text. You should also have a look on the AutoItX3.send_keys method.
55
+ edit.text = "ABCDEFG"
56
+ ===Don't know where to start?
57
+ Have a look at the documentation of the AutoItX3 module.
58
+ +au3+ is well documented and even if you don't find something
59
+ useful, you may just want to play around with it. ;-)
60
+ ==Copyright
61
+ Copyright © 2009 Marvin Gülker
62
+ Licensed under the same terms as Ruby (see http://www.ruby-lang.org/en/LICENSE.txt )
63
+ Initia in potestate nostra sunt, de eventu fortuna iudicat.
64
+ ==License
65
+ This program is free software: you can redistribute it and/or modify
66
+ it under the terms of Ruby's license.
67
+
68
+ This program is distributed in the hope that it will be useful,
69
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
70
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
71
+ Ruby's license for more details.
data/lib/au3.rb ADDED
@@ -0,0 +1,2 @@
1
+ #Encoding: UTF-8
2
+ require_relative("AutoItX3/au3.rb")
@@ -0,0 +1,19 @@
1
+ #Encoding: Windows-1252
2
+ #This file is part of au3.
3
+ #Copyright (c) 2009 Marvin G�lker
4
+ begin
5
+ require_relative "../lib/au3"
6
+ rescue LoadError
7
+ #Aha, this is the gem, not the build environment
8
+ require "au3"
9
+ end
10
+ require "test/unit"
11
+
12
+ class ClipboardTest < Test::Unit::TestCase
13
+
14
+ def test_clipboard
15
+ AutoItX3.cliptext = "HDGDL"
16
+ assert_equal("HDGDL", AutoItX3.cliptext)
17
+ end
18
+
19
+ end
data/test/test_ini.rb ADDED
@@ -0,0 +1,48 @@
1
+ #Encoding: Windows-1252
2
+ #This file is part of au3.
3
+ #Copyright (c) 2009 Marvin G�lker
4
+ begin
5
+ require_relative "../lib/au3"
6
+ rescue LoadError
7
+ #Aha, this is the gem, not the build environment
8
+ require "au3"
9
+ end
10
+ require "test/unit"
11
+
12
+ class IniTest < Test::Unit::TestCase
13
+
14
+ TEST_INI =<<EOF
15
+ [Section1]
16
+ key1=val1
17
+ [Section2]
18
+ key1=val2
19
+ EOF
20
+
21
+ INI_NAME = "test.ini"
22
+
23
+ def self.startup
24
+ File.open(INI_NAME, "w"){|f| f.write(TEST_INI)}
25
+ end
26
+
27
+ def test_read
28
+ assert_equal("val1", AutoItX3.read_ini_entry(INI_NAME, "Section1", "key1", ""))
29
+ assert_equal("val2", AutoItX3.read_ini_entry(INI_NAME, "Section2", "key1", ""))
30
+ assert_equal("XXX", AutoItX3.read_ini_entry(INI_NAME, "Section3", "key1", "XXX"))
31
+ end
32
+
33
+ def test_write
34
+ AutoItX3.write_ini_entry(INI_NAME, "NewSection", "key", "aValue")
35
+ assert_equal("aValue", AutoItX3.read_ini_entry(INI_NAME, "NewSection", "key", ""))
36
+ end
37
+
38
+ def test_delete
39
+ AutoItX3.write_ini_entry(INI_NAME, "ASection", "key", "aValue")
40
+ AutoItX3.delete_ini_entry(INI_NAME, "ASection", "key")
41
+ assert_equal("XXX", AutoItX3.read_ini_entry(INI_NAME, "ASection", "key", "XXX"))
42
+ end
43
+
44
+ def self.shutdown
45
+ File.delete(INI_NAME)
46
+ end
47
+
48
+ end
@@ -0,0 +1,61 @@
1
+ #Encoding: Windows-1252
2
+ #This file is part of au3.
3
+ #Copyright (c) 2009 Marvin G�lker
4
+ begin
5
+ require_relative "../lib/au3"
6
+ rescue LoadError
7
+ #Aha, this is the gem, not the build environment
8
+ require "au3"
9
+ end
10
+ require "test/unit"
11
+
12
+ class KeyboardTest < Test::Unit::TestCase
13
+
14
+ TEXT1 = "abc"
15
+ TEXT2 = "One with\nNewline"
16
+ TEXT3 = "With{TAB}tab"
17
+
18
+ def setup
19
+ @pid = AutoItX3.run("notepad", "", AutoItX3::Window::SW_MAXIMIZE)
20
+ sleep 2
21
+ AutoItX3.mouse_click(150, 150)
22
+ end
23
+
24
+ def teardown
25
+ AutoItX3.kill_process(@pid)
26
+ sleep 1
27
+ end
28
+
29
+ def copy_all
30
+ AutoItX3.send_keys("^a")
31
+ AutoItX3.msleep(200)
32
+ AutoItX3.send_keys("^c")
33
+ AutoItX3.msleep(200)
34
+ end
35
+
36
+ def delete_all
37
+ AutoItX3.send_keys("^a")
38
+ AutoItX3.msleep(200)
39
+ AutoItX3.send_keys("{BS}")
40
+ AutoItX3.msleep(200)
41
+ end
42
+
43
+ def test_send
44
+ AutoItX3.send_keys(TEXT1)
45
+ copy_all
46
+ assert_equal(TEXT1, AutoItX3.cliptext)
47
+ delete_all
48
+ AutoItX3.send_keys(TEXT2)
49
+ copy_all
50
+ assert_equal(TEXT2, AutoItX3.cliptext)
51
+ delete_all
52
+ AutoItX3.send_keys(TEXT3)
53
+ copy_all
54
+ assert_equal(TEXT3.sub("{TAB}", "\t"), AutoItX3.cliptext)
55
+ delete_all
56
+ AutoItX3.send_keys(TEXT3, true)
57
+ copy_all
58
+ assert_equal(TEXT3, AutoItX3.cliptext)
59
+ end
60
+
61
+ end
@@ -0,0 +1,43 @@
1
+ #Encoding: Windows-1252
2
+ #This file is part of au3.
3
+ #Copyright (c) 2009 Marvin G�lker
4
+ begin
5
+ require_relative "../lib/au3"
6
+ rescue LoadError
7
+ #Aha, this is the gem, not the build environment
8
+ require "au3"
9
+ end
10
+ require "test/unit"
11
+
12
+ class MouseTest < Test::Unit::TestCase
13
+
14
+ THREADS = []
15
+
16
+ def self.shutdown
17
+ THREADS.each{|t| t.join}
18
+ end
19
+
20
+ def test_cursor_id
21
+ pid = AutoItX3.run("notepad", "", AutoItX3::Window::SW_MAXIMIZE)
22
+ AutoItX3.move_mouse(150, 150)
23
+ THREADS << Thread.new{sleep 1;AutoItX3.kill_process(pid)}
24
+ assert_equal(AutoItX3::IBEAM_CURSOR, AutoItX3.cursor_id)
25
+ end
26
+
27
+ def test_move_curpos
28
+ AutoItX3.move_mouse(23, 74)
29
+ assert_equal([23, 74], AutoItX3.cursor_pos)
30
+ end
31
+
32
+ def test_click
33
+ pid = AutoItX3.run("notepad", "", AutoItX3::Window::SW_MAXIMIZE)
34
+ AutoItX3.mouse_click(1000000, 5) #End of screen
35
+ THREADS << Thread.new{sleep 1;AutoItX3.kill_process(pid)}
36
+ end
37
+
38
+ def test_tooltip
39
+ assert_nil(AutoItX3.tooltip("Google is watching you!"))
40
+ sleep 1
41
+ end
42
+
43
+ end
@@ -0,0 +1,50 @@
1
+ #Encoding: Windows-1252
2
+ #This file is part of au3.
3
+ #Copyright (c) 2009 Marvin G�lker
4
+ begin
5
+ require_relative "../lib/au3"
6
+ rescue LoadError
7
+ #Aha, this is the gem, not the build environment
8
+ require "au3"
9
+ end
10
+ require "test/unit"
11
+
12
+ class ProcessTest < Test::Unit::TestCase
13
+
14
+ DUMMY_PROG =<<EOF
15
+ #Encoding: Windows-1252
16
+ loop{sleep 1}
17
+ EOF
18
+
19
+ def self.startup
20
+ AutoItX3.opt("WinTitleMatchMode", 2)
21
+ end
22
+
23
+ def test_exists
24
+ assert_equal($$, AutoItX3.process_exists?($$))
25
+ end
26
+
27
+ def test_kill
28
+ File.open("dummy.rb", "w"){|f| f.write(DUMMY_PROG)}
29
+ pid = AutoItX3.run("ruby dummy.rb")
30
+ sleep 1
31
+ assert_equal(pid, AutoItX3.process_exists?(pid))
32
+ AutoItX3.kill_process(pid)
33
+ sleep 1
34
+ assert_equal(false, AutoItX3.process_exists?(pid))
35
+ File.delete("dummy.rb")
36
+ end
37
+
38
+ def test_wait
39
+ pid = AutoItX3.run("mspaint")
40
+ assert(AutoItX3.wait_for_process("mspaint.exe", 5))
41
+ sleep 1
42
+ AutoItX3.kill_process(pid)
43
+ assert(AutoItX3.wait_for_process_close("mspaint.exe", 2))
44
+ end
45
+
46
+ def test_run_and_wait
47
+ assert_raises(AutoItX3::Au3Error){AutoItX3.run_and_wait("dir gibtsnich")}
48
+ end
49
+
50
+ end
data/test/test_tray.rb ADDED
@@ -0,0 +1,29 @@
1
+ #Encoding: Windows-1252
2
+ #This file is part of au3.
3
+ #Copyright (c) 2009 Marvin G�lker
4
+ begin
5
+ require_relative "../lib/au3"
6
+ rescue LoadError
7
+ #Aha, this is the gem, not the build environment
8
+ require "au3"
9
+ end
10
+ require "test/unit"
11
+
12
+ class CDTrayTest < Test::Unit::TestCase
13
+
14
+ TEST_TRAY = "E:"
15
+
16
+ def test_open
17
+ assert(AutoItX3.open_cd_tray(TEST_TRAY))
18
+ end
19
+
20
+ def test_close
21
+ AutoItX3.open_cd_tray(TEST_TRAY)
22
+ if !AutoItX3.close_cd_tray(TEST_TRAY)
23
+ notify "Could not close your CD tray. Are you running on a laptop?"
24
+ else
25
+ assert(true)
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,104 @@
1
+ #Encoding: Windows-1252
2
+ #This file is part of au3.
3
+ #Copyright (c) 2009 Marvin G�lker
4
+ begin
5
+ require_relative "../lib/au3"
6
+ rescue LoadError
7
+ #Aha, this is the gem, not the build environment
8
+ require "au3"
9
+ end
10
+ require "test/unit"
11
+
12
+ class WindowTest < Test::Unit::TestCase
13
+
14
+ THREADS = []
15
+
16
+ def self.startup
17
+ AutoItX3.opt("WinTitleMatchMode", 2)
18
+ end
19
+
20
+ def self.shutdown
21
+ THREADS.each{|t| t.join}
22
+ end
23
+
24
+ def setup
25
+ @pid = AutoItX3.run("mspaint")
26
+ AutoItX3::Window.wait("Paint")
27
+ @win = AutoItX3::Window.new("Paint")
28
+ end
29
+
30
+ def teardown
31
+ @win.kill
32
+ end
33
+
34
+ def test_exists
35
+ assert_true(AutoItX3::Window.exists?(@win.title))
36
+ end
37
+
38
+ def test_activate
39
+ pid = AutoItX3.run("calc")
40
+ THREADS << Thread.new{sleep 3; AutoItX3.kill_process(pid)}
41
+ sleep 1
42
+ assert_equal(false, @win.active?)
43
+ @win.activate
44
+ sleep 1
45
+ assert_true(@win.active?)
46
+ end
47
+
48
+ def test_states
49
+ @win.state = AutoItX3::Window::SW_MINIMIZE
50
+ sleep 1
51
+ assert_true(@win.minimized?)
52
+ @win.state = AutoItX3::Window::SW_RESTORE
53
+ sleep 1
54
+ assert_equal(false, @win.minimized?)
55
+ @win.state = AutoItX3::Window::SW_MAXIMIZE
56
+ sleep 1
57
+ assert_true(@win.maximized?)
58
+ end
59
+
60
+ def test_move_and_resize
61
+ @win.move(37, 45, 200, 200)
62
+ sleep 1
63
+ assert_equal([37, 45], @win.rect[0..1])
64
+ @win.move(0, 0, 420, 450)
65
+ sleep 1
66
+ assert_equal([0, 0, 420, 450], @win.rect)
67
+ end
68
+
69
+ def test_pid
70
+ assert_equal(@pid, @win.pid)
71
+ end
72
+
73
+ def test_statusbar_text
74
+ assert_compare(0, "<", @win.statusbar_text.size)
75
+ end
76
+
77
+ def test_text
78
+ assert_compare(0, "<", @win.text.size)
79
+ end
80
+
81
+ def test_title
82
+ assert_match(/Paint/, @win.title)
83
+ end
84
+
85
+ def test_to_i
86
+ assert_equal(@win.handle.to_i(16), @win.to_i)
87
+ end
88
+
89
+ def test_transparency
90
+ assert_equal(100, @win.transparency = 100)
91
+ sleep 1
92
+ end
93
+
94
+ def test_visible
95
+ assert_true(@win.visible?)
96
+ end
97
+
98
+ def test_close
99
+ @win.close
100
+ assert_true(@win.wait_not_active)
101
+ assert_true(@win.wait_close)
102
+ end
103
+
104
+ end