Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ASCII/scan codes

321 views
Skip to first unread message

ch...@uwpg02.uwinnipeg.ca

unread,
Aug 29, 1993, 10:19:02 PM8/29/93
to
WHat is the difference between ASCII code and scan code. For example,
the character'A' has the ASCII code of 65. But is the scan code
also 65 on a North American extended keyboard?
The F1 key has no ascii code but does have a scan code, correct?

Suppose I wanted an action to continue until I pressed the F1 key.
Could I do something like this :

Ch := Readkey;
REPEAT
dosomething;
UNTIL Ch = whatever the scan code for F1 is?

Does the # symbol in TP5.5 refer to ASCII or scan code?

Finally, I noticed on nic.funet.fi (in the SIMTEL20 mirrors) that there
were some inside-tp magazines 1990. Are any other years of this magazine
available anywhere?

Thank you very much for your help.
internet: ch...@uwpg02.uwinnipeg.ca

Leonard Erickson

unread,
Aug 30, 1993, 12:36:02 AM8/30/93
to
ch...@uwpg02.uwinnipeg.ca writes:

>WHat is the difference between ASCII code and scan code. For example,
> the character'A' has the ASCII code of 65. But is the scan code
>also 65 on a North American extended keyboard?

The "scan code" is the number assigned to that *key* on the keyboard.
And 'A' is most definitely *not* 65!

>The F1 key has no ascii code but does have a scan code, correct?

*All* keys have scan codes. Even the "shift" keys (shift, ctrl, alt, etc)
But in TP the scan codes are not easily accessible. They get translated to
something else at the BIOS level.

>Suppose I wanted an action to continue until I pressed the F1 key.
>Could I do something like this :

>Ch := Readkey;
>REPEAT
> dosomething;
>UNTIL Ch = whatever the scan code for F1 is?

Most keypresses that don't generate an ASCII character do generate an
"extended keypress". Pressing F1 will put *two* characters in the keyboard
queue. The first is 00. The second tells you which special key combo was
pressed. There's a table in the TP manual.

As you can see, your loop is a bit simplstic for this. You'd best write
a function, and test for the value it returns.

>Does the # symbol in TP5.5 refer to ASCII or scan code?

"ASCII". Or rather the 0-255 "extended ASCII code" used in the PC. It
has nothing to do with the keyboard codes. It's actually a typecast.
"#x" is equivalent to "char(X)"

--
Leonard Erickson leo...@qiclab.scn.rain.com
FIDO: 1:105/51 Leonard....@f51.n105.z1.fidonet.org (preferred)

Evan Johnson

unread,
Aug 30, 1993, 10:17:50 AM8/30/93
to
In article <1993Aug30.0...@qiclab.scn.rain.com> Leonard....@f51.n105.z1.fidonet.org writes:
>>Does the # symbol in TP5.5 refer to ASCII or scan code?
>
>"ASCII". Or rather the 0-255 "extended ASCII code" used in the PC. It
>has nothing to do with the keyboard codes. It's actually a typecast.
>"#x" is equivalent to "char(X)"

I beg to differ. The "#" sign before a number in TP5.0 and up refers to a
scan code sans the preceding 00h. Not all of them are available, however.

So, for the loop described in the previous post, you *could* do this:

REPEAT
Ch := ReadKey;
{ do stuff ... }
UNTIL Ch = #59

which would repeat until F1 was pressed. However, although the SHIFT,
CTRL, and ALT keys do in fact have scan codes, they are not available with
this approach.

So, the "#" sign is distinctly different from the Chr () function; #59
refers to the F1 key, while Chr(59) refers to ASCII character 59, or a
semicolon.

-eaj

Brad Williams

unread,
Aug 30, 1993, 11:13:35 AM8/30/93
to
>Finally, I noticed on nic.funet.fi (in the SIMTEL20 mirrors) that there
>were some inside-tp magazines 1990. Are any other years of this magazine
>available anywhere?

I was poking around on oak.oakland.edu this weekend and saw the inside-TP
subdirectory. I have all source code listings through July 91 and will
upload them as soon as I have time. A couple of weeks ago I tried to
download the rest of the *.arc files and found that Cobbs bulletin board had
been discontinued, at least the pascal access. If anyone has the *.arc
files more recent than July 91 I would appreciate a copy. BTW, for the
Inside Turbo Pascal magazine has been discontinued.

