Jump to content

Automatic Mouse Grab without requiring clicking on window


Recommended Posts

Does anyone have any idea how I can properly have the mouse grabbed within the app without needing to click inside the window after changing the MouseHandle?

I've followed this guide and I've been able to get the mouse to grab and everything works properly. The caveat is that the mouse is only grabbed after clicking inside of the window after changing the MouseHandle.

I've tried to do it by directly setting App.MouseGrab to true and it has most of the behavior that I'm looking for. The mouse is grabbed immediately and works, but once I move the mouse to the edge of the screen, I'm no longer able to rotate the camera.

Link to comment

Hi Vadya_Rus,

The point is that the behavior described in the article you referred to (this guide) is considered normal.





The mouse behavior is defined by assigning any of the following modes:

  • Grab - the mouse is grabbed when clicked (the cursor disappears and camera movement is controlled by the mouse). This mode is set by default.
  • Soft - the mouse cursor disappears after being idle for a short time period.
  • User - the mouse is not handled by the system (allows input handling by some custom module).


So, you just don't want to click inside the window... Please correct me if I'm wrong. Well in this case the simplest way would be to emulate a click via code:

// checking for STATE_USE (ENTER key by default) and toggling mouse handling mode
if (controls->clearState(Controls::STATE_USE) == 1) {
	switch (ControlsApp::getMouseHandle())
		case Input::MOUSE_HANDLE_GRAB:
			// if the mouse is currently grabbed, we disable grabbing and restore GUI interaction
			if (App::isMouseGrab())
		case Input::MOUSE_HANDLE_SOFT:
		case Input::MOUSE_HANDLE_USER:
			App::setMouseButton(App::BUTTON_LEFT);// <--- Add this line

Thanks! Hope this helps!

  • Like 1
Link to comment
  • Create New...