python click with mouse code example
Example 1: python click on screen
import pyautogui
pyautogui.click(100, 100)
pyautogui.moveTo(100, 150)
pyautogui.moveRel(0, 10)
pyautogui.dragTo(100, 150)
pyautogui.dragRel(0, 10)
Example 2: python code for on mouse click release
from pynput.mouse import Button, Controller
mouse = Controller()
print('The current pointer position is {0}'.format(
mouse.position))
mouse.position = (10, 20)
print('Now we have moved it to {0}'.format(
mouse.position))
mouse.move(5, -5)
mouse.press(Button.left)
mouse.release(Button.left)
mouse.click(Button.left, 2)
mouse.scroll(0, 2)
Example 3: python move mouse
import mouse
x = 1
y = 2
mouse.move(x, y)
Example 4: python mouse listener
import win32api
import time
width = win32api.GetSystemMetrics(0)
height = win32api.GetSystemMetrics(1)
midWidth = int((width + 1) / 2)
midHeight = int((height + 1) / 2)
state_left = win32api.GetKeyState(0x01)
while True:
a = win32api.GetKeyState(0x01)
if a != state_left:
state_left = a
print(a)
if a < 0:
print('Left Button Pressed')
else:
print('Left Button Released')
win32api.SetCursorPos((midWidth, midHeight))
time.sleep(0.001)