Solved

Hypo please help again( FUNCTION KEYS)

Posted on 2000-03-24
7
174 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to unescape(decode) an encoded string? 5 1,353
delphi 8 619
DevExpress TcxDBLookupComboBox accent insensitive 2 977
Delphi TSQL Connection runtime creating 1 1,080
There are many Password Managers (PM) out there to choose from. PM's can help with your password habits and routines, but they should not be a crutch you rely on too heavily. I also have an article for company/enterprise PM's.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

911 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