-
pyHook3
安装命令 :pip install pyhook3
https://blog.csdn.net/q871063970/article/details/86648386
似乎将pyhook支持py3版本的了? 没有太多研究.
缺点: 只支持win平台.
2.keyboard
& mouse
安装命令: pip install keyboard mouse
from PyQt5 import QtGui, QtWidgets, QtCore
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import keyboard
class Window(QWidget):
def __init__(self, *args, **kwargs):
super(Window, self).__init__(*args, **kwargs)
layout = QVBoxLayout(self)
self.testBtn = QPushButton(self)
layout.addWidget(self.testBtn)
keyboard.add_hotkey('ctrl+shift+x', lambda:print('triggered', 'hotkey'))
keyboard.add_hotkey('ctrl+shift+c', self.abc,args=('aa',"bb","cc"))
def abc(self,a,b,c):
print(a,b,c)
if __name__ == '__main__':
import sys
from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv)
w = Window()
w.show()
sys.exit(app.exec_())
更详细例子 : pyqt中使用keyboard全局热键
优点: 跨平台 ;
缺点: 模块名字取得太差, 不容易被发现.