could someone explain to me how keyboard/mouse input works?

Hi again, so I’ve been trying to figure out how to select certain objects with the mouse. My first assumption was that that panda used some kind of simple variables which came back as ‘True’ or ‘False’ depending on whether the designated button was pressed, however after doing some work on my own and perusing the forums here it appears that panda3d works differently than that. The online manual is a bit sparse when it comes to keyboard/mouse input, so I’m a bit confused as to how this works.

So can you guys help me out? for instance what modules need to be imported, and can you break down the code that gets entered to use it, I don’t remember the exact syntax, but from what I’ve seen I think it works something like this :

self.accept ([i]button pressed[/i], [i]resulting action[/i])

except that I"m not sure how this works if all I’m trying to do is change a value of a variable that determines if the status of an in game object is selected or not, since most of the resulting actions that I’ve seen seem to be something like moving or rotating an object.

Much thanks in advance.

Look at the Roaming Ralph sample for keyboard input and the Ball in Maze sample for mouse input. Both are included with the SDK.

I’m also somewhat of a newbie, but the way I worked keyboard input is as follows:


This will register a particular key event (The “event” parameter) (To use the key for the letter W, you would use “w” for the pressed down event, “w-up” for the released event or “w-repeat” for it to notify being held down for a duration) to be handled by a particular function (The HandlingFunction parameter), and it will supply whatever you put in the [“extra”] parameter to the handling function.

A basic key handling function:

def keyHandler(self,key):
    if(key == "keycode"):
        #Do something

The above code compares the [“extra”] parameter (in this function I’ve called it ‘key’) to different possible values and responds accordingly. I’ve set up all my key-registration calls to supply the event as the extra parameter:

self.accept("w", self.keyHandler, ["w"])
self.accept("w-up", self.keyHandler, ["w-up"])

Since the extra parameter can by anything you’d like, you could instead choose to have something along the lines of:

self.accept("w", self.keyHandler, ["Jim"])
self.accept("w-up", self.keyHandler, ["Joe"])

Assuming you could remember what “Jim” and “Joe” were used for.

I’m sure there’s a cleaner, simpler way to do this but I hope I’ve helped out somewhat in the meantime.

sorry bout the late response, but thanks, and yeah, the tutorial programs helped out, I just had to look deeper.