xdo 0.0.1-x86-linux → 0.0.2-x86-linux

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -13,27 +13,28 @@ spec = Gem::Specification.new do |s|
13
13
  XDo is a library to automate your mouse, fake keyboard input and
14
14
  manipulate windows in a Linux X server environment. It's wrapped
15
15
  around a lot of command line tools (see requirements) of which xdotool
16
- is the main one, the others are usually installed.
16
+ is the main one, the others are usually installed. It's designed to work
17
+ only with Ruby 1.9.
17
18
  DESCRIPTION
18
- s.add_dependency("test-unit", ">= 2.0")
19
- s.requirements = ["The xdotool command-line tool.", "xwininfo (usually installed)", "The xsel command-line tool.", "eject (usually installed)", "xkill (usually installed)"]
20
- s.requirements << "The unit-test gem (will be installed if you don't have it)"
21
- s.version = "0.0.1"
19
+ s.add_development_dependency("test-unit", ">= 2.0")
20
+ s.requirements = ["The xdotool command-line tool.", "The xsel command-line tool.", "xwininfo (usually installed)", "eject (usually installed)", "xkill (usually installed)"]
21
+ s.version = "0.0.2"
22
22
  s.author = "Marvin Gülker"
23
23
  s.email = "sutniuq@gmx.net"
24
- s.platform = Gem::Platform::CURRENT
24
+ s.platform = Gem::Platform::CURRENT #Because it's a Linux-only gem
25
25
  s.required_ruby_version = ">=1.9"
26
- s.files = ["bin/xinfo.rb", Dir["lib/**/*.rb"], Dir["test/*.rb"], Dir["samples/*.rb"], "Rakefile", "lib/README.rdoc"].flatten
26
+ s.files = ["bin/xinfo.rb", Dir["lib/**/*.rb"], Dir["test/*.rb"], Dir["samples/*.rb"], "Rakefile", "lib/README.rdoc", "lib/HISTORY.rdoc"].flatten
27
27
  s.executables = ["xinfo.rb"]
28
28
  s.has_rdoc = true
29
+ s.rdoc_options << "--title" << "XDo RDocs" << "--main" << "lib/README.rdoc"
29
30
  s.test_files = Dir["test/test_*.rb"]
30
31
  s.rubyforge_project = "Automations"
31
32
  end
32
33
  Rake::GemPackageTask.new(spec).define
33
34
 
34
35
  Rake::RDocTask.new do |rd|
35
- rd.rdoc_files.include("lib/**/*.rb", "lib/README.rdoc")
36
- rd.title = "xdo RDocs"
36
+ rd.rdoc_files.include("lib/**/*.rb", "lib/README.rdoc", "lib/HISTORY.rdoc")
37
+ rd.title = "XDo RDocs"
37
38
  rd.main = "lib/README.rdoc"
38
39
  end
39
40
 
data/lib/HISTORY.rdoc ADDED
@@ -0,0 +1,11 @@
1
+ =History of the xdo gem
2
+ This file shows the history of the xdo gem
3
+ from it's very beginning. Important changes in the
4
+ API are marked <b>bold</b>.
5
+ ==0.0.2
6
+ * Replaced fork{system("gedit")} in full_demo.rb with spawn("gedit")
7
+ * Removed "require 'pp'" from keyboard.rb
8
+ * <b>Added the Simulatable mixin</b>
9
+ * <b>Corrected window id usage for the XDo::Keyboard module</b>
10
+ * Added a test for the window id usage
11
+ * Made the test-unit gem a development dependency
data/lib/README.rdoc CHANGED
@@ -4,17 +4,13 @@ Copyright © 2009 Marvin Gülker
4
4
  Initia in potestate nostra sunt, de eventu fortuna iudicat.
5
5
  ++
6
6
  =XDo
7
- XDo is a library to simmulate keyboard and mouse input and manipulating windows on the X server.
7
+ XDo is a library to simulate keyboard and mouse input and manipulating windows on the X server.
8
8
  It's wrapped around the command-line tools xdotool[http://www.semicomplete.com/projects/xdotool/],
