Monitor text that is highlighted

前端 未结 2 606
不知归路
不知归路 2020-12-18 11:20

This is more of a hypothetical question, I\'m brainstorming some ideas for a project that I\'m planning, and was curious if anyone knew of any APIs or methods of getting any

2条回答
  •  Happy的楠姐
    2020-12-18 12:10

    public static String getSelectedData() {
        try {
            Robot robot = new Robot();
            robot.keyPress(KeyEvent.VK_CONTROL);
            Thread.sleep(2*1000);
            robot.keyPress(KeyEvent.VK_C);
            Thread.sleep(2*1000);
            robot.keyRelease(KeyEvent.VK_C);
            Thread.sleep(2*1000);
            robot.keyRelease(KeyEvent.VK_CONTROL);
            Thread.sleep(2*1000);
        } catch (Exception ex) {
            System.out.println(ex);
        }
        String word = getSelectedData();
        return word;
    }
    

    private static String getDataFromClipboard() {

    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Clipboard clipboard = toolkit.getSystemClipboard();
    try {
        String result = (String) clipboard.getData(DataFlavor.stringFlavor);
        return result;
    } catch (Exception e) {
        System.out.println("ERROR");
        return null;
    }
    }
    

提交回复
热议问题