saving mouse/joystick/button presses


Is there a way to save out the mouse movements? Let’s say I have a figure on screen and I’m moving the eyes via the mouse. Is there a way to save out the mous X,Y coordinates?

Also, would saving out be set relative to a time increment so you’d still get the same mouse actions that you could replay?



Not sure exactly what you’re asking for. You can write a Python task that queries base.mouseWatcherNode.getMouse() each frame and stores that information somewhere. There is a fair amount of discussion about this sort of thing in other threads; search the forums.

You might also try Panda’s built-in recorder system, though to be honest I’m not sure if it still works well–it’s been a few revisions of Panda since it was last exercised. But to use it, you would put:


in your Config.prc to record a session, and then play it back later by removing that line and putting:




Panda’s built in recorder seemed to work, but it’s in binary and I want to get the info out in ASCII so I can take it back into Maya.

I basically want someone to play a short game, the game would save a file with all the mouse movements, keystrokes, etc. in it. Then have another person do the same. Bring the information into Maya and write a .mel script to put the right variables to the right rotations at the right time. I can then compare play styles, times, etc. for multiple people and see it all visually.

Before posting I searched and after your response as well, but I couldn’t find anything to give the search engine to bring up anything related to saving out mouse coordinates. Could you point we to some better keywords?

I’ve also tried file.write, but it seem to not like it when I try to pass a variable to it instead of straight text.



OK, write your task to get the mouse position each frame (along with a time stamp, if you like) and format it into a string using standard Python syntax, like this:

file = open('myDataFile.txt')

def getMouseData(task):
  if base.mouseWatcherNode.hasMouse():
    pos = base.mouseWatcherNode.getMouse()
    file.write('%s %s %s\n'  % (pos[0], pos[1], globalClock.getFrameTime())
  return Task.cont