Can a java program "enter" into another Windows program, for example, notepad

In any case, do you need to enter the JAVA process in the notepad.exe process?

+4
source share
1 answer

Yes, using a robot is the solution:

import java.awt.Robot; import java.awt.event.KeyEvent; public class Notepad { static int keyInput[] = { KeyEvent.VK_J, KeyEvent.VK_A, KeyEvent.VK_V, KeyEvent.VK_A, KeyEvent.VK_SPACE }; public static void main(String[] args) throws Exception { Runtime.getRuntime().exec("notepad"); Robot robot = new Robot(); for (int i = 0; i < keyInput.length; i++) { robot.keyPress(keyInput[i]); robot.delay(100); } } } 

if you want to convert String to keyEvents check this question Convert String to KeyEvents

+14
source

Source: https://habr.com/ru/post/1304637/


All Articles