Solved

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

Posted on 2000-03-23
4
201 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In this article, I show you step by step with screenshots to assist you - HOW TO: Deploy and Install the VMware vCenter Server Appliance 6.5 (VCSA 6.5), with some helpful tips along the way.
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now