[REOPEN] Prevent (text)button from being activated by enter

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Message
Author
User avatar
mobychan
Veteran
Posts: 275
Joined: Fri Apr 24, 2015 6:31 am
Projects: The Chosen - Sakura Pink & Gentian Blue
Organization: Foresoft
Location: Germany
Contact:

[REOPEN] Prevent (text)button from being activated by enter

#1 Post by mobychan »

Hey there^^

I made a screen for inputting the mcs name with a Random button.
Usual behavior is, the button is activated when it's focused(eg the mouse is above it) and you press enter.
I'd like the button to only react on clicks, and enter always confirming the input.

I tried something like this:

Code: Select all

    $ config.keymap["button_select"].remove('K_RETURN')
    $ config.keymap["button_select"].remove('K_KP_ENTER')

    call choose_first_name
    call choose_last_name
    
    $ config.keymap["button_select"].append('K_RETURN')
    $ config.keymap["button_select"].append('K_KP_ENTER')
But this deactivates buttons in the menu as well(and for some reason won't reactivate enter on buttons and, after working before, doesn't work anymore...)
I found the "keymap" property on buttons in the wiki, but looks like that isn't working anymore.

Any ideas?
Am I missing something?
Last edited by mobychan on Fri Aug 21, 2015 4:25 pm, edited 2 times in total.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Preventing (text)button from being activated with enter

#2 Post by trooper6 »

Keymap certainly still works, it is in the current documentation: http://www.renpy.org/doc/html/keymap.html
However...

This is what the documentation on config variables: http://www.renpy.org/doc/html/config.ht ... -variables
Ren'Py's implementation makes the assumption that, once the GUI system has initialized, configuration variables will not change. Changing configuration variables outside of init blocks can lead to undefined behavior. Configuration variables are not part of the save data.
So what you have won't work because config is only checked at init and not checked again. You can't change config variable outside of init.

So what do you do? I've been posting a lot about this recently .
You make a screen, and on that screen you use the key interface element to make the keymap what you want it to be. Then you show the screen for however long you want that keymap to be active and hide it when you don't.

So in your case.

Code: Select all

screen key_screen():
    key "K_RETURN" action NullAction()
    key "K_KP_ENTER" action NullAction()
Whenever this screen is being shown, the return key and the enter key will do nothing at all...which is what you were doing with your code.

Then you do:

Code: Select all

show key_screen()
call choose_first_name
call choose_last_name
hide key_screen
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
mobychan
Veteran
Posts: 275
Joined: Fri Apr 24, 2015 6:31 am
Projects: The Chosen - Sakura Pink & Gentian Blue
Organization: Foresoft
Location: Germany
Contact:

Re: Preventing (text)button from being activated with enter

#3 Post by mobychan »

I didn't think it would override it if I just placed a key element somewhere, interesting ^^

However, it won't work in my case I guess, since I still have the input I want to be confirmed with enter.
Is there a possibility to put the input's value into the _return value on that key action?

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Preventing (text)button from being activated with enter

#4 Post by trooper6 »

Maybe there is some other way to fix your problem if you share more information.

For example, why don't you want the player to be able to select a button with Return or Enter? What problems is that causing so that you want to disable that? Perhaps knowing the base problem might present a more appropriate answer?
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
mobychan
Veteran
Posts: 275
Joined: Fri Apr 24, 2015 6:31 am
Projects: The Chosen - Sakura Pink & Gentian Blue
Organization: Foresoft
Location: Germany
Contact:

Re: Preventing (text)button from being activated with enter

#5 Post by mobychan »

It's for a commission ^^''

The main problem is:
you click "Random" and a random name is inputted into the input, so the player can decide whether to keep it or not.
Then, without moving the mouse you want to accept the name it inputted, but as soon as you press enter, the random button is activated and the name is replaced.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Preventing (text)button from being activated with enter

#6 Post by trooper6 »

It is 4:47am and I have to go to bed!
But a question I have is -- do you ever need the return and enter keys to select buttons or would it be fine for that functionality to never be there?
If you are okay with that, then you could just add your old removal code:

Code: Select all

$ config.keymap["button_select"].remove('K_RETURN')
    $ config.keymap["button_select"].remove('K_KP_ENTER')
to the end of the options.rpy file. It'll get registered in init and then those two keys won't ever do that think you don't want them do to.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
mobychan
Veteran
Posts: 275
Joined: Fri Apr 24, 2015 6:31 am
Projects: The Chosen - Sakura Pink & Gentian Blue
Organization: Foresoft
Location: Germany
Contact:

