Moving mouse cursor from external data

Hi guys,

I am collecting data (x,y) positions from an external computer vision program, and I am looking for an easy way to bring this data to panda. My aim for now is to use this data to move the mouse cursor.

I am exporting the data into a text file, and I would like to know, how can I open the file in panda, read the data and assign to the mouse cursor?

Unfortunately there is no example like this in the forums ( I wasnt expecting one!) so can somebody a bit more knowledgeable advice please?

Thanks!

If you actually want to move the mouse pointer, the little onscreen pointer that normally the user controls directly, you can do this with base.win.movePointer(x, y), where x and y are in the range -1 to 1 (not pixel values). There are plenty of examples for this in the forums; try searching for movePointer.

But I’d recommend against this. Better to control something onscreen that represents a mouse pointer, like a crosshairs or something that you attach to render2d. To do this, just do model.setPos(x, 0, y), where x and y are in the range 0 to 1. This is better because the mouse belongs to the user, and it’s rude to take control away from the user. In fact, Apple doesn’t even allow it because they consider it a poor user interface.

David

Hi David,

Thanks for your reply. I am actually using the base.mouseWatcherNode.getMouse, like the looking and gripping example. I will take your advice into consideration and try to use render2d. My question though concerned the next part.

Let me try to rephrase the problem. I have a text file with values taken from a computer vision system (this text file is being constantly updated with values) and I want to use this values to move the pointer.

How can I:

  1. open the text file in panda
  2. read the values
  3. assign this values to the mouse pointer? (either using render2d or base.win.movePointer(x,y)

I hope I am clear on what I mean. Thanks!

Doros

Sounds like you just want to use standard Python I/O calls, e.g.

file = open('data.txt', 'r')
for line in file.readlines():
  words = line.split()
  x = int(words[0])
  y = int(words[1])

or whatever is appropriate for the format in which your file is written. I suggest a Python tutorial, or the information on python.org, for more information about these calls.

David

Thanks David,

That is exactly what I want. I will follow your suggestion.

Just out of curiosity anyone here ever did a project using panda and a computer vision system?