Accepting input from cursor keys...
Author |
Message |
Andreas Kahar #1 / 10
|
 Accepting input from cursor keys...
Quote: > G'day, > Trying to write a small program to accept input and run certain procedures > accordingly. Unfortunately I do not know the ASCII binary representations > for input keys such as page up, page down, cursor keys, home and end. Any > idea how I can find these (to use in an if statement for example, if ch = > 0x..... )? > Thanks, > Jess
Wy don't you write a small program that reads the keys that the user uses and prints the corresponding ASCII values? /A -- # Andreas K?h?ri # Brought to you from Uppsala, Sweden # http://www.*-*-*.com/ # Echelon: guvf vf whfg gb naabl lbh Sent via Deja.com http://www.*-*-*.com/ Before you buy.
|
Sun, 01 Sep 2002 03:00:00 GMT |
|
 |
Joona I Palast #2 / 10
|
 Accepting input from cursor keys...
: G'day, : Trying to write a small program to accept input and run certain procedures : accordingly. Unfortunately I do not know the ASCII binary representations : for input keys such as page up, page down, cursor keys, home and end. Any : idea how I can find these (to use in an if statement for example, if ch = : 0x..... )? The input keys (page up, page down, cursor keys, home and end) are not part of the C standard. This question cannot be portably answered. Try asking in your own operating system's newsgroup instead. --
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #80 D+ ADA N+++ | | http://www.helsinki.fi/~palaste W++ B OP+ | \----------------------------------------- Finland rules! ------------/ "You will be given the plague." - Montgomery Burns
|
Sun, 01 Sep 2002 03:00:00 GMT |
|
 |
Dave Vandervi #3 / 10
|
 Accepting input from cursor keys...
