#coding=utf-8
from pymouse import PyMouse, PyMouseEvent
from pykeyboard import PyKeyboard, PyKeyboardEvent
import time, threading
import math
## 初始化参数区(全局变量)
stop = False
interval = 1
is_running = False
times = 10
keys_mapping = {
0 : [
'1'
,
'2'
,
'3'
,
'4'
],
10 : [
'a'
,
'b'
],
1 : [
'c'
,
'd'
],
11 : [
'e'
,
'f'
],
}
# 左上:0 右上:10 左下:1 右下:11
mouse = PyMouse()
keyboard = PyKeyboard()
x_dim, y_dim = mouse.screen_size()
## 循环按键
def loop(key):
global stop
global is_running
global keyboard
is_running = True
for
i
in
range(times):
for
k
in
keys_mapping[key]:
if
stop:
print(
'stop'
)
is_running = False
return
print(key, k)
#keyboard.tap_key(k)
time.sleep(interval)
is_running = False
## 监控鼠标
class Clickonacci(PyMouseEvent):
last_ts = None
last_x = None
last_y = None
last_button = None
def __init__(self):
PyMouseEvent.__init__(self)
## hori:1-上,-1-下
def scroll(self, x, y, hori, press):
print(x, y, hori)
def click(self, x, y, button, press):
if
press:
return
global stop
global x_dim
global y_dim
ts = time.time()
# button:1-左键,2-右键,3-中键
# press: True-按下,False-释放
if
button == 1:
## 判断双击
if
self.last_ts and ts-self.last_ts<0.3 and self.last_button==button:
print(
'double click'
)
if
is_running == True:
stop = True
time.sleep(interval)
stop = False
## 计算类型
key = 10*math.floor(2.0*x/x_dim) + math.floor(2.0*y/y_dim)
t = threading.Thread(target=loop, name=
'LoopThread'
, args=(key,))
t.start()
self.last_ts = ts
self.last_x = x
self.last_y = y
self.last_button = button
else
:
stop = True
if
__name__ ==
'__main__'
:
#main()
C = Clickonacci()
C.run()