awtrobot

Java Robot Keypress Command Key

…衆ロ難τιáo~ 提交于 2019-11-30 17:13:21
What is the VK_[key] code for the command key on a mac, if one exists? I am trying to get a Robot (java Robot) to press the command key. I am using the command keyPress(), and I need to know the integer keycode for the command key on a mac. KeyEvent.VK_META , with key code 157 , is Java's virtual key that maps to the the Mac command key. 来源: https://stackoverflow.com/questions/15418987/java-robot-keypress-command-key

Type a String using java.awt.Robot

吃可爱长大的小学妹 提交于 2019-11-30 14:35:55
问题 I already know how to use java.awt.Robot to type a single character using keyPress , as seen below. How can I simply enter a whole pre-defined String value at once into a textbox? robot.keyPress(KeyEvent.VK_1); robot.keyPress(KeyEvent.VK_1); robot.keyPress(KeyEvent.VK_1); // instead, enter String x = "111" 回答1: Common solution is to use the clipboard: String text = "Hello World"; StringSelection stringSelection = new StringSelection(text); Clipboard clipboard = Toolkit.getDefaultToolkit()

Get the VK int from an arbitrary char in java

我是研究僧i 提交于 2019-11-30 09:15:42
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 if you already have a KeyEvent, but what if you just want to turn chars into VK ints? I'm not interested in getting the FK code for strange characters, only [A-Z],[a-z],[0-9]. Context of this problem -------- All of the Robot tutorials I've seen assume programmers love to spell out words by sending keypresses with VK codes: int keyInput[] = {

Increasing screen capture speed when using Java and awt.Robot

我们两清 提交于 2019-11-30 01:51:31
问题 Edit: If anyone also has any other recommendations for increasing performance of screen capture please feel free to share as it might fully address my problem! Hello Fellow Developers, I'm working on some basic screen capture software for myself. As of right now I've got some proof of concept/tinkering code that uses java.awt.Robot to capture the screen as a BufferedImage. Then I do this capture for a specified amount of time and afterwards dump all of the pictures to disk. From my tests I'm

Java Robot Keypress Command Key

南楼画角 提交于 2019-11-30 00:35:45
问题 What is the VK_[key] code for the command key on a mac, if one exists? I am trying to get a Robot (java Robot) to press the command key. I am using the command keyPress(), and I need to know the integer keycode for the command key on a mac. 回答1: KeyEvent.VK_META, with key code 157 , is Java's virtual key that maps to the the Mac command key. 来源: https://stackoverflow.com/questions/15418987/java-robot-keypress-command-key

Change mouseListener while mouse is pressed

旧巷老猫 提交于 2019-11-29 17:08:32
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 mousePressed event after the glassPane has been acivated. Now here comes the problem, this workaround only

Using Java's Robot to hold a key down

十年热恋 提交于 2019-11-29 12:27:40
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.currentTimeMillis() - curTime < duration) { rob.keyPress(whatever); } rob.keyRelease(whatever); This,

How does Robot's getPixelColor(int x, int y) method work?

狂风中的少年 提交于 2019-11-29 11:52:02
How exactly does the method getPixelColor(int x,int y) from the Robot class work? I tried this code fragment: try { Robot robos = new Robot(); } catch (AWTException e) { } for (int i = 0; i < 100; i++) robos.getPixelColor(0, 0); System.out.println("fsadf"); on my PC, which is a core 2 duo, and it took one second or less to execute the print statement. However, when I ran this same code on my laptop, which is a core i3, it took much more time (about 2-3 seconds). What is the reason behind this? Does it have to do with the screen quality or something like that? How can I solve this problem? how

Invalid key code @ java

…衆ロ難τιáo~ 提交于 2019-11-29 08:58:23
I'm working on a system to type things automatically with java. This is how I write it: public void typeMessage(String message) { for (char c : message.toCharArray()) { int code = c; if (code > 96 && code < 123) code = code - 32; if (c == '@') { robot.keyPress(VK_SHIFT); robot.keyPress(VK_AT); robot.keyRelease(VK_SHIFT); robot.keyRelease(VK_AT); } else { type(code); } } type(VK_ENTER); } But I'm getting this error: Exception in thread "Thread-2" java.lang.IllegalArgumentException: Invalid key code on robot.keyPress(VK_AT); Your keyboard layout should have a key for the @ symbol for this code

Java search for on-screen text field

匆匆过客 提交于 2019-11-29 08:48:47
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 Alex Lynch I can't directly give you a solution, but I messed around with some code and may be able to point you in the right direction. Java, as you probably know, runs in the JVM. This