0

Is it possible to simulate multiple keys press in Java application which is running in system without graphics environment or even started by systemd? It doesn't have to be multisystem solution, may just work in Linux.

If there is windows environment running I could use Robot as described here How to simulate keyboard presses in java? but in this case I can't (I get AWTException: headless environment)

user3626048
  • 706
  • 4
  • 19
  • 52
  • What are you trying to achieve? There may be a better way than simulating keypresses. – Federico klez Culloca Dec 21 '18 at 13:30
  • @FedericoklezCulloca I don't think there is better way, third party application is listening for keys pressed and running its own action then – user3626048 Dec 21 '18 at 13:35
  • If that third party program is running inside a tty, you could interface with ioctl via jni and send whatever you want. See [this](https://www.linuxquestions.org/questions/linux-software-2/how-do-i-stuff-a-keystroke-into-another-virtual-terminal%27s-stdin-839110/) thread. The solution is in C, but it's a start. – Federico klez Culloca Dec 21 '18 at 13:40
  • Also [this](https://stackoverflow.com/questions/8163166/calling-ioctl-from-java-how-is-it-done) about ioctl + jni – Federico klez Culloca Dec 21 '18 at 13:40
  • @FedericoklezCulloca thank you, I will try that – user3626048 Dec 21 '18 at 13:44
  • @FedericoklezCulloca what if 3rd party app would be running inside graphical environment but my app would work as service (using systemd/systemctl)? – user3626048 Dec 21 '18 at 13:50

0 Answers0