Recent

Author Topic: Scan code of the enter key in readkey function  (Read 1911 times)

Scorpion197

  • Newbie
  • Posts: 5
Scan code of the enter key in readkey function
« on: December 21, 2019, 02:20:16 pm »
I'm writing the following code in Pascal :
Code: Pascal  [Select][+][-]
  1. program console;
  2. uses crt;
  3. var
  4.         x,y :integer;
  5.         key:char;
  6. begin
  7.         x := 0;
  8.         y := 0;
  9.         Repeat
  10.                 Write('Enter a key : ');
  11.                 key := readkey;
  12.                 case key of
  13.                 { 72 ==> up key ; 80 ==> down key }
  14.                         #75 : x := x-1 ;
  15.                         #77 : x := x+1;
  16.                
  17.                 end;
  18.         until (key = #27); // Esc
  19.         writeln;
  20.         write('The new position of x is : ',x);
  21. end.
  22.        
I want if the user clicks on the enter key then i will perform some actions . but i ignore the scancode the enter key . So does anyone know its scan code ?

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Scan code of the enter key in readkey function
« Reply #1 on: December 21, 2019, 02:46:57 pm »
You can get the code for any key with a similar program:

Code: Pascal  [Select][+][-]
  1. program whichkey;
  2. uses crt;
  3. var
  4.   key:char;
  5. begin
  6.   WriteLn('Press keys (ESC to exit) : ');
  7.   repeat
  8.     key := readkey;
  9.     if key <> #00 then
  10.       writeln('Key : #', Ord(key))
  11.     else
  12.       writeln('Extended key : #', Ord(ReadKey));
  13.   until (key = #27); // Esc
  14. end.

Compile, run and press <Enter> :)
« Last Edit: December 21, 2019, 03:43:59 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Scorpion197

  • Newbie
  • Posts: 5
Re: Scan code of the enter key in readkey function
« Reply #2 on: December 21, 2019, 03:17:24 pm »
It worked ! thanks man !

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Scan code of the enter key in readkey function
« Reply #3 on: December 21, 2019, 03:44:38 pm »
 :D
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018