Java search for on-screen text field

后端 未结 3 1001
暗喜
暗喜 2020-12-18 16:15

I am trying to create a program that automatically searches for a text field on the screen and types a word repetitively into that text field. Is there any class that can fi

3条回答
  •  眼角桃花
    2020-12-18 17:16

    my friend, the Robot class can simulate writing text.

    private static void typeOut(String s,Robot bot)
    {
    try
    {
    char [] chars = s.toCharArray();
    for (char c : chars) 
    {
    bot.keyPress((int)c);
    bot.keyRelease((int)c);
    }
    }
    catch (Exception e) 
    {
    System.out.println(e.getMessage());
    }
    }
    

    and you can use this method by

    Robot bot=new Robot();    
    typeOut("WWW.GOOGLE.COM", bot);
    

    and if in any way you want to read text or write text to a textfield on a browser i would advice you to use selenium.

提交回复
热议问题