Questions tagged [awtrobot]

The Robot class (java.awt.Robot) is used to programmatically trigger input events such as key press events and mouse actions & can also perform screenshot capture.

The Robot class (java.awt.Robot) is used to programmatically trigger input events, such as key press events and mouse actions & can also perform capture.

For Example:

Example of Java Robot Programming

662 questions
12
votes
3 answers

Headless environment error in java.awt.Robot class with MAC OS

I am trying to capture screen shots in my JavaFX application using Robot class, this is the code which I used in my application: Rectangle screenBounds = new Rectangle(Screen.getPrimary().getBounds().getWidth(), …
Shreyas Dave
  • 3,815
  • 3
  • 28
  • 57
11
votes
5 answers

How do I read pixels from a PNG file?

I know how to capture a screenshot by using Robot, Windowtester or FEST. I also know how to read a pixel from the screen by using robot. int x = 10; int y = 10; Color px = getPixelColor(int x, int y); However, I don't know how to read a pixel from…
user793623
11
votes
2 answers

Sending slash and backslash with Java

When using a Java robot, when sending a slash or backslash throws an exception. For example: public void slash() throws AWTException { Robot rob = new Robot(); rob.keyPress(KeyEvent.VK_SLASH); rob.keyRelease(KeyEvent.VK_SLASH); } public…
borges
  • 371
  • 4
  • 12
10
votes
2 answers

Does java.awt.Robot.waitForIdle() wait for events to be dispatched?

I'm using java.awt.Robot for integration tests of my Swing application, but I'm having trouble running my actions in the correct order. How can I tell the thread that calls robot.mousePressed(...) to block until Swing is finished dispatching that…
yonran
  • 18,156
  • 8
  • 72
  • 97
9
votes
3 answers

How to get the x and y of a program window in Java?

Is there a way for me to get the X and Y values of a window in java? I read that I'll have to use runtime, since java can't mess directly, however I am not so sure of how to do this. Can anyone point me some links/tips on how to get this?
Pedro Cimini
  • 175
  • 1
  • 1
  • 7
9
votes
8 answers

How can I make Robot type a `:`?

I want to type : using Java Robot. However, I'm getting an IllegalArgumentException. My code is: robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_COLON); robot.keyRelease(KeyEvent.VK_COLON); robot.keyRelease(KeyEvent.VK_SHIFT); The…
Eric Bautista
  • 403
  • 3
  • 8
  • 18
9
votes
2 answers

Alt+Tab using Java Robot

I am trying to bring up the alt+tab menu with a Java Robot. When I call the alt_tab() method, I want to bring up the alt+tab menu and keep the menu up. I know this can be achieved using alt+ctrl+tab. So far I have tried the code below, and also…
Kahtaf Alam
  • 463
  • 2
  • 7
  • 19
8
votes
8 answers

Get the VK int from an arbitrary char in java

How do you get the VK code from a char that is a letter? It seems like you should be able to do something like javax.swing.KeyStroke.getKeyStroke('c').getKeyCode(), but that doesn't work (the result is zero). Everyone knows how to get the key code…
Myer
  • 3,670
  • 2
  • 39
  • 51
8
votes
5 answers

Robot.mouseMove not moving to specified location properly

Whenever I run a mouseMove command for a robot, the mouse doesn't always go to the same location. For example, I have the following code: import java.awt.Robot; import java.util.concurrent.TimeUnit; public class MainBot { public static void…
DarkHorse
  • 963
  • 1
  • 10
  • 28
8
votes
4 answers

How to emulate pressing media keys in Java?

How can I emulate pressing media keys in Java? Such as play/pause, next/previous, volume control. C# has VK_MEDIA_PLAY_PAUSE, VK_MEDIA_NEXT_TRACK and so on. Java has class Robot for working with keys, but there are no media keys.
just_user
  • 91
  • 1
  • 2
8
votes
2 answers

How to capture only a desired portion of screen using createScreenCapture

The following code captures the screen: import java.awt.Dimension; import java.awt.Rectangle; import java.awt.Robot; import java.awt.Toolkit; import java.awt.image.BufferedImage; public class capture{ public static void main(String args[])…
Kumara
  • 117
  • 2
  • 10
8
votes
3 answers

Cannot press Window+L using robot in Java

I am using the Robot class to simulate key press in Java. But i am unable to press Window key+L although i am able to press them individually. Here is my code: private void pressKey() { Robot r=new Robot(); …
Madeyedexter
  • 1,155
  • 2
  • 17
  • 33
7
votes
1 answer

Get screen coordinates of a node in javaFX 8

I am developing a JavaFX application on Windows 8.1 64bit with 4GB of RAM with JDK version 8u45 64bit. I want to capture part of the screen using Robot but the problem is that I can't get the screen coordinates of the anchor pane that I want to…
Waxren
  • 2,002
  • 4
  • 30
  • 43
7
votes
2 answers

How to press physical buttons of android programatically

I want to press volume button programatically. In Java it is possible using the robot class, but in Android there is no robot class. I am wondering how to achieve this in Android.
Varun Chaudhary
  • 370
  • 4
  • 19
7
votes
3 answers

Java bot for an online game

I am creating a bot in java using the java.awt.Robot. The bot works fine on a browser (I have also tested it using Microsoft Word!) but when I run it in the game, the only function that works is the mouseMove. I want to build a bot that simply…
George Artemiou
  • 3,076
  • 2
  • 19
  • 36
1
2
3
44 45