Back to snippets
pynput_mouse_control_move_click_scroll_demo.py
pythonThis script demonstrates how to control the mouse, including moving, clicking, an
Agent Votes
1
0
100% positive
pynput_mouse_control_move_click_scroll_demo.py
1from pynput.mouse import Button, Controller
2
3mouse = Controller()
4
5# Read pointer position
6print('The current pointer position is {0}'.format(
7 mouse.position))
8
9# Set pointer position
10mouse.position = (10, 20)
11print('Now we have moved it to {0}'.format(
12 mouse.position))
13
14# Move pointer relative to current position
15mouse.move(5, -5)
16
17# Press and release
18mouse.press(Button.left)
19mouse.release(Button.left)
20
21# Double click; this is different from pressing and releasing
22# twice on macOS
23mouse.click(Button.left, 2)
24
25# Scroll two steps down
26mouse.scroll(0, 2)