Keyboard events

Hello all,

I am designing a menu for my game. In my menu, I am implementing several options. The usual stuff, audio, video, and keyboard options.

However, I am trying to find a way to allow the user to modify the default keybindings for the game. So, basically, here is my question.

How do you record a keypress event? i.e., they press a button to change a specific keybinding and then the system will accept the next keypress as the new keybinding for the action.

So in the menu you would see something like this:

Forward = W (BUTTON HERE TO CHANGE BINDING)
Back = S (BUTTON HERE TO CHANGE BINDING)
Right = A (BUTTON HERE TO CHANGE BINDING)
Left = D (BUTTON HERE TO CHANGE BINDING)

So, if I press the button next to ‘Forward = W’, the system will listen for the next keyboard keypress. I have all the functions set up and ready to go, I just can’t figure out how to listen for any key press and record the button that was pressed. Any ideas? Thanks in advance for the help.

["Press any key" problem[solved])

I saw that post just a few minutes before you posted that. The thing that has me help up at the moment, is how I get the function that implements that piece of code to wait or continue listening until a keypress has occurred.

class buttonChange(DirectObject):
	def __init__(self, game):
		self.game = game
		button = base.buttonThrowers[0].node().setButtonDownEvent('button')
		print button

This is what I have now. I tried closing that in a while loop with no success. That actually forced the game to freeze. And the only reason I have it printing the contents of button is for debugging purposes and to see if the button is being recorded correctly.

Would this be a situation in which I would need to use the task manager to have it continually check until a key has been pressed?

Disregard my last post, I got it figured out. I will post the final code in just a bit after I polish it up just a bit. Thanks for the help.