Quote: >G'day, >Trying to write a small program to accept input and run certain procedures >accordingly. Unfortunately I do not know the ASCII binary representations >for input keys such as page up, page down, cursor keys, home and end. Any >idea how I can find these (to use in an if statement for example, if ch = >0x..... )?
As section 19.5 of the comp.lang.c FAQ (which can be found at http://www.eskimo.com/~scs/C-faq/top.html) says, this is system dependent and outside the scope of comp.lang.c . If you have access to curses or ncurses (most unix and unix-like systems have one of the two), it should be able to interpret the cursor keys for you in a manner that's reasonably consistent across most unices and clones thereof; if you have problems with this the friendly folks in comp.unix.programmer will be able to help you out. With other systems, check for '\0' in keyboard input, which is often a flag that a nonstandard character is coming next. Checking with a newsgroup for your compiler and OS will probably get more complete and useful answers. dave -- Dave Vandervies
I have no mouth, and I must scream.
|
Sun, 01 Sep 2002 03:00:00 GMT |
|
 |
-hs- #4 / 10
|
 Accepting input from cursor keys...
Quote:
>> G'day, >> Trying to write a small program to accept input and run certain >procedures >> accordingly. Unfortunately I do not know the ASCII binary >representations >> for input keys such as page up, page down, cursor keys, home and end. >Any >> idea how I can find these (to use in an if statement for example, if >ch = >> 0x..... )? >> Thanks, >> Jess >Wy don't you write a small program that reads the keys that the user >uses and prints the corresponding ASCII values?
Good idea. I have tried that by curiousity (I usually use Borland extensions) #include <stdio.h> #include <ctype.h> int main (void) { int c; while ((c=getchar())!=EOF) { if (isprint(c)) { printf("$%02X (%u) '%c'\n" ,(unsigned)c ,(unsigned)c ,c ); } else { printf("$%02X (%u)\n" ,(unsigned)c ,(unsigned)c ); } } return 0; Quote: }
On my machine (DOS-window on Windows 98), the special keys (arrows, pgup/down, function etc...) are simply ignored by stdin. I am not surprised, but I had never experimented it. (On my DOS machine, I type ^Z/enter to quit). Note : The F6 key produces a ^Z. -- -hs- "Stove" CLC-FAQ: http://www.eskimo.com/~scs/C-faq/top.html ISO-C Library: http://www.dinkum.com/htm_cl "It's specified. But anyone who writes code like that should be transmogrified into earthworms and fed to ducks." -- Chris Dollin CLC
|
Sun, 01 Sep 2002 03:00:00 GMT |
|
 |
Mark McIntyr #5 / 10
|
 Accepting input from cursor keys...
On Wed, 15 Mar 2000 22:25:12 +0100, "-hs-" Quote:
>>> G'day, >>> Trying to write a small program to accept input and run certain procedures >>> accordingly. Unfortunately I do not know the ASCII binary representations >>> for input keys such as page up, page down, cursor keys, home and end. Any >>> idea how I can find these (to use in an if statement for example, if >>Wy don't you write a small program that reads the keys that the user >>uses and prints the corresponding ASCII values? >Good idea. I have tried that by curiousity (I usually use Borland >extensions) >On my machine (DOS-window on Windows 98), the special keys (arrows, >pgup/down, function etc...) are simply ignored by stdin. I am not surprised, >but I had never experimented it. (On my DOS machine, I type ^Z/enter to >quit). >Note : The F6 key produces a ^Z.
The non-alpha keys don't have ASCII codes (-hs- knew that of course) and you can't read them in standard C. You need to use some fancy extensions to C which are OS and system specific. I'm writing this on a Vax Workstation, which has no arrow keys but does have F13-F20. and PF1 to PF4, And F6 definitely does not produce Ctrl-Z. Mark McIntyre C- FAQ: http://www.eskimo.com/~scs/C-faq/top.html
|
Sun, 01 Sep 2002 03:00:00 GMT |
|
 |
Gordon Burdi #6 / 10
|
 Accepting input from cursor keys...
Quote: >The non-alpha keys don't have ASCII codes (-hs- knew that of course) >and you can't read them in standard C.
This is also system-dependent. On many systems special keys DO generate character codes (usually several of them for each special key), and you can write a standard C program to simply read the characters from stdin and print their values in decimal, hex, octal, or however you want. If your native character set happens to be ASCII, these will be ASCII codes. If something tells your program what character sequences correspond to function keys, arrow keys, COIN RETURN key, and SELF-DESTRUCT key, then it can parse the input and figure out what keys were entered. Two examples of this are MS-DOS, where special keys usually have a 2-byte sequence, the first byte having the value 0, and vt100 and similar terminals (and emulators of them), which use 3+ character sequences with the first byte being the ASCII ESC character and the second byte often being the '[' character. Obviously, this is system-dependent. Quote: >You need to use some fancy >extensions to C which are OS and system specific.
Or you could use a user-supplied configuration file which in conjunction with user-supplied code, allows remapping almost the whole keyboard. Quote: >I'm writing this on >a Vax Workstation, which has no arrow keys but does have F13-F20. and >PF1 to PF4, And F6 definitely does not produce Ctrl-Z. >Mark McIntyre >C- FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Gordon L. Burditt
|
Mon, 02 Sep 2002 03:00:00 GMT |
|
 |
Andreas Kahar #7 / 10
|
 Accepting input from cursor keys...
Quote:
> Andreas Kahari a crit dans le message
Quote:
> >> G'day, > >> Trying to write a small program to accept input and run certain > >procedures > >> accordingly. Unfortunately I do not know the ASCII binary > >representations > >> for input keys such as page up, page down, cursor keys, home and end. > >Any > >> idea how I can find these (to use in an if statement for example, if > >ch = > >> 0x..... )? > >> Thanks, > >> Jess > >Wy don't you write a small program that reads the keys that the user > >uses and prints the corresponding ASCII values? > Good idea. I have tried that by curiousity (I usually use Borland > extensions) > #include <stdio.h> > #include <ctype.h> > int main (void) > { > int c; > while ((c=getchar())!=EOF) > { > if (isprint(c)) > { > printf("$%02X (%u) '%c'\n" > ,(unsigned)c > ,(unsigned)c > ,c > ); > } > else > { > printf("$%02X (%u)\n" > ,(unsigned)c > ,(unsigned)c > ); > } > } > return 0; > } > On my machine (DOS-window on Windows 98), the special keys (arrows, > pgup/down, function etc...) are simply ignored by stdin. I am not surprised, > but I had never experimented it. (On my DOS machine, I type ^Z/enter to > quit). > Note : The F6 key produces a ^Z. > -- > -hs- "Stove" > CLC-FAQ: http://www.eskimo.com/~scs/C-faq/top.html > ISO-C Library: http://www.dinkum.com/htm_cl > "It's specified. But anyone who writes code like that should be > transmogrified into earthworms and fed to ducks." -- Chris Dollin CLC
I knew that too. Since the standard doesn't say anything about hardware devices such as keyboards, this is exactly the behaviour that I thought Jess/Pedro/Fred would learn something from. /A -- # Andreas K?h?ri # Brought to you from Uppsala, Sweden # http://hello.to/andkaha # Echelon: guvf vf whfg gb naabl lbh Sent via Deja.com http://www.deja.com/ Before you buy.
|
Mon, 02 Sep 2002 03:00:00 GMT |
|
 |
Mark McIntyr #8 / 10
|
 Accepting input from cursor keys...
Quote:
>>The non-alpha keys don't have ASCII codes (-hs- knew that of course) >>and you can't read them in standard C. >This is also system-dependent. <snip> >Two examples of this are MS-DOS, where special keys usually have >a 2-byte sequence, the first byte having the value 0, and vt100 >and similar terminals (and emulators of them), which use 3+ character >sequences with the first byte being the ASCII ESC character and >the second byte often being the '[' character. Obviously, this is >system-dependent.
... except that getchar() does not recieve the key strokes, and getch() which does is non-standard. Hence my remark that you need to use non-ANSI features as stated below. Quote: >>You need to use some fancy >>extensions to C which are OS and system specific. >Or you could use a user-supplied configuration file which in conjunction >with user-supplied code, allows remapping almost the whole keyboard.
Or you could use non-standard features... Mark McIntyre C- FAQ: http://www.eskimo.com/~scs/C-faq/top.html
|
Mon, 02 Sep 2002 03:00:00 GMT |
|
 |
Gordon Burdi #9 / 10
|
 Accepting input from cursor keys...
Quote: >>>The non-alpha keys don't have ASCII codes (-hs- knew that of course) >>>and you can't read them in standard C. >>This is also system-dependent. <snip> >>Two examples of this are MS-DOS, where special keys usually have >>a 2-byte sequence, the first byte having the value 0, and vt100 >>and similar terminals (and emulators of them), which use 3+ character >>sequences with the first byte being the ASCII ESC character and >>the second byte often being the '[' character. Obviously, this is >>system-dependent. >... except that getchar() does not recieve the key strokes, and >getch() which does is non-standard. Hence my remark that you need to >use non-ANSI features as stated below.
On the systems I am talking about (UNIX with VT-100 terminals, and even some MS-DOS systems), getchar() *DOES* receive the character sequences from the keystrokes. Or you could use fgets(), or fread(), or even the evil gets() or scanf(). Granted, they aren't decoded into a code that says "this is a shifted F4", but with sufficient information, your program can do that decoding, or you could just hardcode the program with the knowledge of what keystroke produces what character sequences. In any case, it is easy to write a pure standard-ANSI-C program that receives the character sequences from special keys and prints them out in decimal or hex or whatever. (Ok, you'll have to press ENTER at the end to be sure the program receives them). Gordon L. Burditt
|
Tue, 03 Sep 2002 03:00:00 GMT |
|
 |