Re: Preventing (text)button from being activated with enter

#7 Post by mobychan »

I'll ask my customer about it once more, thanks anyway ^^

User avatar
Kia
Eileen-Class Veteran
Posts: 1050
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: Preventing (text)button from being activated with enter

#8 Post by Kia »

I can think of few possible ways:
is there any clickable displayable we can use instead of button? something that can be clicked on and without K_RETURN attached to them? imagemaps hotspots might work.
can we set the focus by any means? I saw focus in buttons documentation somewhere.
or the tricky one: find a way to set back config.keymap['button_select'].append('K_RETURN') after the input. or not... nobody will miss that function for buttons unless they play with keyboard only :3

User avatar
mobychan
Veteran
Posts: 275
Joined: Fri Apr 24, 2015 6:31 am
Projects: The Chosen - Sakura Pink & Gentian Blue
Organization: Foresoft
Location: Germany
Contact:

Re: Preventing (text)button from being activated with enter

#9 Post by mobychan »

The hotspot part is actually quite a good idea, I guess I'll try that, thanks for the idea^^

DragoonHP
Miko-Class Veteran
Posts: 758
Joined: Tue Jun 22, 2010 12:54 am
Completed: Christmas
IRC Nick: DragoonHP
Location: Zion Island, Solario
Contact:

Re: Preventing (text)button from being activated with enter

#10 Post by DragoonHP »

If I'm understanding the question right, you just need to put keyboard_focus False under textbutton

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Preventing (text)button from being activated with enter

#11 Post by trooper6 »

DragoonHP wrote:If I'm understanding the question right, you just need to put keyboard_focus False under textbutton
Ooh! Great call!

Fully reading the documentation is always such a good idea. This is why I'm giving myself the challenge to go through everything bit by bit.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Kia
Eileen-Class Veteran
Posts: 1050
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: Preventing (text)button from being activated with enter

#12 Post by Kia »

DragoonHP wrote:If I'm understanding the question right, you just need to put keyboard_focus False under textbutton
I tested that before and the problem is: while mouse is still hovering the button the focus is on button by default and that's the problem mobychan is trying to solve.

DragoonHP
Miko-Class Veteran
Posts: 758
Joined: Tue Jun 22, 2010 12:54 am
Completed: Christmas
IRC Nick: DragoonHP
Location: Zion Island, Solario
Contact:

Re: Preventing (text)button from being activated with enter

#13 Post by DragoonHP »

Kia. Oh thanks.

@Moby: If you don't mind editing source file. Open renpy/display/behaviour.py, go to line 784 and add and not renpy.display.screen.get_screen("choose_first_name")

So it will look something like this:

Code: Select all

        if (self.clicked is not None) and map_event(ev, "button_select") and not renpy.display.screen.get_screen("choose_first_name"):
            return handle_click(self.clicked)

philat
Eileen-Class Veteran
Posts: 1925
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Preventing (text)button from being activated with enter

#14 Post by philat »

I haven't tried this, but wouldn't it be simpler to tweak trooper6's approach and stick a key statement into choose_first_name and choose_second_name? Something like:

Code: Select all

screen choose_first_name:
    # input code 
    # button code
    key "K_RETURN" action If(input_text, Return(), NullAction()) # assuming the name input_text, checks to see if input_text is not empty and then returns if yes, does nothing if no
Again, I haven't tried it, but seems like it should work conceptually.

User avatar
mobychan
Veteran
Posts: 275
Joined: Fri Apr 24, 2015 6:31 am
Projects: The Chosen - Sakura Pink & Gentian Blue
Organization: Foresoft
Location: Germany
Contact:

Re: Preventing (text)button from being activated with enter

#15 Post by mobychan »

DragoonHP wrote:If I'm understanding the question right, you just need to put keyboard_focus False under textbutton
Jup, that won't work, since my focus is from hovering with the mouse.

philat wrote:I haven't tried this, but wouldn't it be simpler to tweak trooper6's approach and stick a key statement into choose_first_name and choose_second_name? Something like:

Code: Select all

screen choose_first_name:
    # input code 
    # button code
    key "K_RETURN" action If(input_text, Return(), NullAction()) # assuming the name input_text, checks to see if input_text is not empty and then returns if yes, does nothing if no
Again, I haven't tried it, but seems like it should work conceptually.
So how do I get the input_text?
I couldn't find anything in the doc how to get it with

Code: Select all

input id "input_name":
    default first_name
    length 12

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], bonnie_641