0

This question already has an answer here:

In my use-case, I want to plug in generic numpad to my PI and have it act as a remote. As such, I would like to redirect any keyboard input to an app of my choosing right after boot. The PI is headless so I do not care much of the app also has screen control or not.

What is the best method to achieve this?

marked as duplicate by goldilocks Nov 15 '16 at 19:38

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • I'm not sure what the problem is - a generic USB numpad should register as a keyboard. If your program's accepting inputs from the keyboard it should work with no action needed on your part. The exception to this would be something like this GPIO numpad, but it doesn't sound like that's what you're using. – goobering Nov 11 '16 at 13:56
  • @goobering - yes, that is not the issue - my issues is how to make the app running right after PI's boot that I can power it up headless and just have it react to keypresses – petr Nov 14 '16 at 9:32
  • The keyword you're looking for here is "kiosk". – Jacobm001 Nov 15 '16 at 17:23
1

Find out which terminal receives the input from your keypad, then use that device as an input for your app. If it's a script, do something like

read input_var < /dev/ttyX

In C, open it with fopen("/dev/ttyX", "r") and read with e.g. fscanf as you would with scanf in case of standard input. There will be similar functions available in other languages as well.

  • will try it out - just to clarify, would the login window capture the same keystrokes as well or would my app take over? I am planning to run it via cron after reboot. Alternatively, is there a way for the script to be ran automatically after boot up, including control of the screen contents? – petr Nov 11 '16 at 15:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.