xdo 0.0.1-x86-linux

Sign up to get free protection for your applications and to get access to all the features.
data/samples/mouse.rb ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ #Encoding: UTF-8
3
+ #--
4
+ #This file is part of XDo. Copyright © 2009 Marvin Gülker
5
+ #XDo is published under Ruby's license. See http://www.ruby-lang.org/en/LICENSE.txt.
6
+ # Initia in potestate nostra sunt, de eventu fortuna iudicat.
7
+ #++
8
+
9
+ =begin
10
+ This is an example on how to use the mouse with XDo::Mouse.
11
+ =end
12
+
13
+ #Require the library
14
+ require "xdo/mouse"
15
+
16
+ #Get current cursor position
17
+ puts "Cursor X pos: #{XDo::Mouse.position[0]}"
18
+ puts "Cursor Y pos: #{XDo::Mouse.position[1]}"
19
+
20
+ #Move the mouse cursor
21
+ XDo::Mouse.move(10, 10)
22
+ #Click at the current position
23
+ XDo::Mouse.click
24
+ #Do a right-click at (100|100)
25
+ XDo::Mouse.click(100, 100, XDo::Mouse::RIGHT)
26
+ #Scroll down a text page
27
+ XDo::Mouse.wheel(XDo::Mouse::DOWN, 4)
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env ruby
2
+ #Encoding: UTF-8
3
+ require "test/unit"
4
+ require "xdo/clipboard.rb"
5
+
6
+ class ClipboardTest < Test::Unit::TestCase
7
+
8
+ def test_read
9
+ #Write something to the clipboard first
10
+ IO.popen("#{XDo::XSEL} -i", "w"){|io| io.write("Some primary test text")}
11
+ IO.popen("#{XDo::XSEL} -b -i", "w"){|io| io.write("Some clipboard \ntest text")}
12
+ IO.popen("#{XDo::XSEL} -s -i", "w"){|io| io.write("Some secondary test text")}
13
+
14
+ clip = XDo::Clipboard.read(primary: true, secondary: true, clipboard: true)
15
+ assert_equal("Some primary test text", XDo::Clipboard.read_primary)
16
+ assert_equal(XDo::Clipboard.read_primary, clip[:primary])
17
+ assert_equal("Some clipboard \ntest text", XDo::Clipboard.read_clipboard)
18
+ assert_equal(XDo::Clipboard.read_clipboard, clip[:clipboard])
19
+ assert_equal("Some secondary test text", XDo::Clipboard.read_secondary)
20
+ assert_equal(XDo::Clipboard.read_secondary, clip[:secondary])
21
+ end
22
+
23
+ def test_write
24
+ XDo::Clipboard.write_primary "Primary!"
25
+ XDo::Clipboard.write_clipboard "Clipboard!\nNewline"
26
+ XDo::Clipboard.write_secondary "Secondary!"
27
+
28
+ assert_equal("Primary!", `#{XDo::XSEL}`)
29
+ assert_equal("Secondary!", `#{XDo::XSEL} -s`)
30
+ assert_equal("Clipboard!\nNewline", `#{XDo::XSEL} -b`)
31
+
32
+ XDo::Clipboard.write("XYZ", primary: true, secondary: true, clipboard: true)
33
+ assert_equal({primary: "XYZ", secondary: "XYZ", clipboard: "XYZ"}, XDo::Clipboard.read(primary: true, secondary: true, clipboard: true))
34
+ end
35
+
36
+ def test_append
37
+ ["primary", "secondary", "clipboard"].each{|m| XDo::Clipboard.send(:"write_#{m}", "This is... ")}
38
+ XDo::Clipboard.append("a Test!", primary: true, secondary: true, clipboard: true)
39
+ ["primary", "secondary", "clipboard"].each{|m| assert_equal(XDo::Clipboard.send(:"read_#{m}"), "This is... a Test!")}
40
+ end
41
+
42
+ def test_clear
43
+ XDo::Clipboard.write("ABC", primary: true, secondary: true, clipboard: true)
44
+ ["primary", "secondary", "clipboard"].each{|m| XDo::Clipboard.send("clear_#{m}")}
45
+ ["primary", "secondary", "clipboard"].each{|m| assert_equal("", XDo::Clipboard.send("read_#{m}"))}
46
+ end
47
+
48
+
49
+ end
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+ #Encoding: UTF-8
3
+ require "test/unit"
4
+ require "xdo/drive.rb"
5
+
6
+ class DriveTest < Test::Unit::TestCase
7
+
8
+ def test_eject
9
+ begin
10
+ XDo::Drive.eject
11
+ sleep 2
12
+ begin
13
+ XDo::Drive.close
14
+ rescue XDo::XError #A laptop drive will raise an XDo::XError since it has to be closed manually
15
+ notify "Couldn't close your CD-ROM drive. Are you using a laptop?"
16
+ end
17
+ assert(true)
18
+ rescue
19
+ assert(false, $!.message)
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env ruby
2
+ #Encoding: UTF-8
3
+ require "test/unit"
4
+ require "xdo/keyboard.rb"
5
+ require "xdo/clipboard.rb"
6
+ require "xdo/xwindow"
7
+
8
+ class TestKeyboard < Test::Unit::TestCase
9
+
10
+ #Command to start a simple text editor
11
+ EDITOR_CMD = "gedit"
12
+ TESTFILENAME = "#{ENV["HOME"]}/abcdefghijklmnopqrstuvwxyzäöüß.txt"
13
+ TESTTEXT = "This is test\ntext."
14
+ APPEND = "XYZ"
15
+ TESTTEXT_RAW = "ä{TAB}?b"
16
+ TESTTEXT_SPECIAL = "ab{TAB}c{TAB}{TAB}d"
17
+
18
+ def self.startup
19
+ File.open(TESTFILENAME, "w"){|file| file.write(TESTTEXT)}
20
+ fork{system(%Q|#{EDITOR_CMD} "#{TESTFILENAME}"|)}
21
+ sleep 5
22
+ end
23
+
24
+ def test_all
25
+ XDo::Keyboard.simulate("{PGUP}")
26
+ 20.times{XDo::Keyboard.char("Shift+Right")}
27
+ XDo::Keyboard.ctrl_c
28
+ sleep 0.2
29
+ assert_equal(TESTTEXT, XDo::Clipboard.read_clipboard)
30
+ XDo::Keyboard.simulate("{RIGHT}#{APPEND}")
31
+ XDo::Keyboard.ctrl_a
32
+ XDo::Keyboard.ctrl_c
33
+ sleep 0.2
34
+ assert_equal(TESTTEXT + APPEND, XDo::Clipboard.read_clipboard)
35
+ (TESTTEXT.length + APPEND.length + 2).times{XDo::Keyboard.simulate("\b")}
36
+ XDo::Keyboard.simulate(TESTTEXT_RAW, true)
37
+ sleep 0.2
38
+ XDo::Keyboard.ctrl_a
39
+ XDo::Keyboard.ctrl_c
40
+ sleep 0.2
41
+ assert_equal(TESTTEXT_RAW, XDo::Clipboard.read_clipboard)
42
+ (TESTTEXT_RAW.length + 2).times{XDo::Keyboard.delete}
43
+ XDo::Keyboard.simulate(TESTTEXT_SPECIAL)
44
+ sleep 0.2
45
+ XDo::Keyboard.ctrl_a
46
+ XDo::Keyboard.ctrl_c
47
+ sleep 0.2
48
+ assert_equal(TESTTEXT_SPECIAL.gsub("{TAB}", "\t"), XDo::Clipboard.read_clipboard)
49
+ end
50
+
51
+ def self.shutdown
52
+ xwin = XDo::XWindow.from_name(EDITOR_CMD)
53
+ xwin.activate
54
+ XDo::Keyboard.ctrl_s
55
+ sleep 0.5
56
+ xwin.close
57
+ File.delete(TESTFILENAME)
58
+ end
59
+
60
+ end
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+ #Encoding: UTF-8
3
+ require "test/unit"
4
+ require "xdo/mouse.rb"
5
+
6
+ class MouseTest < Test::Unit::TestCase
7
+
8
+ def test_position
9
+ str = `#{XDo::XDOTOOL} getmouselocation`
10
+ xdpos = []
11
+ xdpos << str.match(/x:\s?(\d+)/)[1]
12
+ xdpos << str.match(/y:\s?(\d+)/)[1]
13
+ xdpos.collect!{|o| o.to_i}
14
+ assert_equal(xdpos, XDo::Mouse.position)
15
+ end
16
+
17
+ def test_move
18
+ XDo::Mouse.move(200, 200)
19
+ assert_equal([200, 200], XDo::Mouse.position)
20
+ XDo::Mouse.move(0, 0)
21
+ assert_equal([0, 0], XDo::Mouse.position)
22
+ XDo::Mouse.move(0, 200)
23
+ assert_equal([0, 200], XDo::Mouse.position)
24
+ XDo::Mouse.move(100, 100)
25
+ assert_equal([100, 100], XDo::Mouse.position)
26
+ end
27
+
28
+ end
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env ruby
2
+ #Encoding: UTF-8
3
+ require "test/unit"
4
+ require "xdo/xwindow.rb"
5
+
6
+ class WindowTest < Test::Unit::TestCase
7
+
8
+ attr_accessor :xwindow
9
+
10
+ #The program MUST NOT start maximized. xdotool has no possibility of
11
+ #acting on maximized windows.
12
+ NEW_WINDOW_CMD = "gedit"
13
+
14
+ @@xwin = nil
15
+
16
+ def self.startup
17
+ fork{system(NEW_WINDOW_CMD)}
18
+ XDo::XWindow.wait_for_window(NEW_WINDOW_CMD)
19
+ @@xwin = XDo::XWindow.from_name(NEW_WINDOW_CMD)
20
+ end
21
+
22
+ def self.shutdown
23
+ @@xwin.close!
24
+ end
25
+
26
+ def test_ewmh_active_window
27
+ begin
28
+ XDo::XWindow.from_active
29
+ rescue XDo::XError
30
+ #Standard not available
31
+ notify $!.message
32
+ end
33
+ end
34
+
35
+ def test_ewmh_wm_desktop
36
+ begin
37
+ XDo::XWindow.desktop_num
38
+ rescue XDo::XError
39
+ #Standard not available
40
+ notify $!.message
41
+ end
42
+ end
43
+
44
+ def test_ewmh_current_desktop
45
+ begin
46
+ XDo::XWindow.desktop
47
+ rescue XDo::XError
48
+ #Standard not available
49
+ notify $!.message
50
+ end
51
+ end
52
+
53
+ def test_exists
54
+ assert_equal(true, XDo::XWindow.exists?(@@xwin.title))
55
+ end
56
+
57
+ def test_activate_desktop
58
+ XDo::XWindow.activate_desktop
59
+ assert_equal(XDo::XWindow.from_name(XDo::XWindow.desktop_name).id, XDo::XWindow.from_active.id)
60
+ sleep 1
61
+ end
62
+
63
+ def test_active
64
+ @@xwin.unfocus
65
+ sleep 1
66
+ @@xwin.activate
67
+ assert_equal(@@xwin.id, XDo::XWindow.from_active.id)
68
+ sleep 1
69
+ end
70
+
71
+ def test_focused
72
+ @@xwin.unfocus
73
+ sleep 1
74
+ @@xwin.focus
75
+ assert_equal(@@xwin.id, XDo::XWindow.from_focused.id)
76
+ sleep 1
77
+ end
78
+
79
+ def test_move
80
+ @@xwin.move(57, 57)
81
+ assert_in_delta(50, 60, @@xwin.abs_position[0])
82
+ assert_in_delta(50, 50, @@xwin.abs_position[1])
83
+ assert_equal(@@xwin.abs_position, @@xwin.rel_position)
84
+ sleep 1
85
+ end
86
+
87
+ def test_resize
88
+ @@xwin.resize(500, 500)
89
+ assert_equal([500, 500], @@xwin.size)
90
+ sleep 1
91
+ end
92
+
93
+ def test_map
94
+ @@xwin.unmap
95
+ sleep 0.2
96
+ assert_equal(false, @@xwin.visible?)
97
+ @@xwin.map
98
+ sleep 0.2
99
+ assert_equal(true, @@xwin.visible?)
100
+ sleep 1
101
+ end
102
+
103
+ end
104
+
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xdo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: x86-linux
6
+ authors:
7
+ - "Marvin G\xC3\xBClker"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-23 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: test-unit
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "2.0"
24
+ version:
25
+ description: |
26
+ XDo is a library to automate your mouse, fake keyboard input and
27
+ manipulate windows in a Linux X server environment. It's wrapped
28
+ around a lot of command line tools (see requirements) of which xdotool
29
+ is the main one, the others are usually installed.
30
+
31
+ email: sutniuq@gmx.net
32
+ executables:
33
+ - xinfo.rb
34
+ extensions: []
35
+
36
+ extra_rdoc_files: []
37
+
38
+ files:
39
+ - bin/xinfo.rb
40
+ - lib/xdo.rb
41
+ - lib/xdo/xwindow.rb
42
+ - lib/xdo/mouse.rb
43
+ - lib/xdo/drive.rb
44
+ - lib/xdo/keyboard.rb
45
+ - lib/xdo/clipboard.rb
46
+ - lib/xdo/wxaliases.rb
47
+ - test/test_drive.rb
48
+ - test/test_clipboard.rb
49
+ - test/test_keyboard.rb
50
+ - test/test_xwindow.rb
51
+ - test/test_mouse.rb
52
+ - samples/mouse.rb
53
+ - samples/full_demo.rb
54
+ - Rakefile
55
+ - lib/README.rdoc
56
+ has_rdoc: true
57
+ homepage:
58
+ licenses: []
59
+
60
+ post_install_message:
61
+ rdoc_options: []
62
+
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "1.9"
70
+ version:
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ requirements:
78
+ - The xdotool command-line tool.
79
+ - xwininfo (usually installed)
80
+ - The xsel command-line tool.
81
+ - eject (usually installed)
82
+ - xkill (usually installed)
83
+ - The unit-test gem (will be installed if you don't have it)
84
+ rubyforge_project: Automations
85
+ rubygems_version: 1.3.5
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Simulate keyboard and mouse input via a ruby interface to xdotool and other console programs.
89
+ test_files:
90
+ - test/test_drive.rb
91
+ - test/test_clipboard.rb
92
+ - test/test_keyboard.rb
93
+ - test/test_xwindow.rb
94
+ - test/test_mouse.rb