Page 1 of 1

Insensitive menu options still selectable with keyboard

Posted: Thu Jul 15, 2021 11:58 pm
by minyan
Hello,

I'm using this code so that users can select menu choices with the number keys:

Code: Select all

for n, i in enumerate(items, 1): # n would be the number starting from 1
            if n<10:
                key str(n) action i.action

            textbutton str(n) + ". " + i.caption action i.action style "nvl_button"
It works fine, and the choices are displayed like:

1. Choice 1
2. Choice 2

Users can choose by pressing 1 or 2 on the keyboard.

However, if an option is insensitive, for example:

menu:
"choice 1" if stat > 0:
pass
"choice 2":
pass

In the case that the variable "stat" was at 0, they will be able to see that menu option, but they can't choose it. With my code above, they can't click on it, but if they press 1 on the keyboard, it still lets them choose that option. Is there anyway to disable keyboard input for insensitive choices?

Re: Insensitive menu options still selectable with keyboard

Posted: Fri Jul 16, 2021 12:25 am
by hell_oh_world
a button has a keysym property, use that instead...
https://www.renpy.org/doc/html/screens.html#textbutton

Re: Insensitive menu options still selectable with keyboard

Posted: Fri Jul 16, 2021 11:57 am
by minyan
I’m sorry, I’m not familiar enough with that property to know how I’d change the code. Can you explain a little more?

Re: Insensitive menu options still selectable with keyboard

Posted: Fri Jul 16, 2021 11:57 am
by minyan
hell_oh_world wrote:
Fri Jul 16, 2021 12:25 am
a button has a keysym property, use that instead...
https://www.renpy.org/doc/html/screens.html#textbutton

I’m sorry, I’m not familiar enough with that property to know how I’d change the code. Can you explain a little more?

Re: Insensitive menu options still selectable with keyboard

Posted: Fri Jul 16, 2021 12:14 pm
by hell_oh_world

Code: Select all

for n, i in enumerate(items, 1): # n would be the number starting from 1
            textbutton str(n) + ". " + i.caption:
              action i.action
              style "nvl_button"
              keysym (str(n) if n < 10 else None) # works like the `key` displayable on screens...
            

Re: Insensitive menu options still selectable with keyboard

Posted: Fri Jul 16, 2021 12:27 pm
by vollschauer
remove that:

Code: Select all

key str(n) action i.action
add keysym to the textbutton, I think it is something like that .... you'll find out

Code: Select all

textbutton str(n) + ". " + i.caption action i.action keysym str(n) style "nvl_button"

Re: Insensitive menu options still selectable with keyboard

Posted: Fri Jul 16, 2021 10:25 pm
by minyan
hell_oh_world wrote:
Fri Jul 16, 2021 12:14 pm

Code: Select all

for n, i in enumerate(items, 1): # n would be the number starting from 1
            textbutton str(n) + ". " + i.caption:
              action i.action
              style "nvl_button"
              keysym (str(n) if n < 10 else None) # works like the `key` displayable on screens...
            
Thank you, this worked!

Re: Insensitive menu options still selectable with keyboard

Posted: Fri Jul 16, 2021 10:27 pm
by minyan
vollschauer wrote:
Fri Jul 16, 2021 12:27 pm
remove that:

Code: Select all

key str(n) action i.action
add keysym to the textbutton, I think it is something like that .... you'll find out

Code: Select all

textbutton str(n) + ". " + i.caption action i.action keysym str(n) style "nvl_button"
Thank you!