I am new to Java programming. I wrote this program to insert "Hello world!". every second. The program works correctly, and the text is inserted into many Windows programs, such as Notepad, Microsoft Word, Browsers, and each text area or input field. But in some programs, my code did not work, for example, Windows End Task Manager or Garena.
Now my question is: can some programs reject JAVA codes for security reasons? If true, how to include Java in them?
Remember that I use the NetBeans IDE to program and compile a jar file. My code is as follows:
package com.javacodegeeks.snippets.desktop;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;
public class SimulateMouseMoveAndKeyPress {
public static void main(String[] args) throws InterruptedException {
try {
int counter = 0;
while(true) {
Thread.sleep(1000);
String myString = "[" + counter + "] Hello world!";
StringSelection stringSelection = new StringSelection (myString);
Clipboard clpbrd = Toolkit.getDefaultToolkit ().getSystemClipboard ();
clpbrd.setContents (stringSelection, null);
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);
counter = (counter)+1;
}
} catch (AWTException e) {
System.out.println("Low level input control is not allowed " + e.getMessage());
}
}
}
Please help me. Thanks to everyone.