I'm pretty new to Python and I'd like to make a kind of an Autoclicker, which keeps clicking every 0.1 seconds when my left mouse button is held down. My Problem is, that when I run my script, my mouse instantly starts clicking. What should I do?:
import win32api
import time
from pynput.mouse import Button, Controller
mouse = Controller()
while True:
if win32api.GetAsyncKeyState(0x01):
mouse.click(Button.left, 1)
time.sleep(0.1)
else:
pass
Thanks
My Problem is, that when I run my script, my mouse instantly starts clicking. What should I do?
You should use
win32api.GetAsyncKeyState(0x01)&0x8000instead.Now, the only thing it does is click once, which makes my click a double click.
Because
GetAsyncKeyStatedetects the key state of the left mouse button. When you press the left mouse button, theclickfunction is called,clickwill realize the two actions of the left mouse button press and release. Then in the place of thewhileloop,GetAsyncKeyStatewill detect the release action, which is why it stops after double-clicking.I suggest you set the left mouse button to start and the right mouse button to stop.
Code Sample: