Solved

How do I get Function keys to be recognised?? e.g. F1

Posted on 2000-03-23
4
206 Views
Last Modified: 2010-04-16
I am a beginning pascal programmer. I need to know how to get pascal to recognise the Function buttons (e.g.F1, F2 etc.)
I am going to use a case statement for a menu and the function keys are the keys I need to use.
PLEASE HELP
THANKYOU
0
Comment
Question by:Waulsy
  • 2
  • 2
4 Comments
 

Author Comment

by:Waulsy
ID: 2652185
Adjusted points from 50 to 75
0
 
LVL 12

Accepted Solution

by:
Hypo earned 75 total points
ID: 2652299
Here's a sample code for you that I made. Some keys on the keyboard are extended and some of the keys are not extended. When you receive a scancode for an extended key, the scancode will be preceeded by a 0. If it's not an extended key, the scancode will come alone.

So... check the GetKey function I've made, it holds the information you need be able to identify these keypresses.  

Program GetKeys;
uses crt;

var Ext : boolean;
    Key : byte;

Procedure GetKey;
begin
  Key := ord(Readkey);
  if Key = 0 then begin
   Key := ord(Readkey);
   Ext := true;
  end else Ext := false;
end;

begin
 ClrScr;
 repeat
  GetKey;
  GotoXy(1,1);
  Writeln('Key: ',Key:3,'  Extended: ',Ext:5);
 until Key = 27;
end.
0
 

Author Comment

by:Waulsy
ID: 2652601
GOOD PROGRAM I LIKE.
But how do I implement that into a CASE statement to say when this key(F1) is pressed do THIS???
0
 
LVL 12

Expert Comment

by:Hypo
ID: 2656282
You really shouldn't have to ask a new  question about this. But since you did, I'll post this answer in the new questions aswell as this one, and let you decide wether or not you want to give away those points. ;)

Here's the example:

Program GetKeys;

uses crt;

var Ext : boolean;
    Key : byte;

Procedure GetKey;
begin
  Key := ord(Readkey);
  if Key = 0 then begin
   Key := ord(Readkey);
   Ext := true;
  end else Ext := false;
end;

begin
 ClrScr;
 repeat
  GetKey;
  GotoXy(1,1);
  clreol;
  Write('Key: ',Key:3,'  Extended: ',Ext:5,' - ');
  If Ext then
  { F1..F10 are extended keys and have the scancodes between 59-68 }
   Case Key of
    59 : Writeln('You pressed F1');
    60 : Writeln('You pressed F2');
    61 : Writeln('You pressed F3');
    62 : Writeln('You pressed F4');
    63 : Writeln('You pressed F5');
    64 : Writeln('You pressed F6');
    65 : Writeln('You pressed F7');
    66 : Writeln('You pressed F8');
    67 : Writeln('You pressed F9');
    68 : Writeln('You pressed F10');
   end;
 until Key = 27;
end.

Hope it helps,
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Troubleshooting common task sequence error codes
One of the biggest threats in the cyber realm pertains to advanced persistent threats (APTs). This paper is a compare and contrast of Russian and Chinese APT's.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question