A couple of things.
First, I’m wondering if I have hit a bug in JavaFX. I’ve sent an inquiry to openjfx-dev@openjdk.java.net. [EDIT: email submission was rejected. IDK yet if this was maybe due to my having read-only status or if they deemed the content off topic.]
AFAIK, the code below should generate the console message “main mouse move” when the mouse remains within the main area but is beyond the far edges of the nested, overridden Canvas, but doesn’t. Not being able to properly trigger mouse events over regions of the screen is a roadblock.
I’ve done my best to make the code example for the error as small as possible.
public class MouseMoveTest extends Application
{
public static void main(String[] args)
{
Application.launch(args);
}
@Override
public void start(Stage primaryStage)
{
Group root = new Group();
Scene scene = new Scene(root, 500, 200, Color.DARKGREY);
root.setOnMouseMoved(e -> System.out.println("main mouse move"));
CenterArea centerArea = new CenterArea(300, 100);
GridPane grid = new GridPane();
grid.setPadding(new Insets(50, 0, 0, 100));
grid.add(centerArea, 0, 0);
centerArea.setFocusTraversable(true);
root.getChildren().add(grid);
primaryStage.setScene(scene);
primaryStage.show();
}
}
class CenterArea extends Canvas {
private GraphicsContext gc;
public CenterArea(double arg1, double arg2)
{
super(arg1, arg2);
gc = getGraphicsContext2D();
gc.setFill(Color.RED);
gc.fillRect(0, 0, arg1, arg2);
setOnMouseMoved( e -> System.out.println("center mouse move"));
}
}
If the vector approach is used, it seems to me that considerable infrastructure would need to be rebuild, as I am making extensive use of buttons, dropdowns and sliders which were designed to respond to the mouse events that would have to be intercepted and interpreted.
I don’t know why I thought using a Robot might “reset” the mouse location. For example, I had the idea that if my mouse was at 100, 100 and the Robot moved the mouse to 200, 100, further mouse moves would proceed from 200,100. But as far as the system is concerned, the physical mouse is still at 100, 100.
As far as JNA libraries, it will be a chore, but there are some leads. For Windows, we have the SystemsParametersInfo() function which has been referenced in this stackoverflow thread, and some additional avenues to investigate as provided in this inquiry on the JNA google group. The responder points to likely routines to call for MacOS as well as also pointing to the same Windows-related code.
EDIT: another possibility that occurs to me is to do something such as make a double click or action put one into a mode where the cursor only operates in the syrup pit. Then the transitions don’t have to be coded in and out. Will ponder more. Regardless, I think I’m going to put this refinement on hold a bit while working on other aspects.