from pykeyboard import *
from pymouse import *
import win32api
# 键盘鼠标事件
m=PyMouse()
k=PyKeyboard()
#m.click(1157,470)
#k.type_string('123456')
#k.tap_key(k.enter_key)
#k.type_string('ABCHD')
#k.tap_key(k.enter_key)
# y 为左上角往下 x为左上角往右
# m.click(200,30,1,2)
x_dim, y_dim = m.screen_size()
print ('screen_size',x_dim,y_dim)
#
'''
以上代码需要如下库支持
pip install PyUserInput
pip install pypiwin32 有m.click(x, y, button, n) -- 点击,想x,y坐标,button:1表示左键,2表示右键,n:默认1次,2双击
m.move(x, y) -- 鼠标移动
m.screen_size() -- 获取屏幕尺寸
· 键盘操作
k.type_string('abcdefg') --输入内容
k.press_key('a') --按a键
k.release_key('a') --松开a键
k.tap_key('a') --点击a键
k.tap_key('a', n=2, interval=5) --点击a键2次,每次间隔5秒
k.tap_key(k.function_keys[5]) --功能键F5
k.press_keys([k.alt_key, 'a']) --组合按键,试验不成功
————————————————
'''
'''
x_dim, y_dim = m.screen_size()
m.click(x_dim//2, y_dim//2, 1) #取整除 - 向下取接近除数的整数
k.type_string('Hello, World!')# pressing a key
k.press_key('H')
# which you then follow with a release of the key
k.release_key('H')
# or you can 'tap' a key which does both
k.tap_key('e')
# note that that tap_key does support a way of repeating keystrokes with a interval time between each
k.tap_key('l',n=2,interval=5)
# and you can send a string if needed too
k.type_string('o World!')
#Create an Alt+Tab combo
k.press_key(k.alt_key)
k.tap_key(k.tab_key)
k.release_key(k.alt_key)k.tap_key(k.function_keys[5]) # Tap F5
k.tap_key(k.numpad_keys['Home']) # Tap 'Home' on the numpad
k.tap_key(k.numpad_keys[5], n=3) # Tap 5 on the numpad, thrice# 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) PyMouse、PyKeyboard
用python操作鼠标和键盘的库,使用起来比较简单,需要结合具体的应用需求才能玩出新花样。