[Solved] Screen Action for Left Click

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
SypherZent
Veteran
Posts: 368
Joined: Fri Sep 02, 2016 3:14 am
Completed: Multiverse Heroes, Space Hamster in Turmoil
Location: Puerto Rico
Contact:

[Solved] Screen Action for Left Click

#1 Post by SypherZent »

Hi,

I have a Point & Click segment in the game I am developing.
The Controller functions to move the mouse cursor.

I just need to make "pad_a_press" function exactly as a left click, so no matter where the cursor is on the screen, pressing the A button on Gamepad (and possibly other keys later) just causes the mouse to do a left click.

Anyone know of a simple way to do this?
Last edited by SypherZent on Fri Feb 24, 2023 7:43 am, edited 1 time in total.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3808
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Screen Action for Left Click

#2 Post by Imperf3kt »

I would simply place a button over the entire screen, usually by using the background as the button via an image button. Make sure its zorder is below that of other buttons and UI
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
SypherZent
Veteran
Posts: 368
Joined: Fri Sep 02, 2016 3:14 am
Completed: Multiverse Heroes, Space Hamster in Turmoil
Location: Puerto Rico
Contact:

Re: Screen Action for Left Click

#3 Post by SypherZent »

This is a Point & Click segment of gameplay. It has hidden buttons throughout the screen.
So, I don't need a button. I need to map a Screen Action to the A button on gamepad.

Code: Select all

key "pad_a_press" action ???
^ Like this.

I just can't find any Screen Actions in the Ren'Py documentation that function exactly like left clicking the mouse.

(Edit: When pressing "A" on Gamepad, I need the game to process where the Mouse Cursor is, detect if there are any buttons at those exact coordinates, just like Left Clicking would do. So, to simplify, I just want to map the exact functionality of a Mouse Left Click to the Gamepad A Button.)

I don't want to have to dig into PyGame documentation.
I'm hoping someone has an elegant solution.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3808
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Screen Action for Left Click

#4 Post by Imperf3kt »

Oh, sorry I misread.

You'll want to check out the keybinds
https://www.renpy.org/doc/html/keymap.html
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
SypherZent
Veteran
Posts: 368
Joined: Fri Sep 02, 2016 3:14 am
Completed: Multiverse Heroes, Space Hamster in Turmoil
Location: Puerto Rico
Contact:

Re: Screen Action for Left Click

#5 Post by SypherZent »

Ren'Py natively has "button_select" keybind on both mouseup_1 and pad_a_press.
However, using pad_a_press is not causing a left-click at mouse coordinates.
Using pad_a_press is activating the first button on the screen.

If basic Ren'Py documentation worked, I would not be on these forums asking for a solution...

My question is simple:

How do I map the mouse's left click functionality to "pad_a_press" using a Screen Action (or using Function with a PyGame function)?

Edit: I found a solution, but I'm still interested in a Screen Action that can cause a Mouse Left Click at current mouse coordinates, if anybody knows how to do that, even if it's the Function() Screen Action using pygame.event.post or something similar, that would be appreciated.|

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

Re: Screen Action for Left Click

#6 Post by Alex »

SypherZent wrote: Fri Feb 24, 2023 7:25 am Ren'Py natively has "button_select" keybind on both mouseup_1 and pad_a_press.
However, using pad_a_press is not causing a left-click at mouse coordinates.
Using pad_a_press is activating the first button on the screen.

If basic Ren'Py documentation worked, I would not be on these forums asking for a solution...

My question is simple:

How do I map the mouse's left click functionality to "pad_a_press" using a Screen Action (or using Function with a PyGame function)?

Edit: I found a solution, but I'm still interested in a Screen Action that can cause a Mouse Left Click at current mouse coordinates, if anybody knows how to do that, even if it's the Function() Screen Action using pygame.event.post or something similar, that would be appreciated.|
Might be wrong, but I think that left click is evaluated on button's side. Like if mouse pointer is over the button or not the button's action will be executed or not. So, there is no left click action. You still can use a function that checks the mouse pointer pos and do stuff according to this as an action (like you did for 'a' key).

User avatar
SypherZent
Veteran
Posts: 368
Joined: Fri Sep 02, 2016 3:14 am
Completed: Multiverse Heroes, Space Hamster in Turmoil
Location: Puerto Rico
Contact:

Re: [Solved] Screen Action for Left Click

#7 Post by SypherZent »

Thanks Alex, I thought about doing it based on positions like you mentioned. It would have been a last resort, but since it would take longer to code that I was looking for a simpler solution. It makes sense that there is no left click action for the reason you mentioned, too. That clarifies things.

Seems the problem I had was a button being focused, so it was a simpler solution than I originally anticipated.

Post Reply

Who is online

Users browsing this forum: No registered users