_GENGRAPH

FkMax(), FkLabel(), Set Function

These functions and command are one way to use the function keys. FKMAX() and FKLABEL() tell you how many and what function keys are available. SET FUNCTION lets you define a keyboard macro and assign it to a function key.

Usage

nKeyTotal = FKMAX() cKeyName = FKLABEL( nKey )
FKMAX() simply counts the number of function keys and returns the count. Unless you SET COMPATIBLE ON, in which case it also counts the number of Ctrl and Shift combinations available and returns the total. You'd think it would be three times the number of function keys (or even more if you can use things like Ctrl+Shift+key), but in this mode, FoxPro doesn't see the F11 and F12 keys. Plus, Shift+F10, which used to bring up the macro definition dialog, doesn't get counted. It's considered unavailable. Missing F11 and F12 strikes us as carrying compatibility a little too far. Is it really necessary to duplicate the competition's bugs, too?

FKLABEL() lets you translate the number of keys into the actual labels of the keys, which you can then use in SET FUNCTION or ON KEY LABEL. With SET COMPATIBLE ON, you get all the valid combinations, too. For reasons we don't understand, the values of nKey that you can pass to FKLABEL() begin with 0, not 1. So FKLABEL(0) is "F1" and so forth. Must be C programmers at work.

Example

PROCEDURE DispFKey * Display a list of all the valid function keys * Pass "ON" or "OFF" to determine COMPATIBLE setting LPARAMETER cSetCompat    * cSetCompat determines setting for SET COMPATIBLE    * Default to current setting   LOCAL cOldCompat, nCnt cOldCompat = SET("COMPATIBLE")   IF TYPE('cSetCompat')="C" AND ;         INLIST(UPPER(cSetCompat),"ON","OFF")    SET COMPATIBLE &cSetCompat ENDIF   FOR nCnt = 1 TO FKMAX()    ?FKLABEL(nCnt-1) ENDFOR   SET COMPATIBLE &cOldCompat RETURN

Usage

SET FUNCTION nKeyNumber | cKeyLabel TO [ cCharSequence ]
SET FUNCTION assigns the specified function key a keyboard macro of the same sort you can create with the Tools | Macros dialog. (It didn't always work this way, but it's a sensible choice.) Once you assign such a macro, whenever you press that function key, FoxPro behaves as if you'd typed in the specified key sequence wherever the focus rests.

nKeyNumber corresponds not to the numbers you pass to FKLABEL(), which start with 0, but to the actual number on the function key. That is, SET FUNCTION 2 TO something-or-other is the same as SET FUNCTION F2 TO something-or-other. With COMPATIBLE ON, SET FUNCTION 12 is the same as SET FUNCTION CTRL+F2.

The sequence of characters is specified as a string and must be enclosed in quotes (unless you store it to a variable first). Use ";" to indicate a return. If you're putting a command in, you need that semicolon or the command just sits there and waits.

Before VFP 5, by default, functions F2 through F9 had keyboard macros set up when you started FoxPro. Several of these were quite useful during development. F5 executed DISPLAY STRUCTURE, F6 was DISPLAY STATUS and F7 was DISPLAY MEMORY. Tamar used these all the time. (Ted has a cat who likes to run across the keyboard.) On the other hand, we hardly ever remembered that F9 was APPEND and we had to look up F8 to find out that it was DISPLAY. By now, you're catching on that these assignments go back to the very beginnings of Xbase history. None of them belongs in any application. However, by the frequency with which we hear complaints about SET or APPEND turning up in people's data, we know that lots of people don't turn them off. CLEAR MACROS turns off these macros as well as any others you've defined or loaded. RESTORE MACROS restores either this default set or any other set you've stored away.

The new debugger added in VFP 5 has its own uses for the function keys, so the default assignments were removed. Tamar was aggravated, but she's gotten used to it. Ted never noticed because of his cat.

There is no way to determine what is stored to a function key macro programmatically. Ted's favorite macro, one to place a comment with his initials and today's date at the end of the current line of code, has to be programmed via the Record Macro dialog each day, because you cannot set macros containing control-key sequences in code. (Of course, in VFP 7, IntelliSense provides a better way to do this.)


Example

* Give the user a shortcut for entering today's date SET FUNCTION F9 TO "KEYBOARD DTOC(DATE());"

See Also

Clear Macros, On Key Label, Restore Macros, Save Macros, Set, Set Compatible


View Updates

Copyright © 2002 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. All Rights Reserved.



Hacker's Guide to Visual FoxPro 7. 0
Hackers Guide to Visual FoxPro 7.0
ISBN: 1930919220
EAN: 2147483647
Year: 2001
Pages: 899

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net