1import win32api
2import time
3
4width = win32api.GetSystemMetrics(0)
5height = win32api.GetSystemMetrics(1)
6midWidth = int((width + 1) / 2)
7midHeight = int((height + 1) / 2)
8
9state_left = win32api.GetKeyState(0x01) # Left button down = 0 or 1. Button up = -127 or -128
10while True:
11 a = win32api.GetKeyState(0x01)
12 if a != state_left: # Button state changed
13 state_left = a
14 print(a)
15 if a < 0:
16 print('Left Button Pressed')
17 else:
18 print('Left Button Released')
19 win32api.SetCursorPos((midWidth, midHeight))
20 time.sleep(0.001)