0

i'm a PYQT freshman i'm using PYQT5 and Python3.x on raspberry pi 3

Update

sorry for previous question

The question is :

How can i know if the num lock is on? For simply, i want to :

  • print ("NumLock is ON") # if num lock is on without any key pressed before or using keypressevent.
  • else print("NumLock is OFF") # if numlock is off
Community
  • 1
  • 1

1 Answers1

0

You can write a function on your main form to catch all keypress events, and filter the numlock key, like this:

class Form(QDialog, Some_Form):
    ...
    def keyPressEvent(self, event):
        ''' Get key press event '''

        if event.key() == Qt.Key_NumLock:
            do_something()

Edit: As pointed out in a comment, this will not register a change if the window has no focus.

As far I can tell, pyqt has not a status function for numlock and capslock. Probably the best way to do it is implementing this if you are on linux, and this if you run windows.

Community
  • 1
  • 1
  • 1
    This won't catch key presses when the window does not have focus, so you will not keep track of the state correctly (nor does it tell you about the initial state) – three_pineapples Jun 23 '16 at 02:18
  • @three-pineapples i mean i want to detect the numlock indicator on the program begining without any keypressevent – Ceppy Nurul Huda Jun 26 '16 at 00:40