I use Raspbian lite. I'm trying to map a hotkey to start the service or a script. I do not use a graphical user interface, only a text console with a local attached display. I'm not using ssh.

I tried using xbindkeys, but:

> xbindkeys -k
Could not open display, check shell DISPLAY variable, and export or setenv it!

How can I map a key to start a script?

  • Hi Pasha, Is this from a console/terminal, headless via ssh, or have you installed a gui on the Pi? – Danny Staple Oct 31 '18 at 20:30
  • Hi Danny! No gui, only console/terminal, locally without ssh. – Pasha Geronimo Nov 1 '18 at 7:42

You do not use a graphical user interface (GUI) so I guess you are using Raspbian Stretch Lite. With a default installation of it there is no xbindkeys installed for good reasons. With apt show xbindkeys you will find:

xbindkeys is a program that allows you to launch shell commands with your keyboard or your mouse under the X Window System.

The X Window System is the default GUI on Linux so it is unsurprising that xbindkeys complains it cannot find a DISPLAY for graphical output.

On the default bash shell you can use the builtin command bind. Look for help with help bind. I have found an answer at How to execute a script in shell when a shortcut key is pressed.

  • I tried BIND. He can not bind a button. Power button . maybe there are other ways? – Pasha Geronimo Nov 1 '18 at 19:22
  • @PashaGeronimo So far we only talked about keyboard keys as guessed when you talk about hotkey and xbindkeys. The power button is not a keyboard key so neither xbindkeys nor bind can manage it. What are you trying to do with the power button? Running a script before shutdown? – Ingo Nov 1 '18 at 19:31
  • Ingo, i use this remote link . It work like as keyboard. When i press Power nothing happens (linux not shutdown). I need to map Power some script to button Power. – Pasha Geronimo Nov 2 '18 at 8:41

Your Answer

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

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