Solved

Hypo please help again( FUNCTION KEYS)

Posted on 2000-03-24
7
171 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
Comment Utility
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 47

Expert Comment

by:dbrunton
Comment Utility
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
Comment Utility
OK... Let him/her decide...
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 12

Accepted Solution

by:
Hypo earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Nope...
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article will show you how to create an ISO CD-ROM/DVD-ROM image (*.iso), and MD5 checksum signature, for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5). It's a good idea to compare checksums, because many installations fail because of a corr…
HOW TO: Upload an ISO image to a VMware datastore for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere Host Client, and checking its MD5 checksum signature is correct.  It's a good idea to compare checksums, because many installat…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

771 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

14 Experts available now in Live!

Get 1:1 Help Now