Jump to content

[SOLVED] Input::setMouseGrab(true) by code


photo

Recommended Posts

Hi?

When I call Input::setMouseGrab(true) by code, at least one left mouse click is need to control player's view

How can I apply mouse grab mode without mouse click by code?

Test code is here

-------------------------------

if (Input::isKeyUp(Input::KEY_TAB))
    {
        this->isPlayMode = !this->isPlayMode;

        if (this->isPlayMode)
        {
            Input::setMouseHandle(Input::MOUSE_HANDLE_GRAB);
            Input::setMouseGrab(true);
            this->playerActorPtr->setControlled(true);

        }
        else
        {
            Input::setMouseHandle(Input::MOUSE_HANDLE_USER);
            this->playerActorPtr->setControlled(false);
        }
    }

Link to comment

You can try this approach:

int AppWorldLogic::init()
{
	// set our own mouse grab logic and engine is no longer responsible for this
	Input::setMouseHandle(Input::MOUSE_HANDLE_USER);

	return 1;
}

int AppWorldLogic::update()
{
	if (Input::isKeyDown(Input::KEY_TAB))
	{
		is_play_mode = !is_play_mode;

		if (is_play_mode)
		{
			// prevent cursor from going outside window
			Input::setMouseGrab(true);

			// enable camera control
			ControlsApp::setEnabled(true);
			ControlsApp::setMouseEnabled(true);
		} else
		{
			// just do the opposite settings...
			Input::setMouseGrab(false);
			ControlsApp::setEnabled(false);
			ControlsApp::setMouseEnabled(false);
		}
	}

	return 1;
}

For GUI clicks you can use following methods to control the mouse behavior:

Thanks!

  • Like 1

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment
  • silent changed the title to [SOLVED] Input::setMouseGrab(true) by code
×
×
  • Create New...