🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.modula2
2 messages
2 total messages Started by Richard A Creed Tue, 16 Apr 1996 19:59
Help - Dedicating keys
#3486
Author: Richard A Creed
Date: Tue, 16 Apr 1996 19:59
62 lines
2141 bytes
Any help most willingly received :

I'm using FST 3.5.

I would like to make one or more function keys availiable in a game
program I have written, sort of:       F1 - Help (opens & a window)
                                       F2 - Rules (opens a window)
                                       F3 - Exit Programme
(and perhaps make the esc key availiable to close the windows). 

I don't have any problem with the windows but I can't work out how
to dedicate a key so that it 

        a) Remains availiable throughout the program
        b) Doesn't get muddled up with other keypresses.

i.e. is permanently availiable, and is independent of any other
keyboard activity (save perhaps the esc key). 
        
I've experimented with KeyPressed() and come up with this test
module which will scroll 'blah' on the screen until I press F1:

MODULE TestKey2;

FROM InOut IMPORT WriteString;
FROM Keyboard IMPORT KeyPressed,GetFunKey,F1;

VAR
        GotKey :   CARDINAL;

PROCEDURE GetF1Key( VAR Key: CARDINAL );
  BEGIN
    IF KeyPressed() THEN
      GetFunKey(Key);
    ELSE
      Key := 0; (*or any other value*)
    END;
  END GetNoWait;


BEGIN
        GotKey  := 0;
        WHILE (GotKey <> 429) DO
                GetF1Key(GotKey);
                WriteString("blah ");
        END;

END TestKey2.
         
but every way that I've tried to implement the principle in my real
program it seems to take the first keypress, then sit and wait for
F1, then never be seen again. I understand why it does this,
& I realise that I was barking up the wrong tree, but I could do
with directions to the right one. 

Thanks, and with hope

Richard.

Richard Creed is at		creed@bigsilver.win-uk.net
	& once a week at	cr589@gre.ac.uk 
             & always ?         http://www.gre.ac.uk/~cr589/
Re: Help - Dedicating keys
#3499
Author: Peter Moylan
Date: Thu, 18 Apr 1996 05:06
35 lines
2049 bytes
Richard A Creed (creed@bigsilver.win-uk.net) wrote:

>I would like to make one or more function keys availiable in a game
>program I have written, sort of:       F1 - Help (opens & a window)
>                                       F2 - Rules (opens a window)
>                                       F3 - Exit Programme
>(and perhaps make the esc key availiable to close the windows). 

One traditional solution is to put the KeuPressed() call in
your main loop, or somewhere where it's going to be executed
frequently while the program is doing its other things, and
then when a key is pressed you save the character value
somewhere, and take a look at the saved value at some
appropriate later place - probably at a place where you were
going to get some keyboard input anyway.

A superior solution is to write a separate thread for keyboard
input, so that you can deal with keypresses asynchronously
with other work.

The most flexible approach is to write your own keyboard
handler, including your own interrupt routine, but of course
it's a fair amount of work to get that right.

You can get some hints by looking at the PMOS source code,
available by following the links in my signature below.
Look particularly at modules Keyboard and MultiScreen.

--
Peter Moylan                           peter@ee.newcastle.edu.au
                  http://www.eng.newcastle.edu.au/ee/Moylan.html
OS/2 freeware list at 
      http://www.eng.newcastle.edu.au/ee/Moylan/os2/os2info.html
Modula-2 information at
      http://www.eng.newcastle.edu.au/ee/Moylan/m2/Modula2.html
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads