You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
916 B
Python
52 lines
916 B
Python
4 months ago
|
from win32api import GetKeyState
|
||
|
from pynput.mouse import Listener
|
||
|
from pynput.keyboard import Key, Controller
|
||
|
import time
|
||
|
|
||
|
# 键盘控制控件
|
||
|
ctr = Controller()
|
||
|
|
||
|
|
||
|
def key_up(key, t=0.1):
|
||
|
# 按下按键
|
||
|
ctr.press(key)
|
||
|
time.sleep(t)
|
||
|
|
||
|
|
||
|
def key_down(key, t=0.1):
|
||
|
# 松开按键
|
||
|
ctr.release(key)
|
||
|
time.sleep(t)
|
||
|
|
||
|
|
||
|
def is_caps():
|
||
|
# 监听大小写
|
||
|
return GetKeyState(20)
|
||
|
|
||
|
|
||
|
def on_scroll(x, y, dx, dy):
|
||
|
# 监听鼠标滚轮, 并检测大小写
|
||
|
# print('Scrolled {0}'.format((x, y)))
|
||
|
if dy == 1:
|
||
|
print("关掉大写")
|
||
|
if is_caps():
|
||
|
key_up(Key.caps_lock)
|
||
|
key_down(Key.caps_lock)
|
||
|
|
||
|
elif dy == -1:
|
||
|
print("开启大写")
|
||
|
if not is_caps():
|
||
|
key_up(Key.caps_lock)
|
||
|
key_down(Key.caps_lock)
|
||
|
|
||
|
|
||
|
# 连接事件以及释放
|
||
|
with Listener(on_scroll=on_scroll) as listener:
|
||
|
listener.join()
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|