awtrobot

How can I use java.awt.Robot inside games?

江枫思渺然 提交于 2019-12-11 08:20:55
问题 I am developing an Android application that controls the PC keyboard and mouse. I wanted to add a new feature (using your mobile as a game controller). I am using java.awt.Robot . It works fine in controlling the keyboard and mouse. But when I used it with games, java.awt.Robot doesn't press buttons. When I go outside the game, it works fine again. For example: if (senderPropertyOne.equalsIgnoreCase("l")) { robot.keyPress(KeyEvent.VK_LEFT); robot.keyRelease(KeyEvent.VK_LEFT); } else if

How to resolve “unreported exception AWTException ; must be caught or declared to be thrown”. Robot instance

*爱你&永不变心* 提交于 2019-12-11 06:05:02
问题 I have the error "unreported exception AWTException ; must be caught or declared to be thrown" instantiating a class that contain methods with mouse and key movements using Robot. I tried with try catch In the instance but the "click" doesnt work this way, what is the problem how to solve it? package Ventanas; enter code here import java.awt.AWTException; import java.awt.Robot; import java.awt.event.InputEvent; public class Sel { Robot robot = new Robot(); public void apos() throws

How to capture mouse cursor in Java?

纵然是瞬间 提交于 2019-12-11 05:11:50
问题 Ok, Most of you will think it's a duplicate because it's already written everywhere that it's not really doable and the only option is to do a screenshot using awt robot. But... The issue is that the mouse cursor does not even appear in the picture produced by AWT robot... I tries gnome-screeshots and there I can see the mouse cursor. But from the java screenshot, nothing. The entire picture, but not mouse cursor. It's like it's hidding it before taking the picture. I search for a parameter

Robot.keyPress does'nt work for VK_ALT_GRAPH (Invalid key code)

a 夏天 提交于 2019-12-11 02:59:34
问题 I'm working on a remoting app.(mouse - keyboard) I just showing fastly my issue... It's working for 'A' or some basic characters. case "a": robot.keyPress(KeyEvent.VK_A); But I did'nt make '@' character. My way is look like this. case "@": robot.keyPress(KeyEvent.VK_ALT_GRAPH); robot.keyPress(KeyEvent.VK_Q); robot.keyRelease(KeyEvent.VK_ALT_GRAPH); I see the exception when I use VK_ALT_GRAPH; Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Invalid key code at sun

AWT Robot not able to drag a window

泄露秘密 提交于 2019-12-11 01:22:45
问题 I'm trying to move a Windows Explorer window using the AWT Robot. The robot is running in Java 7, and the OS is Windows 7. I'm able to move the mouse and click on things, but when I try to click-and-drag, it doesn't seem to be pressing the button at all. I can't see what's wrong, or think of how to figure out what's happening. I started out using Sikuli: mouse.mouseDown(InputEvent.BUTTON1_MASK); mouse.drop(targetLocation); When that didn't work, I tried a lower-level implementation, working

How can I simulate a mousePressed event without using java.awt.robot?

一曲冷凌霜 提交于 2019-12-10 19:01:57
问题 I want to simulate a mousePressed event in Java, I found out that I can use the Robot class for this, and it works, but only in Windows and not in Mac OS X. Does anyone know of an alternative way to simulate a mousePressed event? This is the code I used: Robot robot = new Robot(); robot.mousePress(InputEvent.BUTTON1_MASK); 回答1: If you want to simulate the click action on a JButton you can invoke the doClick method, take a look here. Otherwise, maybe this similar question can help you. Hope

How do you determine if a character requires the shift key to be down to be typed?

佐手、 提交于 2019-12-10 18:48:24
问题 I am writing some code to type strings using the Robot class. Everything is mostly good (well, I have to use a big switch statement to get character keycodes), except some keys don't have keycodes, because they are actually a combination of Shift + some other key. For upper case letters, it is easy to check, using Character.isUpperCase(c) , but for all the symbols such as !@#$%^&*()_+ and various punctuation are not considered "upper case" although they do require shift to be pressed in order

Trying to paint image to JFrame with Java BufferedImage, Graphics

有些话、适合烂在心里 提交于 2019-12-10 17:39:14
问题 I'm trying to capture the screen and then paint the image to a JFrame recursively while scaling the image (to create that effect you get when you look at a mirror in a mirror). I'm having trouble with my code - it doesn't paint any graphics. What am I doing wrong? import java.awt.AWTException; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.Graphics; import java.awt.HeadlessException; import java.awt.Image; import java.awt.Rectangle; import java.awt.Robot; import java

Java awt.Robot: CTRL+ALT+DEL does not bring up desired screen

◇◆丶佛笑我妖孽 提交于 2019-12-10 17:17:20
问题 I just recently found out about the awt.Robot Library and I'm quite excited to get to use it. I thought I'd play a little prank on my friend and have the robot press control,alt,delete press the lock the computer button but I can't get the program to bring up the control alt delete screen. Here's my code: import java.awt.*; import java.awt.event.KeyEvent; public class Bot { public static void main(String[] args) { try { Robot bot = new Robot(); bot.delay(4000); bot.keyPress(KeyEvent.VK

Robot.mouseMove not moving to specified location properly

别等时光非礼了梦想. 提交于 2019-12-10 13:05:31
问题 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 main(String[] args){ try { Robot screenWin = new Robot(); TimeUnit.SECONDS.sleep(2); screenWin.mouseMove(100, 300); } catch (Exception e) { e.printStackTrace(); } } } The code usually makes the mouse end up at the X: First, I hit run (I am using eclipse)