Mark McIntyr #10 / 10
|
 Accepting input from cursor keys...
Quote:
>>>>The non-alpha keys don't have ASCII codes (-hs- knew that of course) >>>>and you can't read them in standard C. >>>This is also system-dependent. <snip> >>>Two examples of this are MS-DOS, where special keys usually have >>>a 2-byte sequence, the first byte having the value 0, and vt100 >>>and similar terminals (and emulators of them), which use 3+ character >>>sequences with the first byte being the ASCII ESC character and >>>the second byte often being the '[' character. Obviously, this is >>>system-dependent. >>... except that getchar() does not recieve the key strokes, and >>getch() which does is non-standard. Hence my remark that you need to >>use non-ANSI features as stated below. >On the systems I am talking about (UNIX with VT-100 terminals, and >even some MS-DOS systems), getchar() *DOES* receive the character >sequences from the keystrokes.
So, like we say, the result is totally implementation dependent and you can't do it in standard C. BTW on all the DOS platforms i tried it on this failed. I;ll try it on Solaris and VMS tomorrow but I have little hope... Quote: >Or you could use fgets(), or >fread(), or even the evil gets() or scanf().
And even less for these... Quote: >Granted, they aren't >decoded into a code that says "this is a shifted F4", but with >sufficient information, your program can do that decoding, or >you could just hardcode the program with the knowledge of what >keystroke produces what character sequences. In any case, it is >easy to write a pure standard-ANSI-C program that receives the >character sequences from special keys and prints them out in >decimal or hex or whatever. (Ok, you'll have to press ENTER at the >end to be sure the program receives them). > Gordon L. Burditt
Mark McIntyre C- FAQ: http://www.eskimo.com/~scs/C-faq/top.html
|
Tue, 03 Sep 2002 03:00:00 GMT |
|
|
|