home *** CD-ROM | disk | FTP | other *** search
- {The question has been asked of how the game MEGAROIDS from Megamax can
- handle _multiple_ keypresses simultaniously and still sort out when
- each key has been pressed and released individually. The following
- program shows one possible solution. Use it as you see fit, adapt it,
- play with it, and let me see all of your great games you come up with!
- NOTE: Some may say 'Why not simply use an event routine or a GEMDOS
- call?' That works most of the time, but this routine will return not
- only multiple key presses, but also the SHIFT,CONTROL,ALT,CAPS_LOCK and
- all Function keys _individually_ which the various conin calls will not!}
-
- {$ P-, R- } {MUST turn range and bounds checking off!}
- PROGRAM PEEKKEY;
- VAR Key : INTEGER ; { Used to store value of key pressed}
-
- FUNCTION Super ( Address : Long_INTEGER ) : Long_INTEGER ;
- GEMDOS( $20 ) ; { Switches in/out of SUPERVISOR Mode!!! }
-
- FUNCTION Peek( Address : Long_INTEGER ) : BYTE ;
- VAR SuperStack : Long_INTEGER ;{ Save this to return to USER mode.}
- Switch_em : RECORD { A weird looking variable declaration}
- CASE BOOLEAN of { but the only way it works in Pascal}
- False : ( L_Int : Long_INTEGER ) ;
- True : ( ptr : ^INTEGER) ;
- END ; {RECORD}
- Temp : INTEGER ;
- BEGIN
- SuperStack := Super( 0 ) ; { Enter SUPERVISOR Mode; must use '0'}
- Switch_em.L_Int := Address ; {Change Long to pointer }
- Temp := Switch_em.ptr^ ; {get what it points to }
- SuperStack := Super(SuperStack); { MUST go back to user mode}
- Peek := ShR(Temp,8) ; {Then give Key the right byte}
- END ; {Peek}
-
- BEGIN {Main}
- While Key <> $10 {The 'Q' key} DO
- BEGIN
- Key := Peek( $FFFC02 ) ; { Find HARDWARE key-code}
- Writeln ( Key :2:H) ; { Output results in HEX }
- END ; {While; loop again}
- END. {Main}
-
- { ADDITIONAL NOTE: The value stored in $FFFC02 will be between 0 & 114 ($72)
- when a key is pressed. Then when _that_ key is _released_ the original value
- + 128 ($80) is returned. I.E. pressing the 'Q' key sends 16 ($10), releasing
- it gives 144 ($90). This means _any_ number of keys can be pressed together!
- The other values, those 115 thru 127, inclusive, and over 242 are mostly
- related to mouse events and the keyboard processor and should not be passed.}
- { Mark_Kelling }
- əəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəə