Java After Hours: 10 Projects Youll Never Do at Work
Chapter 7. Running Any Program Via Remote Control with the Robot
The Robot. Ever want to run some program by remote control? Ever get into one of those cases where you're just doing the same thing over and over in a program? Ever wish you could run a program late at nightand not have to be there? The answer is this chapter's project, the Robot. The Robot lets you run other programs by remote control, no matter what kind of programs they are. Using the Robot, you can control another program by sending keystrokes and mouse actions to it. You can even capture the screen when in the middle of some operation so you have a visual record of what happened. Very cool. You can see what the Robot looks like in Figure 7.1. All you have to do is to enter commands to the Robot in the text area on the left and click the Go button. Figure 7.1. The Robot.
What kind of commands can you enter in Robot? You can send text to the program you're controlling by remote control. You can use the Alt and Ctrl keys. You can also send tab characters, the Enter key, or the Esc key. NOTE Note that you can use the Alt key in Windows to open menus and select menu itemslook for the underlined character in the menu or menu item name and use that with the Alt key. For example, Alt+F will open the File menu, and Alt+X will select the Exit item in that menu.
You can also use the mousejust enter the screen location (in pixels) where you want the mouse to move to. Then click the mouse, right-click it, or double-click it (by clicking twice). You can also take screen captures, which is great if you've got an interim step in a process running late at night that can cause problemsyou can capture the screen and look at it later. Besides all this, you can tell the Robot to wait for a specified number of seconds before proceeding to the next step. If you want to tell the Robot to do its thing late at night, for example, this is the command to use. A companion command makes the Robot beep, informing you, even if you're not at your desk, that it's working again after one of these delays. You don't even have to enter commands into the text area of the Robot shown in Figure 7.1the Robot can read commands from a file, making repeated tasks that much easier to run. What commands are available? Here's the list, from the Robot's help screen (at right in Figure 7.1): Type text: t:abc t:ALTDN t:ALTUP t:CTRLDN t:CTRLUP t:TAB t:ENTER t:ESCAPE Move mouse: m:x,y Left Click: c: Right Click: r: Wait n sec's: w:n Cap screen: s: Beep: b:
Each command consists of a single letter, followed by a colon and, optionally, data for the command. For example, suppose you enter the following commands into the Robot and then click the Go button (note that there's a space at the end of the text in each line, although you can't see it here, to divide the words being sent to the target program): t:Hello t:from t:the t:robot.
The Robot would then send the text "Hello from the robot." to the program it's controlling. |