[python3.5] [Pyuserinput] simulating mouse and keyboard simulations

Source: Internet
Author: User

First, Pyuserinput installation

The python3.5 Pymouse and Pykeyboard modules are integrated into the Pyuserinput module. In python3.5, the Pyuserinput module can be installed directly

Installation of Pywin32 and Pyhook modules prior to pyuserinput module installation

PYWIN32 module is installed by default

The Pyhook module can be downloaded from here

http://www.lfd.uci.edu/~gohlke/pythonlibs/

Find a lot of Pyhook on the Python website is not available for python3.5 version

Pyuserinput Module

Https://github.com/PyUserInput/PyUserInput

Ii. Methods of Use

Import Module

Import Pymouse,pykeyboard,os,sys  from Import *fromimport Pykeyboard

Define an instance individually

m = Pymouse ()
K = Pykeyboard ()

Mouse Operation:

M.click (x,y,button,n) – Mouse click
x,y– is the coordinate position
Buttong–1 means left button, 2 means right click
n – Clicks, default is 1 times, 2 means double click

M.move (x, y) – Mouse moves to coordinates (x, y)

X_dim, Y_dim = M.screen_size () – Get screen size

Keyboard operation:

K.type_string (' Hello, world! ') – Analog keyboard input string
K.press_key (' h ') – Analog keyboard Press H key
K.release_key (' h ') – Analog keypad release H key
K.tap_key ("H") – Analog click H key
K.tap_key (' h ', n=2,interval=5) – Analog-click H-Key, 2 times, 5 seconds per interval
K.tap_key (K.function_keys[5]) – Click the function key F5
K.tap_key (k.numpad_keys[5],3) – Tap Numpad 5, 3 times

Joint key Simulation

For example, pressing ALT + TAB keyboard

K.press_key (K.alt_key) – Hold down the ALT key
K.tap_key (K.tab_key) – Click the TAB key
K.release_key (K.alt_key) – Release the ALT key

[python3.5] [Pyuserinput] simulating mouse and keyboard simulations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.