I want to change this Hold button code to Toggle and I don't know how.
while True:
if win32api.GetAsyncKeyState(0x02) < 0:
img = np.array(sct.grab(boyutlar))
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(hsv, lower,upper)
kernel = np.ones((3,3), np.uint8)
dilated = cv2.dilate(mask,kernel,iterations= 5)
thresh = cv2.threshold(dilated, 60, 255, cv2.THRESH_BINARY)[1]
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
if len(contours) != 0:
M = cv2.moments(thresh)
cX = int(M["m10"] / M["m00"])
cY = int(M["m01"] / M["m00"]) / 1.228
x = -(mid - cX-2) if cX < mid else cX - mid*0.9
y = -(mid - cY) if cY < mid else cY - mid
x2 = x *xspd
y2 = y *yspd
mousemove(x2,y2)