0

I have a simple python program that responds to keyboard presses using the package keyboard:

import keyboard
import time

def catch_key( event ):
    print( "Key pressed:" + event.name )

def propel():

    keyboard.hook( catch_key )

    is_running = True
    while is_running:

        # press the 'escape' key to quit
        if keyboard.is_pressed('escape'):
            is_running = False

        time.sleep(0.05)

if __name__ == "__main__":
    propel()

This works fine using the USB keyboard plugged directly into the PI. However, when I use VNC Viewer (from RealVNC) the remote keyboard does not trigger anything. Any thoughts?

The keyboard package needs to be run with sudo to "capture" the keyboard. All keyboard input, regardless of what has focus, triggers the code.

In all other respects the remote keyboard works completely fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.