Answers for "python keyboard mouse"

1

python move mouse

import mouse
# Number of pixels to move by on x and y axis
x = 1
y = 2
mouse.move(x, y)
Posted by: Guest on February-24-2020
0

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)  # Left button down = 0 or 1. Button up = -127 or -128
while True:
    a = win32api.GetKeyState(0x01)
    if a != state_left:  # Button state changed
        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)
Posted by: Guest on August-21-2020

Code answers related to "python keyboard mouse"

Python Answers by Framework

Browse Popular Code Answers by Language