Ren'Py Renpy input on android always focused

yozayozo

Newbie
Sep 14, 2021
18
2
Hello. I'm building a custom screen that fires before maim menu. Everything is perfect except when the game is opened on android.

The input on the screen is always focused and the keyboard is always showing. The caret is always present in the input

If a user presses "enter" on the android keyboard, nothing happens and keyboard stays on the screen
If a user presses "back" button on android , the keyboard disappears and then re-appears in less than a second.

This behaviour is not good, but currently I don't know how to fix it.

Can anyone more experienced help?
Can the input be binded to the button on "enter" somehow?


This is my current code:

Code:
screen hhh(ffff):
    frame:
        align (0.5, 0.01)
        xpadding(10)
        ypadding(10)
        vbox:
            text"Welcome!"

    frame:
        align (0.5, 0.5)
        xpadding(10)
        ypadding(10)
        vbox:
            input default "":
                value VariableInputValue("ffff")
                copypaste True
                length 30
    frame:
        align (0.5, 0.6)
        xpadding(10)
        ypadding(10)
        vbox:
            textbutton "Enter!":
                action [Function(o)]
 
Last edited:

Playstorepers

Member
May 24, 2020
160
79
It's been over a year since I wrote this, but it should work:

EDIT: I scrapped that code from somewhere on the internet.
EDIT2: If that screen's happening in the splashscreen before the main menu, you can probably also return instead of jump at the confirmbutton.

basically you need the keysym and I'd recommend to move the input upwards on mobile, so the player can see what he types.

Python:
screen charactername:#Da screen to enter the name of the mc
    modal True
    frame:
        if renpy.variant("pc") or (renpy.variant("web") and not renpy.variant("mobile")):
            area(600, 300, 645, 360)
        else:
            area(600, 10, 645, 360) # needs to be higher, cuz android keyboard will overlap the textbox
        vbox: #now we want to do vbox to make the input below the textbox
            xalign 0.5
            yalign 0.5
            spacing 20
            text "What's your name, homie?": #we added text using this
                size 30 #in here you can edit the text with those: https://www.renpy.org/doc/html/style_properties.html#text-style-properties
                # at transform: #with this you can animate the text
                #     alpha 0 #here you type parameters which are used at first
                #     pause 0.5 #you can add a pause
                #     linear 2 alpha 1.0 #now you add how it's changed (I used linear but here are all: https://www.renpy.org/doc/html/atl.html#warpers) then the time of the animation and then to what it is changed

            input default "":#now we add input which will be below the text because it's in the vbox. In default you can type something that will be already typed when the screen will be shown
                size 40
                xalign 0.5
                pixel_width(430)#this to not allow too long name
                value VariableInputValue("playername")#with this you save the input to a variable.

            textbutton "Confirm":
                xalign 0.5
                action Jump("nextlabel")#in action you type what will happen, when you click ok
                keysym('K_RETURN', 'K_KP_ENTER') #you can also add keysym to activate it with a keyboard
 
  • Like
Reactions: yozayozo