-
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全局熱鍵
優(yōu)點: 跨平臺 ;
缺點: 模塊名字取得太差, 不容易被發(fā)現(xiàn).