Game Development Community

Can't track mouse movement if hardware cursor hidden

by Ken Pajala · in Torque Game Builder · 02/11/2008 (6:37 pm) · 2 replies

When I use Canvas.hideCursor() to hide the hardware cursor I lose the ability to track the mouse position. The cause of the issue seems to be twofold:

guiCanvas.cc -- GuiCanvas::processInputEvent()
else if(event->deviceType == MouseDeviceType && cursorON)
So if cursorON is false, we don't process mouse events...

And in GuiCanvas::setCursorON ()
if(!cursorON)
   mMouseControl = NULL;
If cursorON is false, we trash the mouseControl.

Removing those bits solves the mouse tracking issue, but leads to another problem that is likely Mac-specific. When the cursor is hidden and we click the mouse, the Carbon Event Handler thinks the cursor is still where it was when we first hid the mouse. So if you happen to be using a custom cursor, it then teleports it back to that position.

At least in my case I can step around that issue since I keep track of the cursor position myself, and when I get a gameWindow2D::onMouseDown event I just call gameWindow2D.setMousePosition($lastMousePos) and it solves my problem. I don't see a general solution at the moment though.

#1
02/12/2008 (3:58 pm)
I can't duplicate your issue; I've been hiding the cursor and successfully using sceneWindow2D.getMousePosition() for quite awhile. I assume you have useWindowMouseEvents set to true for your sceneWindow2D. What version are you using?

Greg
#2
02/12/2008 (4:57 pm)
Ah, okay... seems like the problem is actually my call to showCursor() which in turn calls Canvas.cursorOff() which I believe hides the custom cursor. Just using Canvas.hideCursor() hides the hardware cursor and works fine.

Still not sure why shutting off the custom cursor would turn off mouse events though.

Thanks.