用到的模块
pyHook
pyUserInput
win32gui
win32api
win32con
subprocess
pyUserInput的文档使用
点击打开链接
win32gui method
点击打开链接
下面这个安装方法是对的!!不要再装什么其他的pymouse了!!!安装了pyuserinput后,pymouse就在啦!!!!!
__________________________________________________________________
一、PyUserInput安装
python3.5的PyMouse和PyKeyboard模块都集成到了PyUserInput模块中。在python3.5中,直接安装PyUserInput模块即可
PyUserInput模块安装前需要安装pywin32和pyHook模块
pywin32模块默认已安装
pyHook模块可从这里下载
http://www.lfd.uci.edu/~gohlke/pythonlibs/
//在Python官网找了很多个pyHook都不适用于python3.5版本
PyUserInput模块
https://github.com/PyUserInput/PyUserInput
二、使用方法
//导入模块
import pymouse,pykeyboard,os,sys
from pymouse import *
from pykeyboard import PyKeyboard
1
2
3
1
2
3
//分别定义一个实例
m = PyMouse()
k = PyKeyboard()
鼠标操作:
# import the module
from pymouse import PyMouse
# instantiate an mouse object
m = PyMouse()
# move the mouse to int x and int y (these are absolute positions)
m.move(200, 200)
# click works about the same, except for int button possible values are 1: left, 2: right, 3: middle
m.click(500, 300, 1)
# get the screen size
m.screen_size()
# (1024, 768)
# get the mouse position
m.position()
# (500, 300)
m.click(x,y,button,n) –鼠标点击
x,y –是坐标位置
buttong –1表示左键,2表示点击右键
n –点击次数,默认是1次,2表示双击
m.move(x,y) –鼠标移动到坐标(x,y)
x_dim, y_dim = m.screen_size() –获得屏幕尺寸
键盘操作:
k.type_string(‘Hello, World!’) –模拟键盘输入字符串
k.press_key(‘H’) –模拟键盘按H键
k.release_key(‘H’) –模拟键盘松开H键
k.tap_key(“H”) –模拟点击H键
k.tap_key(‘H’,n=2,interval=5) –模拟点击H键,2次,每次间隔5秒
k.tap_key(k.function_keys[5]) –点击功能键F5
k.tap_key(k.numpad_keys[5],3) –点击小键盘5,3次
联合按键模拟
例如同时按alt+tab键盘
k.press_key(k.alt_key) –按住alt键
k.tap_key(k.tab_key) –点击tab键
k.release_key(k.alt_key) –松开alt键
___________________________________________
keycode对照表
keycode 8 = BackSpace 回格keycode 9 = Tabkeycode 12 = Clearkeycode 13 = Enter 回车keycode 16 = Shift_Lkeycode 17 = Control_Lkeycode 18 = Alt_Lkeycode 19 = Pausekeycode 20 = Caps_Lockkeycode 27 = Escapekeycode 32 = spacekeycode 33 = Priorkeycode 34 = Nextkeycode 35 = Endkeycode 36 = Homekeycode 37 = Leftkeycode 38 = Upkeycode 39 = Rightkeycode 40 = Downkeycode 41 = Selectkeycode 42 = Printkeycode 43 = Executekeycode 45 = Insertkeycode 46 = Deletekeycode 47 = Helpkeycode 48 = 0 equal bracerightkeycode 49 = 1 exclam onesuperiorkeycode 50 = 2 quotedbl twosuperiorkeycode 51 = 3 section threesuperiorkeycode 52 = 4 dollarkeycode 53 = 5 percentkeycode 54 = 6 ampersandkeycode 55 = 7 slash braceleftkeycode 56 = 8 parenleft bracketleftkeycode 57 = 9 parenright bracketrightkeycode 65 = a Akeycode 66 = b Bkeycode 67 = c Ckeycode 68 = d Dkeycode 69 = e E EuroSignkeycode 70 = f Fkeycode 71 = g Gkeycode 72 = h Hkeycode 73 = i Ikeycode 74 = j Jkeycode 75 = k Kkeycode 76 = l Lkeycode 77 = m M mukeycode 78 = n Nkeycode 79 = o Okeycode 80 = p Pkeycode 81 = q Q atkeycode 82 = r Rkeycode 83 = s Skeycode 84 = t Tkeycode 85 = u Ukeycode 86 = v Vkeycode 87 = w W