mouse pointer relocates when I press button


05-08-2008 15:09:39

I have created a button, but when I click on it, when the mouse button is released the pointer teleports to somewhere in the middle of the screen, and the button event is not fired.

When I move the mouse afterwards, the pointer teleports back to where it was before and moves as normal.

I set the mouse position with absolute coordinates myself (these are abs coordinates from OIS, but adjusted for mouse speed).
->injectMouseMove(key.mPosAbs.x, key.mPosAbs.y, e.state.Z.abs);

if I copy the demo and do:
then it works fine (but then mouse is too slow and I have no control of starting position).


06-08-2008 00:12:00

You should also use this coordinates in injectMousePress and injectMouseRelease.
Something like
->injectMouseRelease(key.mPosAbs.x, key.mPosAbs.y, button_id);
->injectMouseRelease(e, button_id);


06-08-2008 12:26:09

ah! of course!


13-08-2008 06:27:28

Can you, please, show all related to mouse control code. I think this will be useful for other users.

13-08-2008 11:55:07



13-08-2008 12:28:29

Its using my own structs but it should be simple enough to understand

float MOUSE_SPEED = 1.5;

bool mouseMoved(const OIS::MouseEvent &e )
//this is for mouse speed
key.mSpeed.x = e.state.X.rel * MOUSE_SPEED;
key.mSpeed.y = e.state.Y.rel * MOUSE_SPEED;
key.mSpeed.z = e.state.Z.rel / 100;

//this is for mouse coordinate in pixels
key.mPosAbs.x += key.mSpeed.x;
key.mPosAbs.y += key.mSpeed.y;

if (key.mPosAbs.x > viewport->getActualWidth())
key.mPosAbs.x = viewport->getActualWidth();
if (key.mPosAbs.y > viewport->getActualHeight())
key.mPosAbs.y = viewport->getActualHeight();
if (key.mPosAbs.x < 1)
key.mPosAbs.x = 1;
if (key.mPosAbs.y < 1)
key.mPosAbs.y = 1;

//this is mouse coordinate as 0-1 values
key.mPos.x = key.mPosAbs.x / ou.render.getScreenWidth();
key.mPos.y = key.mPosAbs.y / ou.render.getScreenHeight();

guiManager->injectMouseMove(key.mPosAbs.x, key.mPosAbs.y, e.state.Z.abs);

return true;

and then mouse click and release callbacks just enter the mPosAbs:

gui.getGuiManager()->injectMousePress(key.mPosAbs.x, key.mPosAbs.y, (MyGUI::MouseButton)id);