A program written in Java similar to the key-pushing wizard. It supports script file writing (including source code)

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.