Hello,
There is a problem when querying flag state using the following API CGEventSourceFlagsState(kCGEventSourceStateHIDSystemState). When there is external mouse movement the flag gets reset by a low OS-level event corresponding to mouse move. As a result the modifier keys don’t work as expected when using Java’s Robot which in-turn uses Apple's native CGEvent APIs.
The issue occurs at CRobot.m#L295 the flags gets reset or cleared when mouse is moved physically in unison with Robot's key events. The difference can be seen in the logs without and with mouse move for typing 'A'. (log attached)
Due to this issue applications that use Java's Robot on Mac don’t work as expected, in particular this behavior breaks the usability of the on-screen accessibility related keyboard application - TouchBoard. More details of this use case here. https://github.com/adoptium/adoptium-support/issues/710
The Robot is initialized with the following initial configurations - https://github.com/openjdk/jdk/blob/ac6af6a64099c182e982a0a718bc1b780cef616e/src/java.desktop/macosx/native/libawt_lwawt/awt/CRobot.m#L125
- Are we missing anything during initialization of Robot which cause this issue?
- Why does an external mouse movement cause the event flags to reset?
- Since a low level OS event corresponding to mouse move is causing the flag to reset, there might be an issue within the CGEventSourceFlagsState() API.
- Is there a reason behind why an external mouse event causes CGEventFlag state to reset to 0 ?
- Is there any known issue regarding CGEventSourceFlagsState() and a workaround for it?