Solved

Hypo please help again( FUNCTION KEYS)

Posted on 2000-03-24
7
180 Views
Last Modified: 2010-04-16
I need to know how to implement this knowledge of the function keys into a case statement.
What I want to do is say in the program is IF this button (i.e F1) is pressed THEN do this. I need to know how to write this up.
THANKYOU.
0
Comment
Question by:Waulsy
  • 4
  • 2
7 Comments
 
LVL 6

Expert Comment

by:My name is Mud
ID: 2656072
Program FunctionKeys;
USES
  CRT;
CONST
  Special: Boolean = False;
VAR
  Key: Char;

Begin
  Repeat
    Key:=#0;
    If KeyPressed Then
      Begin
        Key:=ReadKey;
        If Key = #0 Then
          Begin
            Special:=True;
            Key:=ReadKey;
          End
        Else Special:=False;
      End;
    Case Key Of
      #59:
        If Not Special Then
          WriteLn('Key ',Key,' Pressed...')
        Else
          WriteLn('Key F1 Special Pressed...');
      #60:
        If Not Special Then
          WriteLn('Key ',Key,' Pressed...')
        Else
          WriteLn('Key F2 Special Pressed...');
      #61:
        If Not Special Then
          WriteLn('Key ',Key,' Pressed...')
        Else
          WriteLn('Key F3 Special Pressed...');
      #62:
        If Not Special Then
          WriteLn('Key ',Key,' Pressed...')
        Else
          WriteLn('Key F4 Special Pressed...');
      #63:
        If Not Special Then
          WriteLn('Key ',Key,' Pressed...')
        Else
          WriteLn('Key F5 Special Pressed...');
      #64:
        If Not Special Then
          WriteLn('Key ',Key,' Pressed...')
        Else
          WriteLn('Key F6 Special Pressed...');
      #65:
        If Not Special Then
          WriteLn('Key ',Key,' Pressed...')
        Else
          WriteLn('Key F7 Special Pressed...');
      #66:
        If Not Special Then
          WriteLn('Key ',Key,' Pressed...')
        Else
          WriteLn('Key F8 Special Pressed...');
      #67:
        If Not Special Then
          WriteLn('Key ',Key,' Pressed...')
        Else
          WriteLn('Key F9 Special Pressed...');
      #68:
        If Not Special Then
          WriteLn('Key ',Key,' Pressed...')
        Else
          WriteLn('Key F10 Special Pressed...');
      Else If (Key <> #0) And Not Special Then
        WriteLn('Key ',Key,' Pressed...')
      Else If (Key <> #0) And Special Then
        WriteLn('Key ',Key,' Pressed, This is a Special Key...')
    End;
  Until (Key = #27) And Not Special
End.
0
 
LVL 48

Expert Comment

by:dbrunton
ID: 2656202
I don't think that's what he wants.  More like this.  Note this code was thrown together on the screen and not tested.

procedures DoHelp, DoFind are the procedures that are called when you press the corresponding key

procedure Menu(special_keypress : char);
begin
  case special_kepress of
     #59 : DoHelp; {F1 key pressed}
     #60 : DoFind; {F2 key pressed}
     #61 : DoExit;  {F3 key pressed}
     #107: DoCloes; {ALT-F4 key pressed}
 else
     ;   {Do Nothing}
  end;  
end;

If KeyPressed Then
  Begin
    Key := ReadKey;
    If Key = #0 then  {should really check if #224 has been entered as well}
      Begin
         Special:=True;
          Key:= ReadKey;
          Menu(Key);
             
We did use some of Whatboy's code here.  I don't thnk he'll mind.  :)      
0
 
LVL 6

Expert Comment

by:My name is Mud
ID: 2656216
OK... Let him/her decide...
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 12

Accepted Solution

by:
Hypo earned 50 total points
ID: 2656287
Here's that example again Waulsy, a bit modifyed though... ;)
Is this what you want?

regards Hypo

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.

0
 
LVL 6

Expert Comment

by:My name is Mud
ID: 2656438
I have another one...

Program KeyChecker;

Procedure HiHeadWithHammer;
begin
  Call(Hammer);
  Use.Hammer;
End;

Procedure checkKeys;
Begin
  If Key not in [pocket,desk,TV] Then
    Begin
       If Replace.Key do
         Use.Key;
       Else
         While Seek.Key Do
           HitHeadWithHammer;
    End
End;

Begin
  CheckKeys;
End.
0
 
LVL 12

Expert Comment

by:Hypo
ID: 2656553
hehehe... annoyed by the fact that my program looks very much like yours???
well... whatboy, The reason I posted my comment was because of Waulsy's old question I answered.
http://www.experts-exchange.com/jsp/qShow.jsp?ta=pascal&qid=10316655 

0
 
LVL 6

Expert Comment

by:My name is Mud
ID: 2657517
Nope...
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Many businesses neglect disaster recovery and treat it as an after-thought. I can tell you first hand that data will be lost, hard drives die, servers will be hacked, and careless (or malicious) employees can ruin your data.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

765 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