#๐Ÿ”’ Automation Program for a Minigame.

67 messages ยท Page 1 of 1 (latest)

thin glacierBOT
#

@short knoll

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

valid furnace
#

pyautogui is slow find other modules like keyboard winapi and PIL

valid furnace
#

!code

thin glacierBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

valid furnace
#

!paste

thin glacierBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

short knoll
#

``win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
elif button == 'right':
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0)
time.sleep(0.1)
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0)

Continuously check for the prompts and perform actions

while True:
# Take a screenshot
screenshot = ImageGrab.grab()
screenshot = cv2.cvtColor(np.array(screenshot), cv2.COLOR_RGB2BGR)
screenshot_gray = cv2.cvtColor(screenshot, cv2.COLOR_BGR2GRAY)

# Match templates
for template, key in [(template_q, 'q'), (template_e, 'e'), (template_left_mouse, 'left'), (template_right_mouse, 'right')]:
    location, confidence = match_template(screenshot_gray, template)
    if confidence > 0.8:
        if is_inside_circle(location, key_circle_center, key_circle_radius):
            if key in ['q', 'e']:
                press_key(key)
                print(f"Pressed key: {key}")
        elif is_inside_circle(location, mouse_circle_center, mouse_circle_radius):
            if key in ['left', 'right']:
                click_mouse(button=key)
                print(f"Clicked mouse button: {key}")

# Delay to prevent overloading the CPU
time.sleep(0.01)``
short knoll
#

Got it, thank you

valid furnace
#

also use !paste if it doesnt fit in a message

short knoll
#

!paste

thin glacierBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

short knoll
#

There you go ^^

valid furnace
#

all ur issues seem to be from delays so tweak those i guess?

short knoll
#

How, exactly? Reduce or entirely remove the cpu delay?

valid furnace
#

remove the cpu delay ur pc shouldnt give it all recources automatically

short knoll
#

Alright, got it, I shall tweak it

valid furnace
#

and maybe u could try to multithread and search the next target while clicking the other

short knoll
#

How do I multithread? I haven't done that before.

#

Ah threading module, I'll search around.

#

Added threading as well, still doesn't work.

#

I can't seem to get it to click or press at all.

valid furnace
short knoll
#

I require the program to click and press without any input from me other than running the file, as for Win APi, I believe I used it correctly, I would appreciate if you could review it and give me your input. ^^

valid furnace
#

add a small delay between left down and left up

short knoll
#

Did that, still not working

#

I do not see a single click happening, this is mildly infruriating.

valid furnace
#

try to test the clicks alone in an other file

short knoll
#

The problem is that the program needs to identify which key/button to click and when.

#

@valid furnace Apparently someone else had a similar issue. This minigame is called a Rhythm game, and they too cannot seem to reach a conclusion.

#

@valid furnace https://paste.pythondiscord.com/UL6A

This is a working bit, using color principles for the mouse clicks. I still cannot get the key presses' to work though. Would appreciate a review. ^^

valid furnace
#

if not even pyautogui click idk what u can do

short knoll
#

The only thing remaining now is the keyboard bit

valid furnace
short knoll
#

Pressing Q and E when detected

valid furnace
#

also use keyboard.press for that or something simalar

short knoll
# valid furnace this code doesnt have that

Yes, I know, this one doesn't have that, but I just wanted to update you that the mouse bit is working, and wanted your input if such could be modified to incorporate keyboard press

short knoll
#

Colour detection is out of the way since Q and E in the minigame is just black and white, so they cannot be discerned

valid furnace
short knoll
valid furnace
short knoll
#

It isn't automating the keyboard.

#

Colour detection cannot be used for Keyboard pressess, so I have to find another way.

valid furnace
#

thats what the keyboard module is for

short knoll
#

I think I should rephrase what I require

#

I require the program to automatically press Q or E, whichever is displayed on the minigame, when it pops up.

valid furnace
#

oh is anything else black or white?

short knoll
#

Let me send an image

#

The code I sent earlier works for mouse, since it uses color. Red for left mouse, Purple for right mouse.

#

E and Q, as you can see, are black and white.

valid furnace
#

i see u need to use some image recognition to differentiate them probably from witch all i know is u may need open cv

short knoll
#

I have achieved automation for the mouse clicks, but not for the keyboard pressess.

short knoll
#

Even gave it a template which is just screenshot fo E and Q keys cropped

#

Doesn't seem to work.

valid furnace
short knoll
#

Yeah pyautogui is too slow, I need realtime quick input

thin glacierBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.