I use the following lines to simulate a control_a [select all] key action in Java with robots , But the clipboard is not getting text, why?
robot robot = null; Try {robot = new robot (); } Hold (AWTException pre) {System.err.println ("Robots can not be started:" + East); } Robot.mouseMove (260,500); Robot.mousepress (InputEvent.BUTTON1_MASK); // robot.mouseMove (660,700); Robot.mouserelease (InputEvent.BUTTON1_MASK); Robot.keyPress (KeyEvent.VK_CONTROL); // Choose all robots. KeyPoids (KAVent.VK_A); Robot.keyRelease (KeyEvent.VK_A); Robot.keyRelease (KeyEvent.VK_CONTROL); Robot.keyPress (KeyEvent.VK_CONTROL); // copy robot KeyPoint (KeyEvent.VK_C); Robot.keyRelease (KeyEvent.VK_C); Robot.keyRelease (KeyEvent.VK_CONTROL); Transferable T = Toolkit.getDefaultToolkit () GetSystemClipboard () GetContents (faucet); {If (t! = Null & amp; amp; amp; amp; amp; amp; amp; t.isDataFlavorSupported (DataFlavor.stringFlavor)) {string text = (string) Try T.getringdata (DataFlavor.stringFlavor); Println (text); }} Hold (Exception pre) {ex.printStackTrace (); } I have a browser open, so there is a text [260,500] on that screen in that area. What am I missing?
Edit:
I have some strange things when I opened a browser, the browser does not have text copies, but if I open Notepad / WordPad, there will be copies in their text So why did not the browser do this?
-
all your code inside the try block Where you instantiate the robot because you can try to work with a redundant reference and a NullPointerException . And if your robot is never ready and has never been copied, then you will not have any sense to try to access the content from the clipboard. -
I'm not completely sure that before trying to read from the clipboard, before adding a slight delay before fixing things, I'm guessing that the race between the lattice It may have to be done with the situation earlier the system had time to update it. This update code should work:
robot robot = null; Try {robot = new robot (); Robot.moussamov (260, 500); Robot.mousepress (InputEvent.BUTTON1_MASK); // robot.mouseMove (660,700); Robot.mouserelease (InputEvent.BUTTON1_MASK); Robot.keyPress (KeyEvent.VK_CONTROL); // Choose all robots. KeyPoids (KAVent.VK_A); Robot.keyRelease (KeyEvent.VK_A); Robot.keyRelease (KeyEvent.VK_CONTROL); Robot.keyPress (KeyEvent.VK_CONTROL); // copy robot KeyPoint (KeyEvent.VK_C); Robot.keyRelease (KeyEvent.VK_C); Robot.keyRelease (KeyEvent.VK_CONTROL); Try {// Sleep Thread Just Thread a Little Clipboard Content. Sleep (25); } Grip (Interrupted e) e.printStackTrace (); } Transferable T = Toolkit.GetDefaultToolKit () GetSystemClipboard () GetContents (faucet); {If (t! = Null & amp; amp; amp; amp; amp; amp; amp; t.isDataFlavorSupported (DataFlavor.stringFlavor)) {string text = (string) Try T.getringdata (DataFlavor.stringFlavor); Println (text); }} Hold (Exception pre) {ex.printStackTrace (); }} Hold (AWTException pre) {System.err.println ("Robot can not be started:" + east); }
Comments
Post a Comment