2

I have a certain shell (zsh) script which reads one character at a time and performs an action afterwards. In the shell, this is realized by "read -k" in a loop. I want to execute the script as a keyboard shortcut, without opening a shell.

What is the easiest way to grab keyboard input for this? I could use dmenu if I wanted to read an entire string, but the script needs to be able to parse the characters one at a time.

Thanks.

0

(tried to post as a comment but I'm getting an error - will try as an answer)

When you say "execute from a shortcut" "without opening a shell", are you talking about in a graphical environment (X11) without opening a terminal emulator window?

The shell command read reads characters from the "standard input" character steam - not necessarily the keyboard.

A terminal emulator receives X11 keyboard events on its window, and maps to a character stream (which usually starts as standard input).

If you want use read but not a terminal emulator, you'll need something else to map some window's X11 keypress events to a character stream. (possibly the "root window")

Depending on what your script is doing with the characters, it may be easier to write a small graphical program.

| improve this answer | |
  • Yes exactly, but I was thinking that mabe there was an existing tool to do this for me (such as xdotool, but for input instead of output). – user247679 May 17 '14 at 6:43
0

xbindkeys can register for hot-keys in and execute whatever you want. This way you can have a key which activates your program and then do as you wish.

The thing to launch would be a terminal emulator with zsh running your script that directly does read -k. This way you don’t have to launch the terminal yourself. Please note that you can instruct the terminal to come up in any size you want (e.g. small).

Without activation key (or any other activation) it is unclear to me how you want to distinguish when normal keyboard input should go to your program or the other applications you might use.

| improve this answer | |

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.