awtrobot

java print screen two monitors

巧了我就是萌 提交于 2019-12-21 04:23:09
问题 I'm trying to use print screen image area to get 2 monitors, but only works for one monitor. Can you advise me how to get figure 2 monitors? Robot robot = new Robot(); Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); BufferedImage capture = new Robot().createScreenCapture(screenRect); ImageIO.write(capture, "bmp", new File("printscreen.bmp")); 回答1: Union together the bounds of each screen: Rectangle screenRect = new Rectangle(0, 0, 0, 0); for (GraphicsDevice

How do you simulate a click on a JTextField? Equivalent of JButton doClick()?

三世轮回 提交于 2019-12-19 12:11:57
问题 I am working on a Java project and need to have a keypress simulate a click on a JTextField. What I'm looking for is the equivalent of the JButton doClick() method. I am trying to have the keypress "enter" perform the exact same function as a click on the JTextField. Not sure what other info to provide. Thanks in advance. 回答1: public void simulateKey(KeyEvent e, Component c) { Field f = KeyEvent.class.getField("focusManagerIsDispatching"); f.setAccessible(true); f.set(e, Boolean.TRUE); c

Change mouseListener while mouse is pressed

你离开我真会死。 提交于 2019-12-18 09:28:41
问题 I'm working on a game in Java and have the following challenge. I have 2 JPanels and need to visually drag shapes from one JPanel to another. I've got this working using the GlassPane from the JFrame . When I press the mouse to drag a shape, the GlassPane activates and transfers the shape to the glassPane. Because of this you need to transfer the mousePressed state from the JPanels mouseAdapter to the glassPanes mouseAdapter . I solved this by using the Robot Class which simulates another

Using Java's Robot to hold a key down

别来无恙 提交于 2019-12-18 07:15:18
问题 Currently i'm trying to have java hold down a key like follows: Robot rob; rob.keyPress(KeyEvent.VK_ENTER); Thread.sleep(3000); rob.keyRelease(KeyEvent.VK_ENTER); This should hold enter down for 3 seconds, causing the repeating effect after a second or so. In other words, if you were to manually hold the "r" key, it would first type r, and then after about a second it would go like rrrrrrrr. I want this effect from the robot. I also tried: curTime = System.currentTimeMillis(); while(System

Using Java's Robot to hold a key down

天涯浪子 提交于 2019-12-18 07:15:04
问题 Currently i'm trying to have java hold down a key like follows: Robot rob; rob.keyPress(KeyEvent.VK_ENTER); Thread.sleep(3000); rob.keyRelease(KeyEvent.VK_ENTER); This should hold enter down for 3 seconds, causing the repeating effect after a second or so. In other words, if you were to manually hold the "r" key, it would first type r, and then after about a second it would go like rrrrrrrr. I want this effect from the robot. I also tried: curTime = System.currentTimeMillis(); while(System

Faster alternative to java.awt.Robot.createScreenCapture?

流过昼夜 提交于 2019-12-18 05:59:27
问题 I'm making a program that requires at least 24 screenshots per second to be captured. Currently with the code below I'm only getting 1 per every ~94 milliseconds, so about 10 per second. I'd prefer not to use any 3rd party libraries because I'm trying to keep it as small as possible, but if I'd get significant performance increase I'd be willing to. I'm also trying to keep this platform independent, but again, if it would be a really significant performance increase I'd be willing to keep it

Java search for on-screen text field

为君一笑 提交于 2019-12-18 05:25:08
问题 I am trying to create a program that automatically searches for a text field on the screen and types a word repetitively into that text field. Is there any class that can find a text field? Or is there any way in which a text field can be found? Because I know that the Robot class can type text, I just need to either get the cursor onto the text field and use the mousePress() and mouseRelease() methods. Thanks 回答1: I can't directly give you a solution, but I messed around with some code and

How can I control the keyboard and mouse with Python?

旧时模样 提交于 2019-12-17 22:42:41
问题 How can I control the mouse and keyboard in Python? The idea is to do the same as the Robot() class in Java. Be able to say: move the mouse from here to here, click there, write that whatever is on the screen. For Windows there is win32api but I'm using mainly Linux. For Linux there is Xlib but does it works for keyboard as well? (found only reference to the mouse) Is there a cross-platform solution? (Linux, Windows and even OS X would be the great.) 回答1: I use dogtail (https://fedorahosted

Use a robot to type characters in Java

∥☆過路亽.° 提交于 2019-12-17 20:54:30
问题 I know how to have Robot simulate a Y keypress like so: Robot.keyPress(KeyEvent.VK_Y); But how do I get Robot to press a quote and period?: ". Can anyone provide me some reference page or sample code? 回答1: You can't always just use the KeyEvent.VK... variable. For example on my keyboard the "%" character is above the "5". To use a Robot to type a "5", the code would be: robot.keyPress(KeyEvent.VK_5); robot.keyRelease(KeyEvent.VK_5); and use a Robot to type a "%", the code would be: robot

Using Java to send key combinations

人盡茶涼 提交于 2019-12-17 18:40:43
问题 As per this previous link (How to send keyboard outputs) Java can simulate a key being pressed using the Robot class. However, how could a combination of key presses be simulated? If I wanted to send the combination "alt-123" would this be possible using Robot? 回答1: The simple answer is yes. Basically, you need to wrap the keyPress/Release of the Alt around the other keyPress/Release s public class TestRobotKeys { private Robot robot; public static void main(String[] args) { new TestRobotKeys