home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Zodiac Super OZ
/
MEDIADEPOT.ISO
/
FILES
/
13
/
N_B_V203.ZIP
/
FGETKEY.DMO
< prev
next >
Wrap
Text File
|
1996-07-04
|
8KB
|
210 lines
$if 0
┌──────────────────────────╖ PowerBASIC v3.20
┌──┤ DASoft ╟──────────────────────┬──────────────────╖
│ ├──────────────────────────╢ Copyright 1995 │ DATE: 1996-03-08 ╟─╖
│ │ FILE NAME FGETKEY .DMO ║ by ╘════════════════─ ║ ║
│ │ ║ Don Schullian, Jr. ║ ║
│ ╘══════════════════════════╝ ║ ║
│ A license is hereby granted to the holder to use this source code in ║ ║
│ any program, commercial or otherwise, without receiving the express ║ ║
│ permission of the copyright holder and without paying any royalties, ║ ║
│ as long as this code is not distributed in any compilable format. ║ ║
│ IE: source code files, PowerBASIC Unit files, and printed listings ║ ║
╘═╤═════════════════════════════════════════════════════════════════════╝ ║
│ .................................... ║
╘═══════════════════════════════════════════════════════════════════════╝
this program will accept data from one file and create, format and/or test
so you can add any keys that may come into use or to create a smaller file.
InportFile$ MUST be found on the disk so it can be read in
ExportFile$ is optional. If it is NULL then no file is written.
You will notice that KEYCODES.INC the file in the DMO directory is NOT the
same as the file of the same name in ..\ directory. The file in DMO is more
humanized for easy editing while the actual file in ..\ is more ready for
PowerBASIC.
$endif
'.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°
' ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° °
$INCLUDE "DAS-NB01.INC"
InportFile$ = "DMO\KEYCODES.INC"
ExportFile$ = "..\KEYCODES.INC"
DIM KeyVal%(300), KeyName$(300) ' 300 should be enough!
COLOR 7, 0
CLS
? "┌───────────────────────────────────────────────────────────────────────
? "│ fGetKey% ()
? "│ KEYCODES.INC - DECLARED CONSTANTS FOR KEYS
? "├───────────────────────────────────────────────────────────────────────
? "│ fGetKey% and fAnyKey% are used throughout these libraries. fGetKey%
? "│ however, is NOT included in the library. You need to either import a
? "│ version of it from the help screen or write one of your own. This is
? "│ fGetKey% can be made to do many different things depending on the
? "│ requirements of your program(s). A version of fGetKey% can be found at
? "│ the bottom of this file. How it is used, what values it returns, etc.
? "│ are demonstrated here.
? "│ Have a look into KEYCODES.INC to see what values are returned for which
? "│ keys or/and you can $INCLUDE it in your program/unit files.
? "│
? "│ READ: FGETKEY.TXT
? "└─────────────────────────────────────────────────────────────────────────
IF LEN( DIR$( InportFile$ ) ) = 0 THEN ' check if file is there
PRINT "SORRY BUT I CAN'T FIND "; InportFile$ ' nope! couldn't find it
PRINT
PRINT "PLEASE FIX THE CODE THEN RUN AGAIN."
END
END IF
KeyName$(0) = "UNKNOWN KEY" ' just for display use
PRINT "READING: "; InportFile$ ' read in file
OPEN "I", #1, InportFile$ ' and parce the variable
WHILE NOT EOF(1) ' from the values
LINE INPUT #1, L$ ' if "(256 *" then the
L$ = EXTRACT$( L$, "'" ) ' value will be converted
IF LEN( L$ ) = 0 THEN ITERATE ' to it's INTEGER value
FOR P% = 1 TO 10
P$ = fGetPiece$( L$, 58, P% )
P$ = RTRIM$( LTRIM$( P$ ) )
IF P$ = "" THEN EXIT FOR
IF ASCII( P$ ) <> 37 THEN ITERATE
INCR Last%
KeyName$(Last%) = EXTRACT$( P$, "=" )
KeyName$(Last%) = RTRIM$( KeyName$(Last%) )
LongName% = MAX%( LongName%, LEN( KeyName$(Last%) ) )
P$ = fGetPiece$( P$, 61, 2 )
P$ = RTRIM$( LTRIM$( P$, ANY " (" ), ANY " )" )
X% = INSTR( P$, "*" )
KeyVal%(Last%) = VAL( MID$( P$, X%+1 ) )
IF X% > 0 THEN SHIFT LEFT KeyVal%(Last%), 8
NEXT
WEND
CLOSE #1
INCR LongName%
D$ = SPACE$( LongName% ) ' longest name
FOR X% = 1 TO Last% ' pad names to
KeyName$(X%) = LEFT$( KeyName$(X%) + D$, LongName% ) ' equal length
NEXT
ARRAY SORT KeyName$(1) FOR Last%, COLLATE UCASE, TAGARRAY KeyVal%()
IF ( LEN( ExportFile$ ) > 0 ) AND _ ' export file creation
( ExportFile$ <> InportFile$ ) THEN
PRINT "WRITING: "; ExportFile$
OPEN "O", #1, ExportFile$
FOR X% = 1 TO Last%
D$ = KeyName$(X%) + "= &h" + fHEX$( KeyVal%(X%), 2 )
INCR X%, 1
IF X% =< Last% THEN
D$ = D$ + " : "
D$ = D$ + KeyName$(X%) + "= &h" + fHEX$(KeyVal%(X%), 2 )
END IF
PRINT #1, D$
NEXT
CLOSE #1
END IF
PRINT : PRINT "PRESS ANY KEY TO CONTINUE" ' ready to ROCK!
fGetKey
' ─────────────────────────────────────────────────────────────────────────
' ──── test menu
' ─────────────────────────────────────────────────────────────────────────
MENU_PRINT:
CLS
PRINT "(1) TEST ALL
PRINT "(2) START AT ....
PRINT "(3) RANDOM KEYS
PRINT "(Q) QUIT
MENU_LOOP:
SELECT CASE fGetKey%
CASE 49 : X% = 1 : GOTO TEST_ALL ' 1
CASE 50 : : GOTO START_WHERE ' 2
CASE 51 : : GOTO RANDOM_KEYS ' 3
CASE 81, 113 : GOTO BYEBYE ' Q
END SELECT
BEEP
GOTO MENU_LOOP
' ─────────────────────────────────────────────────────────────────────────
' ──── end of program
' ─────────────────────────────────────────────────────────────────────────
BYEBYE:
CLS
END
' ─────────────────────────────────────────────────────────────────────────
' ──── start where ever X% is in the list
' ─────────────────────────────────────────────────────────────────────────
TEST_ALL:
CLS
PRINT "PRESS <Q> TO QUIT"
PRINT "PRESS THE REQUESTED KEY.
PRINT "IF YOU HEAR A <BEEP> THERE IS/HAS BEEN AN ERROR"
DO
LOCATE 5, 1 : PRINT "PRESS: "; KeyName$(X%)
G% = fGetKey%
IF ( G% = 81 ) OR ( G% = 113 ) THEN EXIT LOOP
IF G% = KeyVal%(X%) THEN INCR X% ELSE BEEP
LOOP UNTIL X% > Last%
GOTO MENU_PRINT
' ─────────────────────────────────────────────────────────────────────────
' ──── start in the middle of the list
' ─────────────────────────────────────────────────────────────────────────
START_WHERE:
CLS
PRINT "PRESS THE STARTING KEY...."
PRINT "PRESS <Q> TO QUIT"
DO
G% = fGetKey%
ARRAY SCAN KeyVal%(1) FOR Last%, = G%, TO X%
IF X% > 0 THEN GOTO TEST_ALL ELSE BEEP
LOOP UNTIL ( G% = 81 ) OR ( G% = 113 )
GOTO MENU_PRINT
' ─────────────────────────────────────────────────────────────────────────
' ──── let's you press keys & tells you if they exist in the list or not
' ─────────────────────────────────────────────────────────────────────────
RANDOM_KEYS:
DO
CLS
PRINT "PRESS <Q> TO QUIT"
LOCATE 3, 1 : PRINT "PRESS A KEY NOW"
G% = fGetKey%
IF ( G% = 81 ) OR ( G% = 113 ) THEN EXIT LOOP
ARRAY SCAN KeyVal%(1) FOR Last%, = G%, TO X%
PRINT "YOU PRESSED "; KeyName$(X%);
PRINT " THIS KEY'S VALUE IS &h"; fHex$( G%, 2 )
PRINT
PRINT "PRESS THE <ANY> KEY TO CONTINUE"
fGetKey%
LOOP
GOTO MENU_PRINT
' ─────────────────────────────────────────────────────────────────────────
' ─── this version of fGetKey% clears the keyboard buffer upon each
' ─── call and, there by, is a copy of fAnyKey%
' ─────────────────────────────────────────────────────────────────────────
FUNCTION fGetKey% () LOCAL PUBLIC ' return key-value
LOCAL G$ '
'
WHILE INSTAT : G$ = INKEY$ : WEND ' clear keyboard buffer
WHILE NOT INSTAT : WEND ' await a key-press
FUNCTION = CVI( INKEY$ + CHR$(0) ) ' convert to INTEGER value
'
END FUNCTION '