detect keyboard input?

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
D-R_aldi
Newbie
Posts: 4
Joined: Tue Sep 03, 2013 2:20 am
Location: Indonesia
Contact:

detect keyboard input?

#1 Post by D-R_aldi »

need some help.
can someone tell me how can we detect input from keyboard in renpy?

I mean, I want it so that when the user click some arrow [K_UP], [K_DOWN], [K_LEFT], [K_RIGHT],
then detect the input,
then do something, like move to the next scenery according with the key pressed.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
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: detect keyboard input?

#2 Post by PyTom »

You generally want a screen, with various key entries.

Code: Select all

screen keynav:
     key "K_UP" action Jump("up")
     key "K_DOWN" action Jump("down")
     # ... etc.
You can then show or call the screen, and it will listen for keys and jump where you want it to.
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

User avatar
D-R_aldi
Newbie
Posts: 4
Joined: Tue Sep 03, 2013 2:20 am
Location: Indonesia
Contact:

Re: detect keyboard input?

#3 Post by D-R_aldi »

Thanks PyTom... :D
it really helps.. :) :)

I'm still a noob after all :oops:

User avatar
PyTom
Ren'Py Creator
Posts: 16096
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: detect keyboard input?

#4 Post by PyTom »

D-R_aldi wrote:I'm still a noob after all :oops:
We all were, once, in most things.
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

Kinross07
Newbie
Posts: 7
Joined: Mon May 29, 2017 3:29 am
Contact:

Re: detect keyboard input?

#5 Post by Kinross07 »

I imagine this thread is fully dead, I don't know if something fundamental has changed in the last 3 years, but I get the following error:

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/input.rpy", line 27: u'jump' is not a keyword argument or valid child for the key statement.
    key  'K_RETURN' action jump("complete")
                               ^

Ren'Py Version: Ren'Py 6.99.12.4.2187

As it stands, it exists in this code:

Code: Select all

screen text_input_screen():

    default screenvar = True
    imagemap:
        ground "background.png"
        idle "idle.png"
        hover "hover.png"
        selected_idle "hover.png"

        hotspot (150,140,475,200) action SetScreenVariable("screenvar",True)
        hotspot (625,140,110,100) action [Hide("text_input_screen"),Jump("complete")]
        key  'K_RETURN' action jump("complete")
        if screenvar == True:
            
            input default firstname pos(200,165) changed name_func
            
I'm trying to make it so that rather than having to press an on-screen button, the user can just hit enter/return when they're done. On the off chance anyone sees this, any advice is greatly appreciated. And if you can explain why that's even better. Trying to reduce the amount of blind copying I do.

User avatar
Pyr0
Newbie
Posts: 20
Joined: Mon Aug 07, 2017 4:34 pm
Contact:

Re: detect keyboard input?

#6 Post by Pyr0 »

Kinross07 wrote: Tue Aug 08, 2017 2:45 pm I imagine this thread is fully dead, I don't know if something fundamental has changed in the last 3 years, but I get the following error:

Code: Select all

File "game/input.rpy", line 27: u'jump' is not a keyword argument or valid child for the key statement.
    key  'K_RETURN' action jump("complete")                              					
    						^
You ought to write Jump with a capital J. Simple typing errors are the most common in Ren'py so I suggest you always give a lot of attention to the error message (in this case it straight up tells you 'jump' is not a function that exists) and always double check what you type.

Kinross07
Newbie
Posts: 7
Joined: Mon May 29, 2017 3:29 am
Contact:

Re: detect keyboard input?

#7 Post by Kinross07 »

This is why it confused me, because when moving to labels and things, lower case jump is perfectly valid, so I didn't realise they were two separate things. Thank you though :)

Post Reply

Who is online

Users browsing this forum: Bing [Bot]