@Override public void onComputeInstruction(ComputeInstruction instruction) { super.onComputeInstruction(instruction); System.out.println("Received Instruction: " + instruction.toString()); if (instruction.getCommand().equals("KEYPRESS")) { String key = instruction.getPayload("keycode"); int keycode = -1; if (key.equals("up")) { keycode = KeyEvent.VK_UP; } else if (key.equals("down")) { keycode = KeyEvent.VK_DOWN; } else if (key.equals("left")) { keycode = KeyEvent.VK_LEFT; } else if (key.equals("right")) { keycode = KeyEvent.VK_RIGHT; } else if (key.equals("a")) { keycode = KeyEvent.VK_D; } else if (key.equals("b")) { keycode = KeyEvent.VK_S; } else if (key.equals("start")) { keycode = KeyEvent.VK_ENTER; } else if (key.equals("select")) { keycode = KeyEvent.VK_SPACE; } System.out.println("Pressing " + keycode); Robot robot = this.getRobot(); // robot.delay(10); robot.keyPress(keycode); robot.delay(20); robot.keyRelease(keycode); } }
/** Handles Compute Instructions Received from Clients */ @Override public void onComputeInstruction(ComputeInstruction instruction) { System.out.println("Received Instruction: " + instruction.toString()); }