Operating System - HP-UX
1833875 Members
1498 Online
110063 Solutions
New Discussion

How to identify keys for validations?

 
SOLVED
Go to solution
Chua Wen Ching
Regular Advisor

How to identify keys for validations?

I am using HP-UX 10.20. In order to do validations, how can i identify F1, F2, space bar, enter, backspace, ?, /, etc. Can it be represented by ASCII or hexadecimal? Any solutions for this. I need to do this so my system can handle exceptions. Any sample bourne shell scripts? Thank you.
wenching
6 REPLIES 6
harry d brown jr
Honored Contributor

Re: How to identify keys for validations?


Try this link

http://www.fnal.gov/docs/UNIX/unix_at_fermilab/htmldoc/rev1997/uatf-14.html


live free or die
harry
Live Free or Die
Chua Wen Ching
Regular Advisor

Re: How to identify keys for validations?

Thanks a lot. But i only see backspace key only which is represented by '^?'. How about enter, space bar, f1, etc. Any other reference. Thank you.
wenching
Bill Hassell
Honored Contributor
Solution

Re: How to identify keys for validations?

For the ASCII characters (including space and backspace and carriage return), see the man page for ascii (ie, man ascii). But the F1 (function keys) do not exist in ASCII. Instead, they are assigned special values, usually 2 or 3 characters.

But to make things quite complicated, there are hundreds of terminals, the majority being incompatible with each other. And to really muddy the problem even more, PC's look like terminals (keyboard and screen) but they can't act like a terminal without special software (called an emulator). The Windows' program Hyperterminal is an imitation terminal (and not a very good one at that).

Since you'll never be able to code for all the terminals that might be used with your script, there is an excellent library to help: Curses, and for shell scripts, tput is the key command. Read the man pages for: tput and terminfo

Note: Very few people use the Bourne shell today on HP-UX. The Bourne shell is started with: /usr/old/bin/sh but the standard shell on HP-UX is the POSIX shell which is /usr/bin/sh and /sbin/sh. A POSIX shell meets the POSIX standards and shells such as Korn (ksh) or BASH and HP's POSIX shell.


Bill Hassell, sysadmin
Chua Wen Ching
Regular Advisor

Re: How to identify keys for validations?

I want to learn bourne shell scripting as a basic fundamentals. I think that bourne is very similar to perl and korn. Anyway i think my org is using posix rather than bourne. But it is similar right, only posix is a newer version? Back to ASCII, i ws suprise to see the ascii values for ! = 041. Hmm, if i want to do validation how am i suppose to compare?

if test $a -eq "041" then
is it something like this, but i worried the shell will treat it as a normal number 041. Any solutions for this?
wenching
Chua Wen Ching
Regular Advisor

Re: How to identify keys for validations?

I had make research on Curses, tput and terminfo. I saw a number of functions but i do not want to implement it in C but in bourne/Posix scripting? Any sample script? i had tried:

tput bold
tput blink
tput rev

Can tput do more than that? Thank you.
wenching
Bill Hassell
Honored Contributor

Re: How to identify keys for validations?

The Bourne shell is a small subset of shells known as POSIX compliant shell programs. The Bourne shell has a large number of incompatibilities with ksh and other POSIX shells and is quite limited. There is nothing in common between Perl and shells like Bourne and Korn except that they are interpreted.

As for your question, the test would be made for plain ACII characters like this:

if test $a = "!"

or

if [ $a = "!" ]

Use the numeric value when there is no displayable character avaliable on the keyboard, and then the form would be:

if [ $a = "\014" ]

which tells the shell to substitute the appropriate ASCII character for \014.


Bill Hassell, sysadmin