$if 0 ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ· PowerBASIC v3.20 ÚÄÄ´ DASoft ÇÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ· ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĶ Copyright 1995 ³ DATE: 1996-03-08 ÇÄ· ³ ³ FILE NAME FGETKEY .TXT º 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 º º ÔÍÑÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ º ³ .................................... º ÔÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ $endif '.ø.ø.ø.ø.ø.ø.ø.ø.ø.ø.ø.ø.ø.ø.ø.ø.ø.ø.ø.ø.ø.ø.ø.ø.ø.ø.ø.ø.ø.ø.ø.ø.ø.ø.ø.ø.ø.ø ' ø ø ø ø ø ø ø ø ø ø ø ø ø ø ø ø ø ø ø ø ø ø ø ø ø ø ø ø ø ø ø ø ø ø ø ø ø ø Hi, Hopefully, in this text, I will be able to endoctrinate you to the use of a small function called fGetKey%. It does NOT exist in the library but there are several importable versions of it in the help screens and you will see various versions of it throughout the .DMO files. In its simple form it looks like this: FUNCTION fGetKey% () LOCAL PUBLIC WHILE NOT INSTAT : WEND FUNCTION = CVI( INKEY$ + CHR$(0) ) END FUNCTION All it is doing here is awaiting a key-presss, converting it to an INTEGER value and returning that value. So, what's all the hubbub about? Well, as I said, this is the "basic, stripped down version". Other versions can trap incoming keys, branch the program to other tasks (like pop-up help), detect no keyboard action for a number of seconds and automatically call the blank-screen routine, or just about anything else you can think of including mouse tracks! The most important thing is does, however, is not in the function's code. It provides/forces all incoming input from the keyboard and/or mouse to pass through one, centeralized location in the program. Every routine or function MUST come through here to get a key. Once you know where things are happening it is an easy matter of taking some action on it. Two simple examples come to mind: For years I have used the pipe "|" as a data seperater in my programs. Because I need to keep this character out of my users' data I can't let them input from the keyboard. Try doing that if you are using INKEY$ in 30 different locations! Or, I once had a program that required the use of the degree sign "ø" that is NOT accessible from the keyboard except by using 248. The user was not using the pipe (because I was blocking it) so every time they pressed "|" they got "ø" and it all took one line of code for the whole program! FUNCTION fGetKey% () LOCAL PUBLIC LOCAL G% WHILE NOT INSTAT : WEND G% = CVI( INKEY$ + CHR$(0) ) IF G% = 124 THEN G% = 248 ' "|" = "ø" FUNCTION = G% END FUNCTION What this all means is greater control over your program. It also allows you to do EXACTLY the same thing as ON KEY(n) GOTO without generating 2 extra bytes of code for each command! In a large program that can be 40 or 50 thousand bytes! You can even to a passable replacement for ON TIMER if it's not critical. (Most on-screen clocks aren't) So, now you understand, hopefully, the why and we can get onto the "what" of fGetKey%. Every since I started programming I've used G$ to carry the incoming key-strokes. Then, a few years back I started using the ASCII value and finally I'm into this method which is better than anything I've seen before since it is almost foolproof! Here are some of the values for those "special" keys around the keyboard: %ESC_key = 27 ' or CVI( CHR$(027,000) ) %F01_key = (256 * 059) ' or CVI( CHR$(000,059) ) %F02_key = (256 * 060) ' or CVI( CHR$(000,060) ) %F03_key = (256 * 061) ' or CVI( CHR$(000,061) ) %F04_key = (256 * 062) ' or CVI( CHR$(000,062) ) %F05_key = (256 * 063) ' or CVI( CHR$(000,063) ) When you press F1 INKEY$ inputs CHR$(000,059); when you press ESC it sends back a single CHR$(27) so (look back at any fGetKey% here) if you take the incoming key-press, add a trailing CHR$(0), convert the whole thing to an INTEGER using CVI you end up with an almost unique value for every key or combination of keys on the keyboard. ( %CTRL_L_BRACKET and %ESC_key both equal 27, etc. ) What this means in your programs is that because we are using INTEGERs instead of strings less memory is in use, faster access to the information is obtained and easier/faster tests are made on the keys. G% = fGetKey% SELECT CASE G% CASE 32 TO 255 ' a regular key CASE %ESC_key ' see how easy it is to read when you CASE %F01_key ' use the %constants? CASE %SHIFT_F1 ' CASE %F10_key ' CASE %ALT_X ' CASE %ENTER_key CASE %CTRL_GREY5 END SELECT This all brings us down to KEYCODES.INC which is a file that contains 170 constants for the values of the "special" keys on the keyboard. There are actually 2 of these files, one is in this directory and one is in the directory with the .PBLs. The difference is that the one in this directory is/was made for human consumption while the one with the .PBLs (the one to include) is more PowerBASIC compatible. humanized Better for PowerBASIC ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ %F01_key = (256 * 059) : %F01_key = 15104 %F02_key = (256 * 060) : %F02_key = 15360 %F03_key = (256 * 061) : %F03_key = 15616 %F04_key = (256 * 062) : %F04_key = 15872 %F05_key = (256 * 063) : %F05_key = 16128 When I'm working on a unit file that will be compiled for a .PBU I don't include the whole file but only pick-out the ones to be used. This, then provides me a quick reference of which keys are used by the routines all neatly listed at the top of the code. %F01_key is also a lot easier to read in the code than CHR$(000,059) too! Now, have a look at FGETKEY.DMO, KEYCODES.INC (both) and everything should snap into place (if it hasn't already:) Happy computing! d83) The following routines use key-press values like those returned by fGetKey% fGetKey% ' get one from the keyboard buffer fAnyKey% ' pause program until a key-press (with ClearKeyboard) fPutKey% ' stuff one back into the keyboard buffer fExitKey% ' test if a key-press is present in a string of key-presses fEventKey% ' keyboard/mouse driver fKeySelect% ' menu driver fTinput% ' field/data input routine fTinputM% ' field/data input routine Mouse aware fTmenuDD? ' drop-down/pull-down menu fTmenuHOT% ' box menus fTmenuINDEX ' index menu fYesNo? ' yes/no dialogue box driver ---- And ANY routine/function that gathers data from the keyboard. ----