Keybinding Syntax: K_UP + K_LEFT?

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
User avatar
noeinan
Eileen-Class Veteran
Posts: 1153
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: noeinan
Github: noeinan
Location: Washington State, USA
Contact:

Keybinding Syntax: K_UP + K_LEFT?

#1 Post by noeinan »

I'm making a simple overworld map for my game and I would like to allow diagonal movement instead of just up/down/left/right. I've got images for my character sprite to accommodate the diagonals, I just haven't found how to use multiple keys in a keybind, when the second key isn't shift/ctrl/alt.

Code: Select all

        key "K_UP" action [Function(cMap.moveDenizen, pc_sprite.x, pc_sprite.y, 0, -1), SetVariable("pc_dir", "back")]
        key "repeat_K_UP" action [Function(cMap.moveDenizen, pc_sprite.x, pc_sprite.y, 0, -1), SetVariable("pc_dir", "back")]

#        key "K_UP" action [Function(cMap.moveDenizen, pc_sprite.x, pc_sprite.y, -1, -1), SetVariable("pc_dir", "dback_left")]
#        key "repeat_K_UP" action [Function(cMap.moveDenizen, pc_sprite.x, pc_sprite.y, -1, -1), SetVariable("pc_dir", "dback_left")]

#        key "K_UP" action [Function(cMap.moveDenizen, pc_sprite.x, pc_sprite.y, 1, -1), SetVariable("pc_dir", "dback_right")]
#        key "repeat_K_UP" action [Function(cMap.moveDenizen, pc_sprite.x, pc_sprite.y, 1, -1), SetVariable("pc_dir", "dback_right")]

        key "K_DOWN" action [Function(cMap.moveDenizen, pc_sprite.x, pc_sprite.y, 0, 1), SetVariable("pc_dir", "front")]
        key "repeat_K_DOWN" action [Function(cMap.moveDenizen, pc_sprite.x, pc_sprite.y, 0, 1), SetVariable("pc_dir", "front")]

#        key "K_DOWN" action [Function(cMap.moveDenizen, pc_sprite.x, pc_sprite.y, -1, 1), SetVariable("pc_dir", "dfront_left")]
#        key "repeat_K_DOWN" action [Function(cMap.moveDenizen, pc_sprite.x, pc_sprite.y, -1, 1), SetVariable("pc_dir", "dfront_left")]

#        key "K_DOWN" action [Function(cMap.moveDenizen, pc_sprite.x, pc_sprite.y, 1, 1), SetVariable("pc_dir", "dfront_right")]
#        key "repeat_K_DOWN" action [Function(cMap.moveDenizen, pc_sprite.x, pc_sprite.y, 1, 1), SetVariable("pc_dir", "dfront_right")]
        
        key "K_LEFT" action [Function(cMap.moveDenizen, pc_sprite.x, pc_sprite.y, -1, 0), SetVariable("pc_dir", "left")]
        key "repeat_K_LEFT" action [Function(cMap.moveDenizen, pc_sprite.x, pc_sprite.y, -1, 0), SetVariable("pc_dir", "left")]

        key "K_RIGHT" action [Function(cMap.moveDenizen, pc_sprite.x, pc_sprite.y, 1, 0), SetVariable("pc_dir", "right")]
        key "repeat_K_RIGHT" action [Function(cMap.moveDenizen, pc_sprite.x, pc_sprite.y, 1, 0), SetVariable("pc_dir", "right")]

        key "K_RETURN" action Function(pcInteracts)
I've tried

Code: Select all

key "K_UP" and "K_LEFT" 
but that doesn't do anything.

Code: Select all

key ["K_UP", "K_LEFT"] 
errors out. I know for the default keymap there are lists like this

Code: Select all

rollback = [ 'K_PAGEUP', 'repeat_K_PAGEUP', 'K_AC_BACK', 'mousedown_4' ]
But that doesn't seem to apply to the key statement. (And those lists are alternates, not pressing both at the same time.) Anybody know the right syntax for this?
Image

Image
Image

User avatar
Andredron
Miko-Class Veteran
Posts: 718
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Re: Keybinding Syntax: K_UP + K_LEFT?

#2 Post by Andredron »

How to write a few letters per action. It is possible with shifta, viola, but with ctrl does not work. config.keymap = dict ( if shift screenshot = ['shift_B'] if alt screenshot = ['alt_B'] in keymap00 renpaya ctrl is used only here: skip = ['K_LCTRL', 'K_RCTRL'] ) Remove button value config.keymap ['function']. remove ('keyboard_key') Record button value config.keymap ['function']. append ('key combination')

User avatar
PyTom
Ren'Py Creator
Posts: 16093
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Keybinding Syntax: K_UP + K_LEFT?

#3 Post by PyTom »

Ren'Py's key input handling doesn't support multiple keys. You'd probably want to sue a CDD to keep track of what keys have been pressed down, and then do some kind of logic on it.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Post Reply

Who is online

Users browsing this forum: Andredron