9
- xsel[http://linux.die.net/man/1/xsel], xwininfo[http://linux.die.net/man/1/xwininfo], ecject[http://linux.die.net/man/1/eject] and xkill[http://linux.die.net/man/1/xkill],
10
- so you will need to have them installed if you want to use Xdo (even if xsel, xwininfo, eject and xkill are usually already installed).
11
- If not, as an Ubuntu or Debian user try to install them via
12
- sudo apt-get install xdotool xsel xwininfo eject xkill
9
+ xsel[http://linux.die.net/man/1/xsel], xwininfo[http://linux.die.net/man/1/xwininfo], eject[http://linux.die.net/man/1/eject] and xkill[http://linux.die.net/man/1/xkill],
10
+ so you will need to have them installed if you want to use Xdo (even if xwininfo, eject and xkill are usually already installed).
11
+ If not, try to install them via your favourite packaging manager.
13
12
  After they're installed, install XDo via RubyGems:
14
13
  sudo gem install xdo
15
- If you want to run the tests, change to the gem's installation directory and type "rake test".
16
- Keep in mind that, while the tests run, you won't be able to use your computer, since they take control
17
- of all things XDo is able to.
18
14
  ==Usage
19
15
  #Require some of XDo's files
20
16
  require "xdo/keyboard"
@@ -24,6 +20,8 @@ of all things XDo is able to.
24
20
  XDo::Mouse.move(100, 100)
25
21
  #Simulate text (with special escape sequences!)
26
22
  XDo::Keyboard.simulate("This is{TAB}text.")
23
+ #Some sequences can be shortened:
24
+ XDo::Keyboard.simulate("This ist\ttext.")
27
25
  #And this will move a window containing the string "gedit",
28
26
  #unless it's maximized.
29
27
  win = XDo::XWindow.from_name("gedit")
@@ -42,10 +40,10 @@ It's by far not perfect, maybe not even good, but I think it can be useful somet
42
40
  (you will need to have wxRuby installed, try <tt>sudo gem install wxruby-ruby19</tt>).
43
41
  If you're looking for a more professional program, try the "X window information" tool.
44
42
  ==Notes
45
- * +xdotool+ rejects to accept the --window option although it's documented, so you can't use the +w_id+ parameter of many methods in XDo::Keyboard.
43
+ * If your +xdotool+ seems to reject the --window option, you are not using the current version. Try building the newest one from the source.
46
44
  * I recommand the "X window information" tool to get infos about your windows if you aren't satisfied by the xinfo.rb shipped with this package.
47
45
  ==Fairly incomplete
48
- * I'm sure there are several things I didn't notice that can be automated somehow. If you know about, email me! Please add a description of the possibilities and a sample script (but don't expect that I will understand it - I only speak Ruby fluently, a bit C and a bit sh ;-) )
46
+ * I'm sure there are several things I didn't notice that can be automated somehow. If you know about, email me! Please add a description of the possibilities and a sample script.
49
47
  * Another interesting thing are the samples. There are many Linux distrubitions out there, and even many of them rely on X. I cannot test with another than a recent Ubuntu machine, but if you want to contribute and send samples for another OS, I want to encourage you to - I surely won't reject your work. :-)
50
48
  ==License/Copyright
51
49
  Copyright © 2009 Marvin Gülker
data/lib/xdo.rb CHANGED
@@ -21,6 +21,9 @@ module XDo
21
21
  #The command to start eject.
22
22
  EJECT = "eject"
23
23
 
24
+ #The version of this library.
25
+ VERSION = "0.0.2"
26
+
24
27
  #Class for errors in this library.
25
28
  class XError < StandardError
26
29
  end
data/lib/xdo/keyboard.rb CHANGED
@@ -3,7 +3,6 @@
3
3
  #Copyright © 2009 Marvin Gülker
4
4
  # Initia in potestate nostra sunt, de eventu fortuna iudicat.
5
5
  require_relative("../xdo")
6
- require "pp"
7
6
 
8
7
  module XDo
9
8
 
@@ -150,7 +149,7 @@ module XDo
150
149
  #Types a character sequence, but without any special chars.
151
150
  #This function is a bit faster then #simulate.
152
151
  def type(str, w_id = nil)
153
- out = `#{XDOTOOL} type #{w_id ? "--window #{w_id}" : ""}"#{str}"`
152
+ out = `#{XDOTOOL} type #{w_id ? "--window #{w_id} " : ""}"#{str}"`
154
153
  nil
155
154
  end
156
155
 
@@ -164,7 +163,7 @@ module XDo
164
163
  if raw
165
164
  commands = []
166
165
  str.each_char do |char|
167
- commands << "#{XDOTOOL} key #{w_id ? "--window #{w_id}" : ""}#{check_for_special_key(char)}"
166
+ commands << "#{XDOTOOL} key #{w_id ? "--window #{w_id} " : ""}#{check_for_special_key(char)}"
168
167
  end
169
168
 
170
169
  commands.each do |cmd|
@@ -197,7 +196,7 @@ module XDo
197
196
  else
198
197
  #Ab hier ist der Token sicherlich normaler Text; entsprechend wird damit verfahren.
199
198
  token.each_char do |char|
200
- commands << "#{XDOTOOL} key #{w_id ? "--window #{w_id}" : ""}#{check_for_special_key(char)}"
199
+ commands << "#{XDOTOOL} key #{w_id ? "--window #{w_id} " : ""}#{check_for_special_key(char)}"
201
200
  end
202
201
  commands.flatten! #Zur Sicherheit
203
202
  end
@@ -212,18 +211,18 @@ module XDo
212
211
  #Simulate a single char directly via the +key+ function of +xdotool+.
213
212
  #+c+ is a single char like "a" or a combination like "shift+a".
214
213
  def char(c, w_id = nil)
215
- `#{XDOTOOL} key #{w_id ? "--window #{w_id}" : ""}#{c}`
214
+ `#{XDOTOOL} key #{w_id ? "--window #{w_id} " : ""}#{c}`
216
215
  end
217
216
  alias key char
218
217
 
219
218
  #Holds a key down. Please call #key_up after a call to this method.
220
219
  def key_down(key, w_id = nil)
221
- `#{XDOTOOL} keydown #{w_id ? "--window #{w_id}" : "" }#{check_for_special_key(key)}`
220
+ `#{XDOTOOL} keydown #{w_id ? "--window #{w_id} " : "" }#{check_for_special_key(key)}`
222
221
  end
223
222
 
224
223
  #Releases a key hold down by #key_down.
225
224
  def key_up(key, w_id = nil)
226
- `#{XDOTOOL} keyup #{w_id ? "--window #{w_id}" : "" }#{check_for_special_key(key)}`
225
+ `#{XDOTOOL} keyup #{w_id ? "--window #{w_id} " : "" }#{check_for_special_key(key)}`
227
226
  end
228
227
 
229
228
  #Deletes a char. If +right+ is true, +del_char+ uses
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env ruby
2
+ #Encoding: UTF-8
3
+ #This file is part of Xdo.
4
+ #Copyright © 2009 Marvin Gülker
5
+ # Initia in potestate nostra sunt, de eventu fortuna iudicat.
6
+ require_relative("../xdo")
7
+ require_relative("./keyboard")
8
+
9
+ module XDo
10
+
11
+ #Mixin that allows String-like objects to be directly
12
+ #simulated. You can use it with Ruby's String class:
13
+ # require "xdo/simulatable"
14
+ #
15
+ # class String
16
+ # include XDo::Simulatable
17
+ # def to_xdo
18
+ # to_s
19
+ # end
20
+ # end
21
+ #
22
+ # "abc".simulate
23
+ #Every method in this module calls ##to_xdo on +self+
24
+ #first, so make sure this method returns a xdo-usable
25
+ #String (i.e. no invisible characters except newline, tab and space).
26
+ module Simulatable
27
+
28
+ #Simulates +self+ as keystrokes. Escape sequences are allowed.
29
+ def simulate(raw = false, w_id = nil)
30
+ XDo::Keyboard.simulate(to_xdo, raw, w_id)
31
+ end
32
+
33
+ #Types +self+ as keystrokes. Ignores escape sequences.
34
+ def type(w_id = nil)
35
+ XDo::Keyboard.type(to_xdo, w_id)
36
+ end
37
+
38
+ #Holds the first key of +self+ down.
39
+ def down(w_id = nil)
40
+ XDo::Keyboard.key_down(to_xdo[0], w_id)
41
+ end
42
+
43
+ #Releases the first key of +self+ if it's hold
44
+ #down by #down.
45
+ def up(w_id = nil)
46
+ XDo::Keyboard.key_up(to_xdo[0], w_id)
47
+ end
48
+
49
+ end
50
+
51
+ end
data/samples/full_demo.rb CHANGED
@@ -36,7 +36,7 @@ class XXX
36
36
  #If we would use system in the main program to open
37
37
  #gedit, it would hang until gedit is closed. That's why
38
38
  #we run it in a separate process.
39
- fork{system("gedit")}
39
+ spawn("gedit")
40
40
  #Now we wait until gedit has made up its GUI.
41
41
  #wait_for_window returns the ID of the found window, so
42
42
  #we catch it and...
@@ -104,7 +104,7 @@ class XXX
104
104
  #command and it sometimes works, but you mustn't rely on it. Therefore I use
105
105
  #the HOME environment variable here to get the home directory, rather than ~.
106
106
  XDo::Keyboard.simulate("#{ENV["HOME"]}/testXDo.txt")
107
- sleep 1 #gedit terminates if send [ALT]+[A] immediatly after the path
107
+ sleep 1 #gedit terminates if send [ALT]+[S] immediatly after the path
108
108
  XDo::Keyboard.alt_s
109
109
  #Now, let's duplicate our table. We could send all the stuff again,
110
110
  #but I want to introduce you in the use of the X clipboard.
@@ -132,7 +132,7 @@ class XXX
132
132
  sleep 5
133
133
  #Than close gedit. There are three methods to close a window,
134
134
  ##close, #close! and #kill!. #close is like sending an [ALT]+[F4] keypress which may result in
135
- #a dialog box asking you for confimation. #close! is a bit stronger. First it calls #close and waits
135
+ #a dialog box asking you for confirmation. #close! is a bit stronger. First it calls #close and waits
136
136
  #a few seconds (you can specify how long exactly) then shuts down the window process. What
137
137
  #leads us to the third method: #kill!. Be sure to call #kill! only on windows you know -
138
138
  #it kills the process of a window by sending SIGTERM first and then SIGKILL. I've not tried
@@ -1,60 +1,110 @@
1
1
  #!/usr/bin/env ruby
2
2
  #Encoding: UTF-8
3
3
  require "test/unit"
4
+ require "tempfile"
4
5
  require "xdo/keyboard.rb"
5
6
  require "xdo/clipboard.rb"
6
7
  require "xdo/xwindow"
8
+ require "xdo/simulatable"
7
9
 
8
10
  class TestKeyboard < Test::Unit::TestCase
9
11
 
10
12
  #Command to start a simple text editor
11
13
  EDITOR_CMD = "gedit"
12
- TESTFILENAME = "#{ENV["HOME"]}/abcdefghijklmnopqrstuvwxyzäöüß.txt"
14
+
13
15
  TESTTEXT = "This is test\ntext."
14
- APPEND = "XYZ"
16
+ TESTTEXT2 = "XYZ"
15
17
  TESTTEXT_RAW = "ä{TAB}?b"
16
18
  TESTTEXT_SPECIAL = "ab{TAB}c{TAB}{TAB}d"
17
19
 
18
- def self.startup
19
- File.open(TESTFILENAME, "w"){|file| file.write(TESTTEXT)}
20
- fork{system(%Q|#{EDITOR_CMD} "#{TESTFILENAME}"|)}
21
- sleep 5
20
+ def setup
21
+ @edit_pid = spawn(EDITOR_CMD)
22
+ sleep 0.5
23
+ end
24
+
25
+ def teardown
26
+ Process.kill("KILL", @edit_pid)
22
27
  end
23
28
 
24
- def test_all
25
- XDo::Keyboard.simulate("{PGUP}")
29
+ def test_char
30
+ Process.kill("KILL", @edit_pid) #Special file need to be opened
31
+ tempfile = Tempfile.open("XDOTEST")
32
+ tempfile.write(TESTTEXT)
33
+ tempfile.flush
34
+ sleep 1 #Wait for the buffer to be written out
35
+ @edit_pid = spawn(EDITOR_CMD, tempfile.path) #So it's automatically killed by #teardown
36
+ sleep 1
37
+ tempfile.close
26
38
  20.times{XDo::Keyboard.char("Shift+Right")}
27
39
  XDo::Keyboard.ctrl_c
28
40
  sleep 0.2
29
41
  assert_equal(TESTTEXT, XDo::Clipboard.read_clipboard)
30
- XDo::Keyboard.simulate("{RIGHT}#{APPEND}")
42
+ end
43
+
44
+ def test_simulate
45
+ XDo::Keyboard.simulate("A{BS}#{TESTTEXT2}")
31
46
  XDo::Keyboard.ctrl_a
32
47
  XDo::Keyboard.ctrl_c
33
48
  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)
49
+ assert_equal(TESTTEXT2, XDo::Clipboard.read_clipboard)
50
+
51
+ XDo::Keyboard.ctrl_a
52
+ XDo::Keyboard.delete
53
+ XDo::Keyboard.simulate(TESTTEXT_SPECIAL)
54
+ XDo::Keyboard.ctrl_a
55
+ XDo::Keyboard.ctrl_c
37
56
  sleep 0.2
57
+ assert_equal(TESTTEXT_SPECIAL.gsub("{TAB}", "\t"), XDo::Clipboard.read_clipboard)
58
+
59
+ XDo::Keyboard.ctrl_a
60
+ XDo::Keyboard.delete
61
+ XDo::Keyboard.simulate(TESTTEXT_RAW, true)
38
62
  XDo::Keyboard.ctrl_a
39
63
  XDo::Keyboard.ctrl_c
40
64
  sleep 0.2
41
65
  assert_equal(TESTTEXT_RAW, XDo::Clipboard.read_clipboard)
42
- (TESTTEXT_RAW.length + 2).times{XDo::Keyboard.delete}
43
- XDo::Keyboard.simulate(TESTTEXT_SPECIAL)
66
+ end
67
+
68
+ def test_type
69
+ XDo::Keyboard.type(TESTTEXT2)
70
+ XDo::Keyboard.ctrl_a
71
+ XDo::Keyboard.ctrl_c
44
72
  sleep 0.2
73
+ assert_equal(TESTTEXT2, XDo::Clipboard.read_clipboard)
74
+ end
75
+
76
+ def test_window_id
77
+ XDo::XWindow.focus_desktop #Ensure that the editor hasn't the input focus anymore
78
+ sleep 1
79
+ edit_id = XDo::XWindow.search(EDITOR_CMD).first
80
+ xwin = XDo::XWindow.new(edit_id)
81
+ XDo::Keyboard.simulate(TESTTEXT_SPECIAL, false, edit_id)
82
+ sleep 1
83
+ xwin.activate
45
84
  XDo::Keyboard.ctrl_a
46
85
  XDo::Keyboard.ctrl_c
47
86
  sleep 0.2
48
87
  assert_equal(TESTTEXT_SPECIAL.gsub("{TAB}", "\t"), XDo::Clipboard.read_clipboard)
49
88
  end
50
89
 
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)
90
+ def test_include
91
+ String.class_eval do
92
+ include XDo::Simulatable
93
+
94
+ def to_xdo
95
+ to_s
96
+ end
97
+ end
98
+
99
+ XDo::Keyboard.ctrl_a
100
+ XDo::Keyboard.delete
101
+ "Ein String".simulate
102
+ XDo::Keyboard.ctrl_a
103
+ sleep 0.2
104
+ XDo::Keyboard.ctrl_c
105
+ sleep 0.2
106
+ clip = XDo::Clipboard.read_clipboard
107
+ assert_equal("Ein String", clip)
58
108
  end
59
109
 
60
110
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xdo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: x86-linux
6
6
  authors:
7
7
  - "Marvin G\xC3\xBClker"
@@ -9,12 +9,12 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-23 00:00:00 +02:00
12
+ date: 2009-12-04 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: test-unit
17
- type: :runtime
17
+ type: :development
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement
20
20
  requirements:
@@ -26,7 +26,8 @@ description: |
26
26
  XDo is a library to automate your mouse, fake keyboard input and
27
27
  manipulate windows in a Linux X server environment. It's wrapped
28
28
  around a lot of command line tools (see requirements) of which xdotool
29
- is the main one, the others are usually installed.
29
+ is the main one, the others are usually installed. It's designed to work
30
+ only with Ruby 1.9.
30
31
 
31
32
  email: sutniuq@gmx.net
32
33
  executables:
@@ -39,6 +40,7 @@ files:
39
40
  - bin/xinfo.rb
40
41
  - lib/xdo.rb
41
42
  - lib/xdo/xwindow.rb
43
+ - lib/xdo/simulatable.rb
42
44
  - lib/xdo/mouse.rb
43
45
  - lib/xdo/drive.rb
44
46
  - lib/xdo/keyboard.rb
@@ -53,13 +55,17 @@ files:
53
55
  - samples/full_demo.rb
54
56
  - Rakefile
55
57
  - lib/README.rdoc
58
+ - lib/HISTORY.rdoc
56
59
  has_rdoc: true
57
60
  homepage:
58
61
  licenses: []
59
62
 
60
63
  post_install_message:
61
- rdoc_options: []
62
-
64
+ rdoc_options:
65
+ - --title
66
+ - XDo RDocs
67
+ - --main
68
+ - lib/README.rdoc
63
69
  require_paths:
64
70
  - lib
65
71
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -76,11 +82,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
82
  version:
77
83
  requirements:
78
84
  - The xdotool command-line tool.
79
- - xwininfo (usually installed)
80
85
  - The xsel command-line tool.
86
+ - xwininfo (usually installed)
81
87
  - eject (usually installed)
82
88
  - xkill (usually installed)
83
- - The unit-test gem (will be installed if you don't have it)
84
89
  rubyforge_project: Automations
85
90
  rubygems_version: 1.3.5
86
91
  signing_key: