Help defining keyboard input actions for imagebuttons

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.
Post Reply
Message
Author
HyDrone
Newbie
Posts: 12
Joined: Tue Apr 10, 2018 12:38 am
Contact:

Help defining keyboard input actions for imagebuttons

#1 Post by HyDrone »

Hi,

Is it possible to link imagebuttons to one another such that the user can switch focus between them using only the arrow keys? Here's what I have:

Code: Select all

if main_menu:
        imagebutton idle gui.start_comic_idle hover gui.start_comic_hover xpos 150 ypos 800 keyboard_focus True action Start()
        imagebutton idle gui.load_idle hover gui.load_hover xpos 130 ypos 900 keyboard_focus True action ShowMenu("load")
        imagebutton idle gui.help_idle hover gui.help_hover xpos 550 ypos 800 keyboard_focus True action Help()
        imagebutton idle gui.exit_idle hover gui.exit_hover xpos 530 ypos 900 keyboard_focus True action Quit()
The arrangement is:
Start Help
Load Quit

I have some experience with appending and removing to the keymap, but I don't know how to define the key behavior specifically for when these buttons are focused. Where should I look?

User avatar
Alex
Lemma-Class Veteran
Posts: 3098
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Help defining keyboard input actions for imagebuttons

#2 Post by Alex »

Isn't it the default behaviour? Ren'Py designed to be operated not only by mouse but by keyboard and joystick.
Check focus_up and focus_down in a keymap - https://www.renpy.org/doc/html/keymap.html#keymap

HyDrone
Newbie
Posts: 12
Joined: Tue Apr 10, 2018 12:38 am
Contact:

Re: Help defining keyboard input actions for imagebuttons

#3 Post by HyDrone »

It turns out left/right wasn't working because of the changes I made for the game controls:

Code: Select all

    $config.keymap['rollback'].append('K_LEFT')
    $config.keymap['dismiss'].append('K_RIGHT')
I disabled those and now left/right is fine. Is there a way to use those keymap edits just for in-game and not the menu?

Now it's all default and the vertical controls still aren't working.

User avatar
Alex
Lemma-Class Veteran
Posts: 3098
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Help defining keyboard input actions for imagebuttons

#4 Post by Alex »

Well, you can try to left the keymap unchanged (the default one), create a screen with changes for key actions, and show this screen at the very begining of the game.

Code: Select all

screen keys_change():
    key "K_LEFT" action Rollback()
    key "K_RIGHT" action Return()
https://www.renpy.org/doc/html/screen_a ... l#Rollback

Post Reply

Who is online

Users browsing this forum: Google [Bot]