Page 1 of 1

Menus: Listen to button '0' or '10'

Posted: Sat May 14, 2016 11:56 pm
by BackRaw
Hi,

I hope this hasn't been asked before. I'm trying to listen to whenever a player presses the '0' or '10' key on the keyboard to close a menu. I want to save previous changes the player made in other menus when the main menu has been closed (either option '4' - currently my manual method - or '0').

Is something like this possible?

Syntax: Select all

def my_callback(menu, index, option):
if option is None: # <--- check for 0
print('0 has been pressed')

menu = SimpleMenu(select_callback=my_callback)
menu.append(SimpleOption(4, 'test', 'test'))
# some more options

menu.send(1) # assuming this index exists


Thanks!


Edit: I'm assuming my_callback doesn't even get called when 0 is pressed. But that's just a thought. :D

Re: Menus: Listen to button '0' or '10'

Posted: Sun May 15, 2016 9:08 am
by iPlayer
Already been asked here

You're right, the callback doesn't get called when menu is closed. This can be changed though, by subclassing SimpleRadioMenu.

Re: Menus: Listen to button '0' or '10'

Posted: Sun May 15, 2016 11:10 pm
by BackRaw
Thanks!