Type a String using java.awt.Robot

前端 未结 7 1853
难免孤独
难免孤独 2020-12-10 00:46

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

7条回答
  •  一整个雨季
    2020-12-10 01:14

        StringSelection path = new StringSelection("path of your document ");
    
        // create an object to desktop
    
        Toolkit tol = Toolkit.getDefaultToolkit();
    
        // get control of mouse cursor
    
        Clipboard c = tol.getSystemClipboard();
    
        // copy the path into mouse
        c.setContents(path, null);
    
        // create a object of robot class
    
        Robot r = new Robot();
    
        r.keyPress(KeyEvent.VK_CONTROL);
        r.keyPress(KeyEvent.VK_V);
        r.keyRelease(KeyEvent.VK_CONTROL);
        r.keyRelease(KeyEvent.VK_V);
        r.keyPress(KeyEvent.VK_ENTER);
        r.keyRelease(KeyEvent.VK_ENTER);
    
    }
    

提交回复
热议问题