1

Suppose I want to scroll using keys 'T' and 'Y' when my java process is running in background, is there any way to do it?

For instance java's robot class can be used to implement mouse click, key presses but I can not find anything relating to scroll.

1 Answers1

2

You've not said otherwise so I assume you're using Swing since you mention Robot, although JavaFX has a Robot too...

  • How to listen to keyboard events when a Java process is in the background

This is not possible without resorting to JNA or JNI, you can only get keyboard events on Java windows with focus. Other questions such as Key listener written in Java JNA. Prevent multiple Callback deal with this. Please be aware your solution will be platform dependent.

  • How to simulate scroll events.

I believe can be achieved with the mouse wheel event.

Robot robot = new Robot();
robot.mouseWheel(1);
robot.mouseWheel(-1);
Community
  • 1
  • 1
Adam
  • 35,919
  • 9
  • 100
  • 137