Import java. Io .*;
Import java. util .*;
Import java. AWT .*;
Import java. AWT. event .*;
/**
* Supports the key control program for script files.
*/
Public class keysprite {
Public static void main (string [] ARGs ){
String filename = "test. t ";
Try {
// Read the configuration file
Vector v = readfile (filename );
// Execution File
Parsevector (v );
} Catch (ioexception e ){
System. Out. println ("configuration file error ");
} Catch (exception e ){
System. Out. println ("other errors ");
}
}
/**
* Read the file to the vector.
* @ Param filepath: file path
*/
Public static vector readfile (string filepath) throws ioexception {
Vector v = new vector ();
// File Buffer input stream
Bufferedreader BR = new bufferedreader (
New inputstreamreader (
New fileinputstream (filepath )));
// Read data
String S = Br. Readline ();
While (s! = NULL ){
// Add to V
V. Add (s );
// Read the next row
S = Br. Readline ();
}
// Close the input stream
BR. Close ();
// Return data
Return V;
}
/**
* Parse the read vector and perform corresponding operations.
* @ Param v vector object
*/
Public static void parsevector (vector v ){
Int size = V. Size ();
Try {
// Create a robot object
Robot r = new robot ();
For (INT I = 0; I <size; I ++ ){
String S = (string) v. Get (I );
// Decomposition
String [] DATA = S. Split ("");
// Resolution execution
If (data [0]. Equals ("move ")){
// Obtain coordinates
Int x = integer. parseint (data [1]);
Int y = integer. parseint (data [2]);
// Move
R. mousemove (x, y );
} Else if (data [0]. Equals ("Press ")){
// Obtain the key types
Char c = data [1]. tolowercase (). charat (0 );
// Press the button
R. keypress (C );
// Release
R. keyrelease (C );
} Else if (data [0]. Equals ("paused ")){
// Get the pause time
Int time = integer. parseint (data [1]);
// Pause
Thread. Sleep (time );
}
}
} Catch (exception e ){
E. printstacktrace ();
}
}
}
Script File test. t
Pause 1000
Mobile 200 300
Pause 1000
Mobile 210 300
Pause 1000
Mobile 220 300
Pause 1000
Mobile 230 300
Pause 1000
Mobile 240 300
Pause 1000
Mobile 250 300
Pause 1000
Mobile 260 300
Pause 1000
Mobile 270 300
Pause 1000
Mobile 280 300
Pause 1000
Mobile 290 300
Pause 1000
Mobile 300 300
Pause 1000
Mobile 310 300