Ren'Py unable to get keyboard-focus on imagebutton

f95zoneuser463

Member
Game Developer
Aug 14, 2017
219
1,024
Why can I not focus that one imagebutton marked in red with arrowkeys?
Try it!
keyboardfocus.png
One would assume that Ren'Py can handle this simple task ... :mad:
I came across this while testing my game only with keyboard controls to make sure it would work fine with keyboard or gamepad only.

Code:
screen keyboard_focus_problem():
    tag hud

    imagebutton:
        auto "gui/wheel%s.png"
        pos(1285,258)
        action NullAction()

    imagebutton:
        auto "gui/wheel%s.png"
        pos(48,258)
        action NullAction()

    imagebutton:
        auto "gui/wheel%s.png"
        pos(1713,803)
        action NullAction()

    imagebutton:
        auto "gui/wheel%s.png"
        pos(68,928)
        action NullAction()

    imagebutton:
        auto "gui/wheel%s.png"
        pos(880,180)
        action NullAction()

    ## this button can not be keyboard focused
    image Solid("#800", xpos=368-32, ypos=368-32, xsize=128, ysize=128)
    imagebutton:
        auto "gui/wheel%s.png"
        pos(368,368)
        action NullAction()
    
    imagebutton:
        auto "gui/wheel%s.png"
        pos(1602,683)
        action NullAction()

label start:
    scene black
    ## not allowed to be re-enable this!
    $ quick_menu = False
    "Why is it not possible to focus that one imagebutton with arrowkeys on the following screen?"
    "You are {color=#F00}not{/color} allowed to move them!"
    "You are {color=#F00}not{/color} allowed to add additional elements that can be keyboard-focused!"
label loop:
    show screen keyboard_focus_problem
    pause
    jump loop
Problem simplified into a test project:


I've already had another example for this problem ... solved it by moving the imagebutton. But I cannot move this one!
 
  • Like
Reactions: Palanto

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,978
16,236
Trying your test project I have this :

right key: The red imagebutton is never reached, as well as the one just after it and the one on the bottom right corner.
left key: Only the three imagebutton in the bottom part can be selected.
up key: Only the ones on the left side can be selected, except the bogus one.
down key: All can be selected except the bogus one and the one on the top left side.

So, yes, the one you point is clearly in a bogus state and never can be selected. But I'm more concerned by the fact that there isn't a situation where you can circle through all by using a single key. And that is an issue with Ren'py itself. The way it deal with focus here is just insane. What works in one way (left key by example) must works backside when you use the opposite key ! And it's not the case.

It become even more insane when you change a little your screen :
Code:
screen keyboard_focus_problem():
    tag hud

    default idx = 0
    text "[idx]"

    imagebutton:
        auto "gui/wheel%s.png"
        pos(1285,258)
        action NullAction()
        hovered SetScreenVariable( "idx", 1 )
Continue adding the "hovered" by increasing the number each time. Then you get :
left key: 2 1 7 3
right key: 3 7 4
up key: 4 2 5
down key: 5 1 7 3 4

There a full lack of logic here since it's neither based on the order of the imagebutton on the screen, nor on the order of their declaration.

And finally it become even more insane when you don't do a full circle. Use the down key to go to "3". Then use the up key... You'll go in reverse order of the down key until you reach the moment when nothing is selected, then you go through the usual 4 2 5 order.

For me, it's not your screen which is in cause, but Ren'py itself. The whole part regarding focus change with arrow key is broke.
 

f95zoneuser463

Member
Game Developer
Aug 14, 2017
219
1,024
Thanks for testing and confirming this.

I guess I have to report it as bug on Github then. I just don't want to be to fast with these kind of things ... the first time I did that it just turned out I was to stupid to read and understand the Ren'Py documentation.

In the docs the only relevant thing about keyboard controls for this is:

That is 'True' by default. I even tried to set this to 'True' manually for the buggy imagebutton. I did set this to 'False' for some other UI elements in my game. This makes playing with keyboard better because when a choice menu pops up the arrowkeys can focus the choices instantly (instead of focusing the UI stuff like questtracker or other buttons).

In the end this seems to be a lost cause, Ren'Py seems to be more optimized for "pointing devices" and PyTom already said that 7.1 will focus on Android ... *meh* ... I have no hope this will get fixed.
 
  • Like
Reactions: Palanto

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,978
16,236
I guess I have to report it as bug on Github then. I just don't want to be to fast with these kind of things ... the first time I did that it just turned out I was to stupid to read and understand the Ren'Py documentation.
Personally I prefer to report problems directly on the official forum. Mister Rothamel use a little more diplomacy when answering there. And if it's only because of a misunderstanding, there will be people helping you to clarify the documentation.
The best way to do is probably using a title like "what am I missing ?" ; so starting with a premise that it's you and not Ren'py.


In the docs the only relevant thing about keyboard controls for this is:
You can also found something in the documentation, more precisely for it's arrowkeys property :
This takes precedence over the usual function of these keys, which is changing focus.
I haven't looked through the whole documentation, but it's the only significant thing found by Google with renpy arrow key, renpy change focus, or renpy keyboard focus. So I assume that those are the two only places in the documentation where it's said that you can change the focus by using the arrow keys.

By the way, looking about your problem, I found this . Following it, I added "default True" to your screen example. It change nothing at all, even if I add it to the bogus imagebutton. But I can have misunderstood its usage.