Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!elroy.jpl.nasa.gov!sdd.hp.com!hplabs!hpcc05!hpyhde1!hpycla!hpcuhc!hpcupt3!defaria@hpcupt3.cup.hp.com From: defaria@hpcupt3.cup.hp.com (Andy DeFaria) Newsgroups: comp.lang.pascal Subject: Re: Re: CTRL-Characters Message-ID: <45670004@hpcupt3.cup.hp.com> Date: 1 Apr 91 17:56:01 GMT References: <1991Mar28.005803.25890@oz.plymouth.edu> Organization: Hewlett Packard, Cupertino Lines: 79 >/ hpcupt3:comp.lang.pascal / einstein@cs.mcgill.ca (Michael CHOWET) / 12:18 am Mar 30, 1991 / >In article <1991Mar27.161213.2100@cs.mcgill.ca> storm@cs.mcgill.ca >(Marc WANDSCHNEIDER) writes: > >>How do I make a PASCAL program recognize CTRL characters (or ALT characters >>for that matter). Ie I want the following: > >> IF CH = CTRL-G then >> BEGIN >> blahblahb >> END; > > Actually, there are two ways to get at this. If you feel like dragging out >the list of ASCII codes, you can type: > > If CH = #07 Then DoSomething ; > > Basically, the # symbol followed by the ASCII code. Simple enough, right? > > But if you want the actual character in there, hit the ^P. The following >character (your CTRL-char) will be accepted as a literal, ie it will be >inserted into the text without trying to process it as an editor control key. IMHO this is asking for trouble and curses from fellow programmers. What I do is: Unit ASCII; Interface Const ControlA = #01; ControlB = #02; ... ControlG = #07; Implementation End. { ASCII } Program Foo; Uses ASCII; Var Character : Char; Begin { Foo } Character := ReadKey; If Character = ControlG then { Do want you want } else { Do something else } End. { Foo } If you define all ASCII characters in the Unit ASCII then you can easily refer to them *symbolically* by simply including the ASCII unit in your uses statement. Note that Control characters do NOT have a scan code. Function keys, and all there derivitives like ControlF1, AltF2, etc, do. What I have done is wrote a more generic GETKEY function that handles these things and returns things like ControlF1 or AltF2, which I have defined in the ASCII unit as something like: Const ControlF1 = #170; ControlF2 = #171; ... AltF1 = #180; AltF2 = #181; I'm pretty sure that the characters #170 on up aren't used (although they are probably 8-bit characters used for other language sets but I'm not concerned with them).