----------------------------------------------------------------------
Dr. Brad Williams, Campus Veterinarian
Animal and Vet Science Phone: (208) 885-8958
University of Idaho FAX: (208) 885-6420
Moscow, Idaho 83844-2330 Internet: bwil...@marvin.ag.uidaho.edu
----------------------------------------------------------------------

Brad Williams

unread,
Aug 30, 1993, 1:39:34 PM8/30/93
to
>>>Does the # symbol in TP5.5 refer to ASCII or scan code?
>>
>>"ASCII". Or rather the 0-255 "extended ASCII code" used in the PC. It
>>has nothing to do with the keyboard codes. It's actually a typecast.
>>"#x" is equivalent to "char(X)"
>
>I beg to differ. The "#" sign before a number in TP5.0 and up refers to a
>scan code sans the preceding 00h. Not all of them are available, however.
>
>So, for the loop described in the previous post, you *could* do this:
>
>REPEAT
>Ch := ReadKey;
>{ do stuff ... }
>UNTIL Ch = #59
>
>which would repeat until F1 was pressed. However, although the SHIFT,
>CTRL, and ALT keys do in fact have scan codes, they are not available with
>this approach.
>
>So, the "#" sign is distinctly different from the Chr () function; #59
>refers to the F1 key, while Chr(59) refers to ASCII character 59, or a
>semicolon.

While, I beg to differ. I just ran your loop and terminated it by pressing
the semicolon.

When I think of the ASCII "character", I associate a byte in the range of
0-255 with a predetermined character in the ASCII character set. For any
key that generates a single scancode (byte) when pressed, the character
value of the scancode is equal to the same byte value of the ASCII
character. Some keys (function keys among others) generate a 0 as
the first scancode followed by a second scancode and must be interpreted
together.

The # sign does in fact convert the byte to a character. Just try to
compile while assigning a #0 to a byte type variable. The compiler gives
a compilation error #26, type mismatch. You can do any of the following:

VAR ch : Char;
b : Byte;

