awtrobot

Using the Robot class in Java to simulate “Fn” key press

假如想象 提交于 2019-12-12 18:16:58
问题 I'm trying to write a small program that makes the backlight of my laptop's keyboard flash whenever I receive an email/text/other type of message. I'm trying to use Java's Robot class to do this. My problem so far is that I cannot seem to find the keycode for the "Fn" key. 回答1: Java generally does not recognize multimedia key strokes (and Fn is generally considered non-standard keyboard key) as valid ones in its inbuilt libraries and will return 0 on non-standard keystroke event . But you can

Robot.mouseMove does not work at all in Mac OS X

谁说我不能喝 提交于 2019-12-12 10:54:20
问题 I created java file in IntelliJ IDE, with that code import java.awt.AWTException; import java.awt.MouseInfo; import java.awt.Robot; public class JavaRobotExample { public static void main(String[] args) { int x = 12, y = 300; try { Robot robot = new Robot(); robot.mouseMove(x, y); int xAct = (int) MouseInfo.getPointerInfo().getLocation().getX(), yAct = (int) MouseInfo.getPointerInfo().getLocation().getY(); String sPred = String.format("Predicted mouse location : %, d, %, d", x, y), sAct =

How to emulate pressing media keys in Java?

拥有回忆 提交于 2019-12-12 07:26:52
问题 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. 回答1: I used the JNI Library to simulate the key presses using code written in C. I've created a .dll file and .java file for hitting the "Volume Down", "Volume Up", "Volume Mute", "Previous Track", "Next Track", and "Play/Pause Track" media keys. Here is a link to

How to make Java Robot hold down a key?

混江龙づ霸主 提交于 2019-12-12 05:58:48
问题 I want to hold down a key for a certain amount of time using the Java robot. I have read other similar threads, but none of them work. Repeatedly pressing the key will only result in the key not releasing. Here's my code so far (It does not work since it only presses the key once): new Thread(new Runnable() { public void run() { final int keyP = 0; //the key to press final int duration = 2000 //2 seconds Robot r = null; try { r = new Robot(); } catch (AWTException e1) { e1.printStackTrace();

How to emulate pressing media keys in Java?

久未见 提交于 2019-12-12 01:28:26
问题 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. 回答1: I used the JNI Library to simulate the key presses using code written in C. I've created a .dll file and .java file for hitting the "Volume Down", "Volume Up", "Volume Mute", "Previous Track", "Next Track", and "Play/Pause Track" media keys. Here is a link to

Simulate keypress in java to write user inputs to another application

妖精的绣舞 提交于 2019-12-12 00:34:26
问题 I am developing a virtual keyboard application. Everything works fine except that what ever i write is written into the present application only not the one that is running behind. I fell this is because ROBOT class in java only works for the application context that creates it. Is there a work around for this? Here is the code, i am trying to write ls in the terminal that is behind my java application: Robot robot = new Robot(); robot.keyPress(KeyEvent.VK_ALT); robot.keyPress(KeyEvent.VK_TAB

How to send a string which contains caps and small case character as well special character using java.awt.Robot?

安稳与你 提交于 2019-12-11 19:11:28
问题 Suppose I want to send the string below String 1 : cd /srcdir/data/PTcpGateway String 2 : vi am1py_packets_PS.config I don't wanted to send one by one character, instead want to send whole string in one go. Is it possible using Java Robot? I tried to follow this post, but it does not work for me. 来源: https://stackoverflow.com/questions/58220899/how-to-send-a-string-which-contains-caps-and-small-case-character-as-well-specia

Java print screen program

我的未来我决定 提交于 2019-12-11 14:02:43
问题 I am trying to use Robot in Java to make an image file of a print screen. So far I have: 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")); But I can't seem to get it to create the file. 回答1: s/printscreen.bmp/"printscreen.bmp" 回答2: Not sure if .bmp files are support. Oops, they are: System.out.println(

Java.awt.robot mousepress is not having any effect

南楼画角 提交于 2019-12-11 13:53:56
问题 I'm trying to simulate a left click in a different program using awt.robot, with the following code: int mask = InputEvent.BUTTON1_DOWN_MASK; bot.mouseMove(x, y); bot.mousePress(mask); bot.mouseRelease(mask); While this is moving the mouse to the correct part of the screen, the other program doesn't seem to be receiving the click. What am I doing wrong? In certain other programs, this same method produces the click, but in one program, it has no effect. I have tried Thread.sleep() to wait 30

Java Robot Linux stimulate all key events

橙三吉。 提交于 2019-12-11 09:28:40
问题 I am trying to type all the possible keys from Keyboard, irrespective of languages or layout using Java Robot. We have written a super class which has common methods to print characters KeyEvent.VK_A to KeyEvent.VK_Z , number KeyEvent.VK_0 to KeyEvent.VK_9 along with SHIFT key combination. Now coming to specific part that is if we are having Italy or Turkish Keyboard which are having Unicode present or if any other special character. How can I stimulate the same keypress or keyrelease ? (as