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.


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

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( )

run( ) 

By the way. If you searched the forum a little you had come to this topic: … 227c7ed82b

thanks for your quick reply
It all works well now