xdojava 1.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/xdojava.class +0 -0
- data/lib/xdojava.java +273 -0
- data/lib/xdojava.rb +23 -0
- metadata +71 -0
data/lib/xdojava.class
ADDED
Binary file
|
data/lib/xdojava.java
ADDED
@@ -0,0 +1,273 @@
|
|
1
|
+
//******************************************************************************
|
2
|
+
// Provide cross-platform keystroke emulation for automation testing.
|
3
|
+
//
|
4
|
+
// Requires Oracle Java SE 7u7
|
5
|
+
// http://www.oracle.com/technetwork/java/javase/downloads/index.html
|
6
|
+
//
|
7
|
+
// Windows: Set default java as 1.7 in Control Panel | Java
|
8
|
+
// Mac OSx: Set default java as 1.7 in Java Preferences
|
9
|
+
// Linux: Set default java as 1.7 using $ update-alternatives --config java
|
10
|
+
//
|
11
|
+
// Compiling from ./java/src/ :
|
12
|
+
// javac xdojava.java -d ../bin
|
13
|
+
//
|
14
|
+
// Execution:
|
15
|
+
// java -classpath <application root>/java/bin xdojava <options>
|
16
|
+
//
|
17
|
+
//******************************************************************************
|
18
|
+
|
19
|
+
import java.awt.Robot;
|
20
|
+
import java.awt.event.KeyEvent;
|
21
|
+
import java.awt.AWTException;
|
22
|
+
import java.io.*;
|
23
|
+
import java.util.*;
|
24
|
+
|
25
|
+
public class xdojava
|
26
|
+
{
|
27
|
+
// CONSTANTS
|
28
|
+
// Escape seq. , Keystroke , Comment
|
29
|
+
public String ALT = "{ALT}"; // [Alt_L]
|
30
|
+
public String ALT_GR = "{ALT_GR}"; // [ISO_Level3_Shift]
|
31
|
+
public String BACKSPACE = "{BACKSPACE}"; // [BackSpace]
|
32
|
+
public String BS = "{BS}"; // [BackSpace]
|
33
|
+
public String CTRL = "{CTRL}"; // [Control_L]
|
34
|
+
public String DEL = "{DEL}"; // [Delete]
|
35
|
+
public String ENTER = "{ENTER}"; // [Enter]
|
36
|
+
public String END = "{END}"; // [End]
|
37
|
+
public String ESC = "{ESC}"; // [Escape]
|
38
|
+
public String HOME = "{HOME}"; // [Home]
|
39
|
+
public String INS = "{INS}"; // [Insert]
|
40
|
+
public String MENU = "{MENU}"; // [Menu]
|
41
|
+
public String NUM_ADD = "{NUM_ADD}"; // [KP_Add]
|
42
|
+
public String NUM_COMMA = "{NUM_COMMA}"; // [KP_Separator]
|
43
|
+
public String NUM_DEL = "{NUM_DEL}"; // [KP_Delete]
|
44
|
+
public String NUM_DIV = "{NUM_DIV}"; // [KP_Divide]
|
45
|
+
public String NUM_ENTER = "{NUM_ENTER}"; // [KP_Enter]
|
46
|
+
public String NUM_INS = "{NUM_INS}"; // [KP_Insert]
|
47
|
+
public String NUM_MUL = "{NUM_MUL}"; // [KP_Multiply]
|
48
|
+
public String NUM_SUB = "{NUM_SUB}"; // [KP_Subtract]
|
49
|
+
public String NUM0 = "{NUM0}"; // [KP_0]..[KP_9]
|
50
|
+
public String NUM1 = "{NUM1}"; // [KP_0]..[KP_9]
|
51
|
+
public String NUM2 = "{NUM2}"; // [KP_0]..[KP_9]
|
52
|
+
public String NUM3 = "{NUM3}"; // [KP_0]..[KP_9]
|
53
|
+
public String NUM4 = "{NUM4}"; // [KP_0]..[KP_9]
|
54
|
+
public String NUM5 = "{NUM5}"; // [KP_0]..[KP_9]
|
55
|
+
public String NUM6 = "{NUM6}"; // [KP_0]..[KP_9]
|
56
|
+
public String NUM7 = "{NUM7}"; // [KP_0]..[KP_9]
|
57
|
+
public String NUM8 = "{NUM8}"; // [KP_0]..[KP_9]
|
58
|
+
public String NUM9 = "{NUM9}"; // [KP_0]..[KP_9]
|
59
|
+
public String PAUSE = "{PAUSE}"; // [Pause]
|
60
|
+
public String PGDN = "{PGDN}"; // [Next]
|
61
|
+
public String PGUP = "{PGUP}"; // [Prior]
|
62
|
+
public String PRINT = "{PRINT}"; // [Print]
|
63
|
+
public String SHIFT_TAB = "{SHIFT_TAB}"; // [Tab]
|
64
|
+
public String SUPER = "{SUPER}"; // [Super_L]
|
65
|
+
public String TAB = "{TAB}"; // [Tab]
|
66
|
+
public String WIN = "{WIN}"; // [Super_L]
|
67
|
+
|
68
|
+
private Robot robot;
|
69
|
+
|
70
|
+
public xdojava() throws AWTException
|
71
|
+
{
|
72
|
+
robot = new Robot();
|
73
|
+
robot.setAutoDelay(40);
|
74
|
+
robot.setAutoWaitForIdle(true);
|
75
|
+
}
|
76
|
+
|
77
|
+
private void ActivateWindow(String windowTitle)
|
78
|
+
{
|
79
|
+
windowTitle = windowTitle.replaceAll("\"", "").trim();
|
80
|
+
System.out.println(windowTitle);
|
81
|
+
}
|
82
|
+
|
83
|
+
private void SendKey(String keystring)
|
84
|
+
{
|
85
|
+
keystring = keystring.trim();
|
86
|
+
|
87
|
+
if( keystring.equals("CONSTANTS") )
|
88
|
+
{
|
89
|
+
Constants();
|
90
|
+
}
|
91
|
+
else if( keystring.equals(ALT) )
|
92
|
+
{
|
93
|
+
Alt();
|
94
|
+
}
|
95
|
+
else if( keystring.equals(ENTER) )
|
96
|
+
{
|
97
|
+
Enter();
|
98
|
+
}
|
99
|
+
else if( keystring.equals(TAB) )
|
100
|
+
{
|
101
|
+
Tab();
|
102
|
+
}
|
103
|
+
else if( keystring.equals(SHIFT_TAB) )
|
104
|
+
{
|
105
|
+
ShiftTab();
|
106
|
+
}
|
107
|
+
else
|
108
|
+
{
|
109
|
+
//Type each character individually
|
110
|
+
byte[] byteArray = keystring.getBytes();
|
111
|
+
for (byte byt : byteArray)
|
112
|
+
{
|
113
|
+
int tempByt = (int)byt;
|
114
|
+
if( tempByt == 32 )
|
115
|
+
{
|
116
|
+
robot.keyPress(tempByt);
|
117
|
+
robot.keyRelease(tempByt);
|
118
|
+
}
|
119
|
+
else if( tempByt >= 48 && tempByt <= 57 )
|
120
|
+
{
|
121
|
+
robot.keyPress(tempByt);
|
122
|
+
robot.keyRelease(tempByt);
|
123
|
+
}
|
124
|
+
else if( tempByt >= 65 && tempByt <= 90 )
|
125
|
+
{
|
126
|
+
robot.keyPress(KeyEvent.VK_SHIFT);
|
127
|
+
robot.keyPress(tempByt);
|
128
|
+
robot.keyRelease(tempByt);
|
129
|
+
robot.keyRelease(KeyEvent.VK_SHIFT);
|
130
|
+
}
|
131
|
+
else if( tempByt >= 97 && tempByt <= 122 )
|
132
|
+
{
|
133
|
+
tempByt = tempByt - 32;
|
134
|
+
robot.keyPress(tempByt);
|
135
|
+
robot.keyRelease(tempByt);
|
136
|
+
}
|
137
|
+
|
138
|
+
}
|
139
|
+
}
|
140
|
+
}
|
141
|
+
|
142
|
+
private void Alt()
|
143
|
+
{
|
144
|
+
robot.keyPress(KeyEvent.VK_TAB);
|
145
|
+
robot.keyRelease(KeyEvent.VK_TAB);
|
146
|
+
}
|
147
|
+
|
148
|
+
private void Enter()
|
149
|
+
{
|
150
|
+
robot.keyPress(KeyEvent.VK_ENTER);
|
151
|
+
robot.keyRelease(KeyEvent.VK_ENTER);
|
152
|
+
}
|
153
|
+
|
154
|
+
private void Tab()
|
155
|
+
{
|
156
|
+
robot.keyPress(KeyEvent.VK_TAB);
|
157
|
+
robot.keyRelease(KeyEvent.VK_TAB);
|
158
|
+
}
|
159
|
+
|
160
|
+
private void ShiftTab()
|
161
|
+
{
|
162
|
+
robot.keyPress(KeyEvent.VK_SHIFT);
|
163
|
+
robot.keyPress(KeyEvent.VK_TAB);
|
164
|
+
robot.keyRelease(KeyEvent.VK_TAB);
|
165
|
+
robot.keyRelease(KeyEvent.VK_SHIFT);
|
166
|
+
}
|
167
|
+
|
168
|
+
public void Constants()
|
169
|
+
{
|
170
|
+
System.out.println("Implemented");
|
171
|
+
System.out.println(" ALT = {ALT}"); // [Alt_L]
|
172
|
+
System.out.println(" ENTER = {ENTER}"); // [Enter]
|
173
|
+
System.out.println(" SHIFT_TAB = {SHIFT_TAB}"); // [Tab]
|
174
|
+
System.out.println(" TAB = {TAB}"); // [Tab]
|
175
|
+
System.out.println();
|
176
|
+
|
177
|
+
System.out.println("Not Implemented");
|
178
|
+
System.out.println(" ALT_GR = {ALT_GR}"); // [ISO_Level3_Shift]
|
179
|
+
System.out.println(" BACKSPACE = {BACKSPACE}"); // [BackSpace]
|
180
|
+
System.out.println(" BS = {BS}"); // [BackSpace]
|
181
|
+
System.out.println(" CTRL = {CTRL}"); // [Control_L]
|
182
|
+
System.out.println(" DEL = {DEL}"); // [Delete]
|
183
|
+
System.out.println(" END = {END}"); // [End]
|
184
|
+
System.out.println(" ESC = {ESC}"); // [Escape]
|
185
|
+
System.out.println(" HOME = {HOME}"); // [Home]
|
186
|
+
System.out.println(" INS = {INS}"); // [Insert]
|
187
|
+
System.out.println(" MENU = {MENU}"); // [Menu]
|
188
|
+
System.out.println(" NUM_ADD = {NUM_ADD}"); // [KP_Add]
|
189
|
+
System.out.println(" NUM_COMMA = {NUM_COMMA}"); // [KP_Separator]
|
190
|
+
System.out.println(" NUM_DEL = {NUM_DEL}"); // [KP_Delete]
|
191
|
+
System.out.println(" NUM_DIV = {NUM_DIV}"); // [KP_Divide]
|
192
|
+
System.out.println(" NUM_ENTER = {NUM_ENTER}"); // [KP_Enter]
|
193
|
+
System.out.println(" NUM_INS = {NUM_INS}"); // [KP_Insert]
|
194
|
+
System.out.println(" NUM_MUL = {NUM_MUL}"); // [KP_Multiply]
|
195
|
+
System.out.println(" NUM_SUB = {NUM_SUB}"); // [KP_Subtract]
|
196
|
+
System.out.println(" NUM0 = {NUM0}"); // [KP_0]..[KP_9]
|
197
|
+
System.out.println(" NUM1 = {NUM1}"); // [KP_0]..[KP_9]
|
198
|
+
System.out.println(" NUM2 = {NUM2}"); // [KP_0]..[KP_9]
|
199
|
+
System.out.println(" NUM3 = {NUM3}"); // [KP_0]..[KP_9]
|
200
|
+
System.out.println(" NUM4 = {NUM4}"); // [KP_0]..[KP_9]
|
201
|
+
System.out.println(" NUM5 = {NUM5}"); // [KP_0]..[KP_9]
|
202
|
+
System.out.println(" NUM6 = {NUM6}"); // [KP_0]..[KP_9]
|
203
|
+
System.out.println(" NUM7 = {NUM7}"); // [KP_0]..[KP_9]
|
204
|
+
System.out.println(" NUM8 = {NUM8}"); // [KP_0]..[KP_9]
|
205
|
+
System.out.println(" NUM9 = {NUM9}"); // [KP_0]..[KP_9]
|
206
|
+
System.out.println(" PAUSE = {PAUSE}"); // [Pause]
|
207
|
+
System.out.println(" PGDN = {PGDN}"); // [Next]
|
208
|
+
System.out.println(" PGUP = {PGUP}"); // [Prior]
|
209
|
+
System.out.println(" PRINT = {PRINT}"); // [Print]
|
210
|
+
System.out.println(" SUPER = {SUPER}"); // [Super_L]
|
211
|
+
System.out.println(" WIN = {WIN}"); // [Super_L]
|
212
|
+
}
|
213
|
+
|
214
|
+
public static void main(String[] args) throws AWTException
|
215
|
+
{
|
216
|
+
if( args.length == 0 )
|
217
|
+
{
|
218
|
+
Help();
|
219
|
+
System.exit(0);
|
220
|
+
}
|
221
|
+
|
222
|
+
if( args.length > 0 )
|
223
|
+
{
|
224
|
+
if( args[0].startsWith("-h"))
|
225
|
+
{
|
226
|
+
Help();
|
227
|
+
System.exit(0);
|
228
|
+
}
|
229
|
+
}
|
230
|
+
|
231
|
+
xdojava XdoJava = new xdojava();
|
232
|
+
String argString = new String();
|
233
|
+
|
234
|
+
if( args[0].startsWith("-w"))
|
235
|
+
{
|
236
|
+
if( args.length > 1 )
|
237
|
+
{
|
238
|
+
for( int i = 1; i < args.length; i++)
|
239
|
+
{
|
240
|
+
argString = argString + " " + args[i];
|
241
|
+
}
|
242
|
+
XdoJava.ActivateWindow(argString);
|
243
|
+
}
|
244
|
+
else
|
245
|
+
{
|
246
|
+
System.exit(0);
|
247
|
+
}
|
248
|
+
}
|
249
|
+
else
|
250
|
+
{
|
251
|
+
for( int i = 0; i < args.length; i++)
|
252
|
+
{
|
253
|
+
argString = argString + " " + args[i];
|
254
|
+
}
|
255
|
+
XdoJava.SendKey(argString);
|
256
|
+
}
|
257
|
+
|
258
|
+
}
|
259
|
+
|
260
|
+
public static void Help()
|
261
|
+
{
|
262
|
+
System.out.println("java xdojava CONSTANTS to list special character constants");
|
263
|
+
System.out.println("java xdojava <string> to send <string> to active window");
|
264
|
+
System.out.println(" currently only alpha-numerics");
|
265
|
+
System.out.println("java xdojava <CONSTANT> to send special character <CONSTANT>");
|
266
|
+
System.out.println(" to active window");
|
267
|
+
//System.out.println("java xdojava -w <window name> to make <window name> the active window");
|
268
|
+
System.out.println("java xdojava -h for this help");
|
269
|
+
}
|
270
|
+
|
271
|
+
}
|
272
|
+
|
273
|
+
|
data/lib/xdojava.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module SageoneNaUtils
|
2
|
+
class XdoJava
|
3
|
+
# Types a character sequence, but without any special chars.
|
4
|
+
def type_keys(type_this)
|
5
|
+
#command_line = 'java -classpath ' + get_classpath + ' xdojava ' + type_this
|
6
|
+
command_line = 'java xdojava ' + type_this
|
7
|
+
system(command_line)
|
8
|
+
sleep(0.5)
|
9
|
+
end
|
10
|
+
|
11
|
+
def tab
|
12
|
+
#command_line = 'java -classpath ' + get_classpath + ' xdojava {TAB}'
|
13
|
+
command_line = 'java xdojava {TAB}'
|
14
|
+
system(command_line)
|
15
|
+
end
|
16
|
+
|
17
|
+
def tab_back
|
18
|
+
#command_line = 'java -classpath ' + get_classpath + ' xdojava {SHIFT_TAB}'
|
19
|
+
command_line = 'java xdojava {SHIFT_TAB}'
|
20
|
+
system(command_line)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xdojava
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 961915988
|
5
|
+
prerelease: 6
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
- pre
|
11
|
+
version: 1.0.0.pre
|
12
|
+
platform: ruby
|
13
|
+
authors:
|
14
|
+
- rgunter
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2012-09-17 00:00:00 Z
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description:
|
23
|
+
email:
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- lib/xdojava.class
|
32
|
+
- lib/xdojava.java
|
33
|
+
- lib/xdojava.rb
|
34
|
+
homepage:
|
35
|
+
licenses: []
|
36
|
+
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
hash: 3
|
48
|
+
segments:
|
49
|
+
- 0
|
50
|
+
version: "0"
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 25
|
57
|
+
segments:
|
58
|
+
- 1
|
59
|
+
- 3
|
60
|
+
- 1
|
61
|
+
version: 1.3.1
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.8.24
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: basic cross-platform keystroke emulation
|
69
|
+
test_files: []
|
70
|
+
|
71
|
+
has_rdoc:
|