Problems with Mouse

im learning Panda3D now and wanted to test the mouse support. i copy & pasted the code from the documentation(, but the only thing i get is this error:

Known pipe types:
(all display modules loaded.)
Assertion failed: _has_mouse at line 65 of c:\buildslave\release_sdk_win32\build
Traceback (most recent call last):
  File "", line 56, in <module>
    app = MyApp()
  File "", line 39, in __init__
AssertionError: _has_mouse at line 65 of c:\buildslave\release_sdk_win32\build\p

my Code:

from direct.showbase.ShowBase import ShowBase
from pandac.PandaModules import *
from sys import exit
from direct.interval.IntervalGlobal import *
class MyApp(ShowBase):
    def __init__(self):
        '''props = WindowProperties()
        self.guy = self.loader.loadModel("models/gadget")
        self.guy.setScale(1, 1, 1)
        self.guy.setPos(0, 3, 0)
        alight = AmbientLight('alight')
        alight.setColor(VBase4(0.1, 0.1, 0.1, 1))
        alnp = render.attachNewNode(alight)
        alnp.setPos(0, 0, 0)
        plight = PointLight('plight')
        plight.setColor(VBase4(0.5, 0.5, 0.5, 1))
        plnp = render.attachNewNode(plight)
        plnp.setPos(0, 0, 0)
        self.accept('w', self.EventKeyW)
        self.accept('w-repeat', self.EventKeyW)
        self.accept('s', self.EventKeyS)
        self.accept('s-repeat', self.EventKeyS)
        self.accept('escape', exit)
    def EventKeyW(self):
        self.guy.setPos(self.guy, 0, -0.05, 0)
    def EventKeyS(self):
        self.guy.setPos(self.guy, 0, 0.05, 0)

app = MyApp()

dont wonder, im new to Panda and Python :slight_smile:
hope you can help me.
if something important is missing tell me please.

sorry if this is the wrong forum, i didnt know where i could post.

You don’t post the code that is actually triggering the error, but I can tell you what the problem is. If you look at the stack trace, you can see this line:

  File "", line 39, in __init__

(This line doesn’t appear in the code you pasted, but this is the line that is triggering the error.)

The error means that you are querying the mouse’s position, but the mouse pointer isn’t over the window so the mouse position doesn’t exist.

To avoid this, check to see if base.mouseWatcherNode.hasMouse() is true before calling getMouseX() or getMouseY().


thx. youre right. i deleted the line to get it working :slight_smile:
but if i check base.mouseWatcherNode.hasMouse() = True i get nothing. i wanted to print the position just for tests. so, my 2. question is: how do ich perform a function every frame (or other intervals)? i do not understand how i get the intervals working.

But thx for your reply. helped me alot.

To perform an operation every frame, you need to use a task. See this section of the manual.


cool, thank you man.
Hopefully im getting it now :slight_smile:

Edit: another problem. how do i add Tasks to the tasklist? i copied taskMgr.add(task) from the manual, but taskMgr is not defined. how do i define the task manager?

taskMgr is defined when you open a window, for instance by calling ShowBase.init(self). If you need to use the taskMgr before then, you can import it explicitly with:

from direct.task.TaskManagerGlobal import taskMgr


Thanks again dwr :smiley:
now its working.
You guy(s) are really awesome :slight_smile:

So there is another Question: is there a possibility to set the mouse position?

Do you mean directly move the mouse pointer that the user controls? Yes and no. It’s technically possible to do this on Windows and Linux, using But this isn’t supported on OSX, for the very good reason that it’s usually a bad interface design if you do this. The user can become disoriented if you move the mouse pointer out from under him, so the operating system disallows it on Apple computers.

If all you want is to implement mouselook mode, which is often implemented by hiding the mouse pointer and constantly repositioning it to the center of the window, you can do this on all platforms (including OSX) by first putting the mouse in MRelative mode, a special mode for just this purpose that is supported on all platforms, including OSX. There are plenty of examples of this in the forums.

yes, i just wanted to center the mouse.
thanks again.