linuxraspberry-pikeyboardsystemdrc

Raspberry Pi: Keyboard input for bash script without connected HDMI display


I'm searching for a possibility to control a bash script by keyboard without having a HDMI display connected.

Background: I want to build a vfd display that can be controlled by a usual keyboard. For this I connected the display with a raspberry pi. The vfd display will be controlled by the serial interface and this is already working.

The script: Key presses will be recognized by a endless loop and read -r -N 1 -p "" -d "" _KEY inside. The script basically works. When I start the script with HDMI display and mouse connected, I can use the keyboard. When I start the script by SSH, the connected computer can control the script but the raspberry pi connected keyboard is not working.

What I already tried:

try issue
Run script as systemd service Script starts but receives constantly a lot of inputs without pressing a key. The input cannot be interpreted. Key presses will not be recognized. Is there a possibility to recognize the keyboard input in the service configuration? Already tried to configure tty but no tty device for the keyboard is available.
Run script in rc.local / .bashrc Script starts but keypresses will not be recognized. This seems not to be a good solution with a endless loop in rc.local, right?

Output lsusb:

Bus 001 Device 005: ID 05af:8277 Jing-Mold Enterprise Co., Ltd USB Keyboard
...

Do you have any idea to control the script with the keyboard? Thanks for help!


Solution

  • I don't think it's nice, but the following solution works for me:

    1. Add the script to the .bashrc of user
    2. Configure auto login for the user: sudo raspi-config -> 1 System Options -> S5 Boot / Auto Login -> Select Option B2 Console Autologin -> Select Finish and reboot