Path: utzoo!attcan!uunet!cs.utexas.edu!sun-barr!newstop!sun!amdahl!netcom!ergo From: ergo@netcom.UUCP (Isaac Rabinovitch) Newsgroups: comp.lang.pascal Subject: Re: Scan codes in TurboPascal Message-ID: <13295@netcom.UUCP> Date: 17 Sep 90 04:45:06 GMT References: <1561.26f20a24@waikato.ac.nz> Organization: UESPA Lines: 59 In <1561.26f20a24@waikato.ac.nz> iam@waikato.ac.nz (Ian McDonald) writes: >How do you pick up Scan codes in TP 5.5? From my reading of the manuals you >have to resort to machine code. I am after picking up Ctrl-ESC as well as just >Esc as ReadKey doesn't differentiate. Correction: ReadKey *does* know about scan codes. (I gather you knew that, but your writing style makes precise interpretation a nondeterministic procedure.) You're right about ReadKey treating CTL-ESC the same as ESC, but that's not ReadKey's fault -- it sends a signal to the BIOS saying it wants a key, and reports what it gets. One way around this is to talk to the BIOS yourself. Now, this is indeed a low-level function, but you can do it in a high-level language if you've got the right function libraries -- and as it happens, the Turbo Pascal DOS Unit is such a library. With the INTR function, you can send arbitrary software interrupts almost as easily as any assembly-language hacker. The following function uses INTR to invoke interrupt 16h, function 2h: interrogate shift status byte. uses dos; function shifts : byte; var r : Registers; begin r.ah := $02; intr($16, r); shifts := r.al; end; The word returned by shifts is the sum of the following values: 1 -- right shift key depressed 2 -- left " " " 4 -- ctrl key depressed 8 -- alt " " 16 -- scroll lock on 32 -- num " " 64 -- caps " " 128 -- insert mode on Note that this gives you the shift status *now*, which is not necesarily what the shift status was when ReadKey returned; you'll want to interrogate shifts *very* soon after calling ReadKey. -- ergo@netcom.uucp Isaac Rabinovitch {apple,amdahl,claris}!netcom!ergo Silicon Valley, CA Collins's Law: If you can't make a mistake, you can't make anything. Corollaries ("Rabinovitch's Rules of Sane Dialogue"): 1. Everybody who matters is stupid now and then. 2. If I'm being stupid, that's my problem. 3. If my being stupid makes you stupid, that's your problem. 4. If you think you're never stupid, boy are you stupid!