home *** CD-ROM | disk | FTP | other *** search
- Unit KeyBoard;
-
- { KeyBoard version 3.5b Copyright (C) 1992 Scott D. Ramsay }
-
- { Even back when I was making games for PC-Compute! I hated the fact }
- { that the keyboard can only handle one press at a time. For games, }
- { one needs to keep the SPACEBAR down (to fire) while using the arrow }
- { keys to move. The old keyboard int. Can handle this. So I wrote }
- { a new keyboard interrupt. }
- { The keyboard is taken over at startup. }
- { This Unit changes interrupts, in your own programs chain the }
- { EXITPROC pointer so when exiting the old keyboard int is restored }
- { example: }
- { Program QuickTest; }
- { }
- { Uses Keyboard; }
- { var }
- { oldexitproc : pointer; }
- { }
- { procedure cleanup; far; }
- { begin }
- { { do your cleanup here } }
- { exitproc := oldexitproc; }
- { end; }
- { }
- { begin }
- { oldexitproc := exitproc; }
- { exitproc := @cleanup; }
- { end. }
- { }
- { KEYBOARD.TPU can be used freely in commerical and non-commerical }
- { programs. As long as you don't give yourself credit for writing }
- { this portion of the code. When distributing it (free only), please }
- { include all files and samples so others may enjoy using the code. }
- { Enjoy. }
-
- interface
-
- var
- ch : char; { contains the the ASCII }
- { value of the key pressed }
- { contians #1 if non pressed }
- np : array[1..9,1..2] of boolean; { keypad, true if pressed }
- { np[7,1] - Q } { np[7,2] - home }
- { np[8,1] - W } { np[8,2] - up arrow }
- { np[9,1] - E } { np[9,2] - pgup }
- { np[4,1] - A } { np[4,2] - left arrow }
- { np[5,1] - S } { np[5,2] - 5 }
- { np[6,1] - D } { np[6,2] - right arrow }
- { np[1,1] - Z } { np[1,2] - end }
- { np[2,1] - X } { np[2,2] - down arrow }
- { np[3,1] - C } { np[2,3] - page down }
-
- { In games I mostly just use the "np" array "NumericPad" }
- { Look at your keyboard, and you'll see why it's arranged this way }
- { Think of the second index number as player 1,player 2 }
-
- portb, { current scancode value }
- { < 128 key is down }
- { hi-bit set, scan code released }
- cleared, { True if interrupt not installed }
- plus, { True if plus key is pressed }
- minus, { True if minus key is pressed }
- cold, { Set to True if you want to call }
- { the old interrupt also, this is }
- { kinda flaky. Try not to use }
- lshft,rshft, { True if shifts are pressed }
- space, { True if SPACE key is pressed }
- bspc, { True if bspc is pressed }
- funct, { True if CH is an extended scan-code }
- esc, { True if ESC key pressed }
- enter : boolean; { True if Enter is pressed }
-
- procedure clearbuffer; { Waits until CH=#1 }
- procedure clearkeyint; { Restores old keyboard int }
- procedure cli; inline($fa); { Disable ints }
- procedure sti; inline($fb); { Enable ints }
- function st(h:longint):string; { convert longint to string }
- function vl(h:string):longint; { convert string to longint }
-
- Implementation
-
- (***********************************************************************)
-
-
- If you have any problems, e-mail at:
-
- ramsays@access.digex.com
-
- The TPU units can be used with in your programs. If you want the source code, more samples or swap-talk,
- just e-mail me. I'll give sample use-code for free. Actual TPU-source
- code prices can be discussed.
-
- Scott D. Ramsay
-