home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c:20128 comp.os.msdos.programmer:12383 alt.sources:3079
- Newsgroups: comp.lang.c,comp.os.msdos.programmer,alt.sources
- Path: sparky!uunet!utcsri!geac!lethe!druid!darcy
- From: darcy@druid.uucp (D'Arcy J.M. Cain)
- Subject: Re: Reading the arrow keys... how?
- Message-ID: <1993Jan23.193041.19858@druid.uucp>
- Date: Sat, 23 Jan 1993 19:30:41 GMT
- References: <1jmeupINN4g9@savoy.cc.williams.edu> <1993Jan22.010607.15208@cbfsb.cb.att.com>
- Organization: D'Arcy Cain Consulting
- Followup-To: comp.os.msdos.programmer
- Lines: 233
-
- **NOTE: I am crossposting to alt.sources because of the header file
- included but am redirecting followups to comp.os.msdos.programmer.
-
- rnichols@cbnewsg.cb.att.com (robert.k.nichols) writes:
- >In article <1jmeupINN4g9@savoy.cc.williams.edu> 93gke@williams.edu (Just Ask The Axis) writes:
- >>I am trying to read the arrow keys from a PC keyboard in C. So far
- >You can use getch() to read the arrow keys. The extended keys all
- >return a 2-byte sequence, with the first byte being either 0 or 0xE0.
-
- Where did you get that 0xE0? It returns a zero byte followed by the
- scan code.
-
- Here is a header file I wrote which I find very useful. The comments
- explain its usage. Enjoy.
-
- /*
- ascii.h
- Written by D'Arcy J.M. Cain
- D'Arcy Cain Consulting
- darcy@druid.com
-
- ASCII control codes (including extended IBM codes)
-
- This file is mainly a handy place to keep the standard names of ASCII
- control characters as well as a simple macro to return a control character.
- Further, if used on an MSDOS system it creates defines for the extended
- characters on the IBM keyboard. The number defined is the scan code of
- the key shifted left 8 bits. To use this create a simple function
- something like this:
-
- int
- getkey(void)
- {
- int c;
-
- if (!(c = getch())) /* don't forget to include conio.h */
- c = getch() << 8
-
- return(c);
- }
-
- Now you can do the following:
-
- switch (c = getkey())
- {
- case UP_ARROW:
- /* up arrow stuff */
- break;
-
- case DOWN_ARROW:
- /* down arrow stuff */
- break;
-
- case FUNC1:
- case ALT_H:
- /* present help */
- break;
-
- case CR:
- /* do carriage return stuff */
- break;
-
- /* etc ... */
-
- default:
- if (isprint(c))
- /* put character into string or whatever */
- break;
- }
-
- */
-
- #ifndef _ASCII_H
- #define _ASCII_H
-
- #ifndef CTRL
- #define CTRL(x) ((x) & 0x1f)
- #endif
-
- #define NUL 0x00
- #define SOH 0x01
- #define STX 0x02
- #define ETX 0x03
- #define EOT 0x04
- #define ENQ 0x05
- #define ACK 0x06
- #define BEL 0x07
- #define BS 0x08
- #define HT 0x09
- #define LF 0x0a
- #define VT 0x0b
- #define FF 0x0c
- #define CR 0x0d
- #define SO 0x0e
- #define SI 0x0f
- #define DLE 0x10
- #define DC1 0x11
- #define XON 0x11 /* alternate name for DC1 */
- #define DC2 0x12
- #define DC3 0x13
- #define XOFF 0x13 /* alternate name for DC3 */
- #define DC4 0x14
- #define NAK 0x15
- #define SYN 0x16
- #define ETB 0x17
- #define CAN 0x18
- #define EM 0x19
- #define SUB 0x1a
- #define ESC 0x1b
- #define FS 0x1c
- #define GS 0x1d
- #define RS 0x1e
- #define US 0x1f
- #define RUBOUT 0x7f
-
- #ifndef EOF
- #define EOF -1
- #endif
-
- #ifdef __MSDOS__
- #define FUNC1 0x3b00
- #define FUNC2 0x3c00
- #define FUNC3 0x3d00
- #define FUNC4 0x3e00
- #define FUNC5 0x3f00
- #define FUNC6 0x4000
- #define FUNC7 0x4100
- #define FUNC8 0x4200
- #define FUNC9 0x4300
- #define FUNC10 0x4400
-
- #define SHIFT_F1 0x5400
- #define SHIFT_F2 0x5500
- #define SHIFT_F3 0x5600
- #define SHIFT_F4 0x5700
- #define SHIFT_F5 0x5800
- #define SHIFT_F6 0x5900
- #define SHIFT_F7 0x5a00
- #define SHIFT_F8 0x5b00
- #define SHIFT_F9 0x5c00
- #define SHIFT_F10 0x5d00
-
- #define CTL_F1 0x5e00
- #define CTL_F2 0x5f00
- #define CTL_F3 0x6000
- #define CTL_F4 0x6100
- #define CTL_F5 0x6200
- #define CTL_F6 0x6300
- #define CTL_F7 0x6400
- #define CTL_F8 0x6500
- #define CTL_F9 0x6600
- #define CTL_F10 0x6700
-
- #define ALT_F1 0x6800
- #define ALT_F2 0x6900
- #define ALT_F3 0x6a00
- #define ALT_F4 0x6b00
- #define ALT_F5 0x6c00
- #define ALT_F6 0x6d00
- #define ALT_F7 0x6e00
- #define ALT_F8 0x6f00
- #define ALT_F9 0x7000
- #define ALT_F10 0x7100
-
- #define ALT_1 0x7800
- #define ALT_2 0x7900
- #define ALT_3 0x7a00
- #define ALT_4 0x7b00
- #define ALT_5 0x7c00
- #define ALT_6 0x7d00
- #define ALT_7 0x7e00
- #define ALT_8 0x7f00
- #define ALT_9 0x8000
- #define ALT_10 0x8100
-
- #define ALT_A 0x1e00
- #define ALT_B 0x3000
- #define ALT_C 0x2e00
- #define ALT_D 0x2000
- #define ALT_E 0x1200
- #define ALT_F 0x2100
- #define ALT_G 0x2200
- #define ALT_H 0x2300
- #define ALT_I 0x1700
- #define ALT_J 0x2400
- #define ALT_K 0x2500
- #define ALT_L 0x2600
- #define ALT_M 0x3200
- #define ALT_N 0x3100
- #define ALT_O 0x1800
- #define ALT_P 0x1900
- #define ALT_Q 0x1000
- #define ALT_R 0x1300
- #define ALT_S 0x1f00
- #define ALT_T 0x1400
- #define ALT_U 0x1600
- #define ALT_V 0x2f00
- #define ALT_W 0x1100
- #define ALT_X 0x2d00
- #define ALT_Y 0x1500
- #define ALT_Z 0x2c00
-
- #define ALT_HYPHEN 0x8200
- #define ALT_EQUAL 0x8300
-
- #define SHIFT_TAB 0x0f00
- #define HOME 0x4700
- #define UP_ARROW 0x4800
- #define PG_UP 0x4900
- #define LEFT_ARROW 0x4b00
- #define RIGHT_ARROW 0x4d00
- #define END 0x4f00
- #define DOWN_ARROW 0x5000
- #define PG_DOWN 0x5100
- #define INSERT 0x5200
- #define DELETE 0x5300
-
- #define CTL_PR_SCR 0x7200
- #define CTL_LEFT_ARROW 0x7300
- #define CTL_RIGHT_ARROW 0x7400
- #define CTL_END 0x7500
- #define CTL_PG_DOWN 0x7600
- #define CTL_HOME 0x7700
- #define CTL_PG_UP 0x8400
-
- #endif /* __MSDOS__ */
- #endif /* _ASCII_H */
-
- --
- D'Arcy J.M. Cain (darcy@druid.com) |
- D'Arcy Cain Consulting | There's no government
- Toronto, Ontario, Canada | like no government!
- +1 416 424 2871 DoD#0082 |
-