python-鼠标宏

按下鼠标左键, 连击

按下鼠标右键, 停止

import win32api
import time
from pynput.mouse import Button, Controller
mouse = Controller()

while True:

    if (win32api.GetAsyncKeyState(0x01)&0x8000 > 0):
        flag = True
        while flag == True:
               mouse.click(Button.left, 1)
               time.sleep(0.1)
               if (win32api.GetAsyncKeyState(0x02)&0x8000 > 0):
                   flag = False
    else:
        pass