#๐ Automation Program for a Minigame.
67 messages ยท Page 1 of 1 (latest)
@short knoll
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.
pyautogui is slow find other modules like keyboard winapi and PIL
!code
!paste
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.
``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)``
triple `
and add the py
Got it, thank you
also use !paste if it doesnt fit in a message
!paste
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.
all ur issues seem to be from delays so tweak those i guess?
How, exactly? Reduce or entirely remove the cpu delay?
reduce i think u can reduce the click delay
remove the cpu delay ur pc shouldnt give it all recources automatically
Alright, got it, I shall tweak it
and maybe u could try to multithread and search the next target while clicking the other
I remvoed the delays, it still doesn't work. https://paste.pythondiscord.com/4W5Q
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.
u either click too fast or didnt use win api correctly
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. ^^
add a small delay between left down and left up
Did that, still not working
I do not see a single click happening, this is mildly infruriating.
try to test the clicks alone in an other file
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. ^^
if not even pyautogui click idk what u can do
If you see this code, Pyautogui is used here for the mouse clicks, and it works.
The only thing remaining now is the keyboard bit
wich keyboard bit?
Pressing Q and E when detected
this code doesnt have that
also use keyboard.press for that or something simalar
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
Alr i shall try that
Colour detection is out of the way since Q and E in the minigame is just black and white, so they cannot be discerned
i thought u have to press the "Q" and "E" keys on the keyboard
Yes but the program has to press it, not human input
how exacly is that an issue than?
It isn't automating the keyboard.
Colour detection cannot be used for Keyboard pressess, so I have to find another way.
thats what the keyboard module is for
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.
oh is anything else black or white?
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.
i see u need to use some image recognition to differentiate them probably from witch all i know is u may need open cv
I have achieved automation for the mouse clicks, but not for the keyboard pressess.
I have opencv and I did use that as well
Even gave it a template which is just screenshot fo E and Q keys cropped
Doesn't seem to work.
u could use pyautogui.locate image
but its quite slow
Yeah pyautogui is too slow, I need realtime quick input
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.