Executing Commands

Having read all the commands to execute, you can loop over those commands with a for loop. Each command, such as t:abc, which sends the text “abc” to the program the Robot project is controlling, is made up of an operation (“t” for text here) and data (“abc” here).

Here's how the Robot project extracts the operation and data from each command as it loops over all commands:

public void actionPerformed(ActionEvent e) 
{
    try{
        .
        .
        .
        for (int loopIndex = 0; loopIndex < numberCommands;
					loopIndex++){
					String operation = commands[loopIndex].substring(0, 1);
					String data = commands[loopIndex].substring(2);

        .
        .
        .

Sending Keystrokes

Each command is a single character, so you can use a switch statement to handle them all. Each operation ...

Get Java™ After Hours: 10 Projects You'll Never Do at Work now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.