keyboard input keeps throwing errors.

i have been trying to implement keyboard control into my game but when i do, the error pops up “name ‘accept’ is not defined”.

This is how i wrote the fuction.

accept(‘arrow_left-repeat’,left_control)

where left_control is a function.

The documentation showed it as having a self attached to it but im not writing my code in object oriented fashion at the moment.

Please,if anyone could see what i have missed
thanks.

Normally you would use self.accept, if you have a class derived from DirectObject, since accept is a method of DirectObject.
If you don’t use classes, you can do it another way. Just make an instance of DirectObject:

import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject

def enterKey():
    print 'enter pressed!'
def spaceKey():
    print 'space pressed!'

o = DirectObject( )
o.accept('enter',enterKey)
o.accept('space',spaceKey)

run( ) 

By the way. If you searched the forum a little you had come to this topic:
discourse.panda3d.org/viewtopic.php … 227c7ed82b

thanks for your quick reply
It all works well now