?
Solved

Hypo please help again( FUNCTION KEYS)

Posted on 2000-03-24
7
Medium Priority
?
192 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 49

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
On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

 
LVL 12

Accepted Solution

by:
Hypo earned 150 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
The top devops trends for 2017 are focused on improved deployment frequency, decreased lead time for change and decreased MTTR.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

770 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