awtrobot

Use a robot to type characters in Java

风格不统一 提交于 2019-11-28 13:59:13
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? 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.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_5); robot.keyRelease(KeyEvent.VK_5); robot.keyRelease

Cannot press Window+L using robot in Java

拟墨画扇 提交于 2019-11-28 13:29:43
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(); robot.keyPress(KeyEvent.VK_WINDOWS); robot.keyPress(KeyEvent.VK_L); robot.keyRelease(KeyEvent.VK_WINDOWS); robot.keyRelease(KeyEvent.VK_L); } Try this instead: Runtime.getRuntime().exec("rundll32 user32.dll,LockWorkStation"); Try: private void pressKey(){ Robot r=new Robot(); robot.keyPress(KeyEvent.VK_WINDOWS); robot.keyPress(KeyEvent.VK_L); robot.keyRelease(KeyEvent.VK_L); robot

How to move a mouse smoothly throughout the screen by using java?

久未见 提交于 2019-11-28 09:31:40
There is a mouseMove()method that makes the pointer jump to that location. I want to be able to make the mouse move smoothly throughout the screen. I need to write a method named mouseGLide() which takes a start x, start y, end x, end y, the total time the gliding should take, and the number of steps to make during the glide. It should animate the mouse pointer by moving from (start x, start y) to (end x, start y) in n steps. The total glide should take t milliseconds. I don't know how to get started can anyone help me get started on this? Can anyone just tell me what steps I need to do in

Using Java to send key combinations

ε祈祈猫儿з 提交于 2019-11-28 08:32:19
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? 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(); } public TestRobotKeys() { try { robot = new Robot(); robot.setAutoDelay(250); robot.keyPress(KeyEvent

Programmatically clicking a GUI button in Java Swing

你说的曾经没有我的故事 提交于 2019-11-28 06:09:18
How would I programmatically click a Swing JButton in a way that would register all the relevant action/mouse events and be visible to the user (i.e. they'd see the button being pressed as if they actually clicked it)? The button is in the same application I'm running; I'm not trying to control a button in another application. I suppose I could directly inject events into the queue, but I'd prefer to avoid that approach if possible, and doing it that way wouldn't show a visible click. I see the java.awt.Robot class offers methods to move the mouse and click the mouse, but not to make it click

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

廉价感情. 提交于 2019-11-28 05:09: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

Invalid key code @ java

岁酱吖の 提交于 2019-11-28 02:20:15
问题 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

How can I make Robot type a `:`?

时光怂恿深爱的人放手 提交于 2019-11-28 01:55:20
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 exception is: java.lang.IllegalArgumentException: Invalid key code.]. I also tried with: robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_SEMICOLON); robot.keyRelease(KeyEvent.VK_SEMICOLON); robot.keyRelease(KeyEvent.VK_SHIFT); How can I solve this problem? try with this code : robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK

cannot instantiate a class using a button

人走茶凉 提交于 2019-11-28 00:29:30
I am trying to make a screen capturing program. What I have is a transparent window, which will give the area to be captured, with a button capture on it, and I am trying to instantiate a class captureScreen that works good when captureScreen is individually executed using a command prompt I am trying to instantiate this captureScreen class when button capture is hit. I have tried keeping this class on my screenrecord.java , putting the code in event listener also. In both these cases,I get these errors AWTException,must be caught or declared in Robot robot = new Robot(); and IOException in

Do Robot methods need to be run on the event queue?

半世苍凉 提交于 2019-11-27 23:32:47
Robot is part of the AWT library, but it seems quite different from most all the rest of the library. I am creating a Swing GUI that mixes Swing with Java Native Access (JNA) and Robot to allow Java to drive some MS Windows/Citrix work programs. My gut feeling is that since Robot will queue events on the "platform's native input queue" that the last thing I want to do is to run it on the EDT, but on the other hand, most of the classes in the AWT and Swing libraries should be run on the Swing event thread. So to try clarify this in my mind for me let me ask as specific a question as possible: