Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pyqt global hotkey

import sys

from PyQt5 import QtCore, QtWidgets

from pynput.keyboard import Key, Listener, KeyCode


class KeyMonitor(QtCore.QObject):
    keyPressed = QtCore.pyqtSignal(KeyCode)

    def __init__(self, parent=None):
        super().__init__(parent)
        self.listener = Listener(on_release=self.on_release)

    def on_release(self, key):
        self.keyPressed.emit(key)

    def stop_monitoring(self):
        self.listener.stop()

    def start_monitoring(self):
        self.listener.start()


class MainWindow(QtWidgets.QWidget):
    pass


if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)

    monitor = KeyMonitor()
    monitor.keyPressed.connect(print)
    monitor.start_monitoring()

    window = MainWindow()
    window.show()

    sys.exit(app.exec_())
Comment

PREVIOUS NEXT
Code Example
Python :: python create named timer 
Python :: faceModel = "opencv_face_detector_uint8.pb" 
Python :: sorted string dict approach 
Python :: stop level of the broker 
Python :: Combining functions 
Python :: meter replacement application 
Python :: django updateview not saving 
Python :: python to uml 
Python :: python create empty list with size 10 
Python :: automate ms word with python 
Python :: install python 3.10 pip 
Python :: how to write together string type value and int type value in print function in python 
Python :: Python NumPy broadcast_arrays() Function Syntax 
Python :: Python NumPy ravel function example array.ravel is equivalent to reshape(-1, order=order) 
Python :: python f strings 
Python :: Python NumPy asarray Function Example list to array 
Python :: Python NumPy vstack Function Example with 1d array 
Python :: python locateonscreen method 
Python :: mid point line drawing 
Python :: Python __le__ magic method 
Python :: selenium rotate user agent 
Python :: NumPy right_shift Syntax 
Python :: ttk.frame 
Python :: adjoint of 3x3 matrix in numpy 
Python :: extract numbers from image python 
Python :: python tkinter.ttk combobox down event on mouseclick 
Python :: preallocate numpy array 
Python :: multiply each element by x in python 
Python :: python pyramid pattern 
Python :: edgar python documentation 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =