simulate a keypress from python

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
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

simulate a keypress from python

#1 Post by Kia »

I'm trying to add a button to the overlay that mimics a keyboard key being pressed. for example when I press this button the interface under it does whatever happens when the "e" button is pressed.

all of the topics I've found searching were either very old using `ui.key` or where binding specific actions instead of a general keypress. is there a way to do it?

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2402
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: simulate a keypress from python

#2 Post by Ocelot »

I am not sure if pysdl used by RenPy exposes that, but you can try to use pygame interface for that:

Code: Select all

import pygame
key_event = pygame.event.Event(pygame.locals.KEYDOWN, unicode="e", key=pygame.locals.K_e, mod=pygame.locals.KMOD_NONE)
pygame.event.post(key_event)
https://www.pygame.org/docs/ref/event.html
< < insert Rick Cook quote here > >

Post Reply

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot]