I am working on this is the project:
http://code.google.com/p/pg3b/
When activated, the user will be moving the mouse, clicking, and pressing buttons on the keyboard. Until you press a special hotkey to deactivate it, the app uses these inputs to control the PG3B, which controls the Xbox controller. This lets you play FPS and other games on the Xbox 360 using the keyboard, mouse, or any other computer peripheral such as joysticks, pedals, etc.
When activated, I can easily prevent the app from accepting keyboard input or mouse clicks:
// Stop keyboard buttons.
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {
public boolean dispatchKeyEvent (KeyEvent event) {
return true;
}
});
// Stop mouse buttons.
getGlassPane().setVisible(true);
However, I need to prevent the mouse from clicking on other windows, which would cause the app to lose focus and then it would no longer be handling the peripheral input. Any ideas on how to solve this? I’d like it to be as cross platform as possible.
Here is a bit of a hack:
// Stop mouse movement.
final Robot robot = new Robot();
Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
public void eventDispatched (AWTEvent event) {
robot.mouseMove(getX() + getWidth() / 2, getY() + getHeight() / 2);
}
}, AWTEvent.MOUSE_MOTION_EVENT_MASK);
This isn’t good enough though. If you move the mouse and click fast enough, you are able to click on other windows.
One idea I had was to use LWJGL to grab the mouse. I played around with this but haven’t been able to get it to work yet. My app doesn’t use OpenGL, so I’m not sure what is the minimum required to get mouse grab to work.