LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How can I trap the TAB key in a read (https://www.linuxquestions.org/questions/linux-newbie-8/how-can-i-trap-the-tab-key-in-a-read-4175487399/)

rrainbolt 12-09-2013 01:38 PM

How can I trap the TAB key in a read
 
if I have a simple form, let's say

NAME:
ADDRESS:
CITY:
ZIP:

and I want to
tput cup 0 6; read name

I want to be able to detect that the user either hit enter OR tabs down to the next field, (not just a tab to the right)

So basically I need to know the user hit tab and then place the cursor on the next field ready for more input, in this case:

tput cup 1 9; read address.

this is just a simple example, my actual need is on a more complex customer entry form so I don't want to echo a new line of info after each "enter"

jpollard 12-09-2013 04:26 PM

You can always set the tab key to be a break character and catch that. See the manpage on stty for that.

It has been over 20 years since I've done stuff like that, but you can go through the terminfo database table on what characters do what... (both input and output).

For bash you can look into the READLINE builtin - it allows an Emacs-style notation to denote keystrokes and you should be able to use that for catching anything else you may want to do.


All times are GMT -5. The time now is 09:16 AM.