b := Ord(ch);
ch := Char(b);
ch := #65;
b := Ord(#65);

But you can't do:

ch := #b;

Joseph Robertson

unread,
Aug 31, 1993, 7:17:53 AM8/31/93
to
In article <bwilliams.3...@marvin.ag.uidaho.edu>,
bwil...@marvin.ag.uidaho.edu (Brad Williams) writes:

>>>>Does the # symbol in TP5.5 refer to ASCII or scan code?

[A lot of text deleted ...]

Hi,

The original posting of this thread asked wether the # had any connection
with either the ASCII code or the scan code returned by Pascal. The # has
a major part to play in the capturing of extended keypresses within Turbo
Pascal as it is used to identify which key or combination of keys were
pressed upon the keyboard.

Most of the code given in the previous replies to this thread were correct
apart from the actual parameters required to terminate the loop given
in the original posting. They failed to ensure that the keypressed at the
keyboard actually returned an extended key code as well as a secondary scan
code. One correct method of stopping a loop when the F1 key is pressed - and
in this case when the F1 key, and the F1 key *only* has been pressed - is as
shown below ...

This may or not be confusing, hopefully not, and may be of use to the
Brad and any number of other individuals out in the big wide world and if
so just goes to show that all that time spent in class was not wasted.

Joe.
---------------------- Pascal Source Code ---------------------------

{ Joseph Kevin Robertson, 31/08/1993 }
{ Dundee Institute of Technology, Dundee }
{ I know this source works on TP5.0, TP5.5 and TP6.0 ... }

Uses
Crt;

Var
FirstScanCode : Char; {Char - Required because you are}
SecondScanCode : Char; {going to examine Scan Codes *NOT*}
{Ascii Codes.}
Begin
Repeat
FirstScanCode := #0; {Initialised as a NULL}
SecondScanCode := #0; {Again, Initialised as a NULL}
FirstScanCode := ReadKey; {Get the first scan code from keyboard}
If (FirstScanCode = #0) Then {Is first scan code equal to NULL?}
Begin {Yes}
SecondScanCode := ReadKey; {Get secondary scan code from keyboard}
End
Else
Begin {No}
WriteLn('That was not an extended keypress ....'); {Error Message}
End;
Until ((FirstScanCode = #0) And (SecondScanCode = #59)); {Halts only
after F1 key
is pressed!}
End.

---------------------- End of Source Code ------------------------

--

**********************************************************************
* Joseph Kevin Robertson "Dragon Master" *
* Dundee Institute of Technology, *
* DUNDEE, SCOTLAND. *
* Internet : MCSCS1JKR%DCT....@NSFNET-RELAY.AC.UK *
* Janet : MCSC...@UK.AC.DUNDEE-TECH *
**********************************************************************

James Sprenger

unread,
Aug 31, 1993, 11:59:28 PM8/31/93
to
In article <bwilliams.3...@marvin.ag.uidaho.edu> bwil...@marvin.ag.uidaho.edu (Brad Williams) writes:
>>Finally, I noticed on nic.funet.fi (in the SIMTEL20 mirrors) that there
>>were some inside-tp magazines 1990. Are any other years of this magazine
>>available anywhere?
>
>I was poking around on oak.oakland.edu this weekend and saw the inside-TP
>subdirectory. I have all source code listings through July 91 and will
>upload them as soon as I have time. A couple of weeks ago I tried to
>download the rest of the *.arc files and found that Cobbs bulletin board had

The Cobb Group BBS can be reached via Compuserve (go znt:cobbprog), but I
think you'll still be disappointed... the archives are usually 1-2 issues
behind.

>been discontinued, at least the pascal access. If anyone has the *.arc
>files more recent than July 91 I would appreciate a copy. BTW, for the
>Inside Turbo Pascal magazine has been discontinued.
>

No, ITP has NOT been discontinued, in fact, I just recieved Aug/Sept 1993!
last week (aug 25/93)

-jgs


--
James Sprenger
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bell Canada: (416) 542-2900, (416) 842-6846
Internet: u0...@csx.cciw.ca

Leonard Erickson

unread,
Aug 31, 1993, 11:55:45 PM8/31/93
to
joh...@access.digex.net (Evan Johnson) writes:

>In article <1993Aug30.0...@qiclab.scn.rain.com> Leonard....@f51.n105.z1.fidonet.org writes:
>>>Does the # symbol in TP5.5 refer to ASCII or scan code?
>>
>>"ASCII". Or rather the 0-255 "extended ASCII code" used in the PC. It
>>has nothing to do with the keyboard codes. It's actually a typecast.
>>"#x" is equivalent to "char(X)"

>I beg to differ. The "#" sign before a number in TP5.0 and up refers to a
>scan code sans the preceding 00h. Not all of them are available, however.

*Where* did you get *that* idea. It's incorrect. I'd quote the manual at
you but I packed it yesterday.

#xx has nothing to do with scan codes. #32 is *space*, and that key does
*not* have a scan code of 32! Please read *your* manuals, with respect to
how you can enter string *constants*. You'll find "#" there.

Rogan Alan Hastings Dawes

unread,
Aug 31, 1993, 6:24:50 AM8/31/93
to
In <29AUG93....@uwpg02.uwinnipeg.ca> ch...@uwpg02.uwinnipeg.ca writes:

If you are going to be using the extended characters ie the function keys,
alt keys etc, what I recommend you do is write a small procedure that will
take care of reading the keystroke, not just the first return from
readkey. What I mean by this is : If you press a normal key, readkey
will return the ASCII value of the character. If you press an extended
key, Readkey will first return a character 0 (synonymous with #0, or char(0) )
and then the next call to readkey will return the scan code of the extended
key.

e.g. F1 is the same as #0#59 ie character 0 followed by character 59, etc

The way I do it is as follows.

type string2 = string[2];

Function GetKey : string2;
var t : string2;
begin
t[0]:=#2; { Assuming an extended key i.e. length =2 }
t[1]:=ReadKey;
if t[1]=#0 then { If we have an extended key then }
t[2]:=readkey { read the extended scan code }
else { else }
t[0]:=#1; { length = 1 }
GetKey := t; { return the string }
end;

var
c : string2;

begin
repeat
c:=Getkey;
until c=#0#59; { Read keys until F1 is pressed }
end.

Hope that this explains things.

ciao

--
--
Rogan Dawes - University of the Witwatersrand, South Africa

ro...@concave.cs.wits.ac.za

0 new messages