FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

KEYBOARD

Test for Function Keys


You can intercept the key codes before they are processed in PG programs and check which one it is. The best place that I found to do this is within the CANCEL filter that comes with the PG package. That routine checks for cammand-period and I ajust add more speciall key combinations t that check for Function keys as well as some custom Command-Key combinations used as shortcuts with buttons. The main code now looks like like this:
LONG IF gLongAction& = _oEvents
  LONG IF gWhat = _keyDwnEvt
' Use this next line to discover keyboard & ASCII Codes
' PRINT : PRINT  RIGHT$( HEX$({@gMessage&+2}), 4)
' This value has the key code in 1st byte
'    and the ASCII # in the 2nd byte
' This allows distintion between top row #s
'    and keypad #s, function keys, etc.
' I use it here mainly for common command buttons
'    in several windows
'  ie  NEXT, PREV, DONE, CANCEL, PROCEED, ERASE

  SELECT {@gMessage& + 2} >> 8    ' get just the 1st byte

    CASE &7B                        'Left arrow = Prev.
      IF gModifiers AND _cmdKey% THEN FN checkKeyForButton("Prev")
    CASE &7C                    'Right arrow = Next
      IF gModifiers AND _cmdKey% THEN FN checkKeyForButton("Next")
    CASE &02                   'D = Done
      IF gModifiers AND _cmdKey% THEN FN checkKeyForButton("Done")
    CASE &2F                   'Period = Cancel
      IF gModifiers AND _cmdKey% THEN FN checkKeyForButton("Cancel")
    CASE &23                   'P = Proceed (Many report windows, )
      IF gModifiers AND _cmdKey% THEN FN checkKeyForButton("Proceed")
    CASE &01                   'S = Save (Enter Scores window)
      IF gModifiers AND _cmdKey% THEN FN checkKeyForButton("Save")
    CASE &2D                   'N = New Gymnast(Setup windows)
      IF gModifiers AND _cmdKey% THEN FN checkKeyForButton("New Gymnast")
    CASE &03                   'F = Find Gymnast(Setup Gymnasts window)
      IF gModifiers AND _cmdKey% THEN FN checkKeyForButton("Find")
    CASE &0E                   'E = Erase (all setup windows)
      IF gModifiers AND _cmdKey% THEN FN checkKeyForButton("Erase")

' Here are the key codes for most special keys....
'     (add your own actions) as needed
'case &35    ' Esc key
'case &7A    ' F1 key
'case &78    ' F2 key
'case &63    ' F3 key
'case &76    ' F4 key
'case &60    ' F5 key
'case &61    ' F6 key
'case &62    ' F7 key
'case &64    ' F8 key
'case &65    ' F9 key
'case &6D    ' F10 key
'case &67    ' F11 key
'case &6F    ' F12 key
'case &69    ' F13 key
'case &68    ' F14 key
'case &71    ' F15 key

' case &74    ' Page Up key
' case &79    ' Page Down key
' case &73    ' Home key
' case &77    ' End key
' case &72    ' Help key
' case &75    ' fwd del key
' case &33    ' delete key
  END SELECT

Stu Cram

Here's a of FN I use to use FKeys. Obviously, you'll need to provide the action!
LOCAL FN doFKeys (x%)                             '(x = vKeyCode%)
  DIM result%
  'See Table 4-1 on page 30 in "Extending the Macintosh Toolbox".
  'Counting starts with A = 0, C = 8, etc.
  LONG IF gCurrentBk% = 0 AND (x% <> 97 AND x% <> 96) AND x% <> 115
    SOUND "OpSound"
    EXIT FN
  END IF
  TEXT _geneva,10,0
  SELECT x%                                       'Which fKey
    CASE 122                                      '1 --- 
     'The buttons do the same thing as the FKeys, so they get hilited!
      BUTTON #_waterTypeBtn,_markedBtn
      FN doWaterTypeBtn
      BUTTON #_waterTypeBtn,_activeBtn
    CASE 120                                      '2 --- 
      BUTTON #_waterSizeBtn,_markedBtn
      FN doWaterSizeBtn
      BUTTON #_waterSizeBtn,_activeBtn
    CASE 99                                       '3 --- 
      BUTTON #_coolerTypeBtn,_markedBtn
      FN doCoolerTypeBtn
      BUTTON #_coolerTypeBtn,_activeBtn
    CASE 118                                      '4 --- 
      BUTTON #_cupTypeBtn,_markedBtn
      FN doCupTypeBtn
      BUTTON #_cupTypeBtn,_activeBtn
    CASE 96                                       '5 --- 
      BUTTON _IDsFBtn,_markedBtn
      FN doIDs ("Product")
      DELAY 200
      BUTTON _IDsFBtn,_activeBtn
    CASE 97                                       '6 --- 
      BUTTON _EquipmentFBtn,_markedBtn
      FN doOtherRefs(_iEquipment,_false)
      DELAY 200
      BUTTON _EquipmentFBtn,_activeBtn
    CASE 98                                       '7 --- 
      BUTTON _LocationsFBtn,_markedBtn
      FN doOtherRefs(_iLocations,_false)
      DELAY 200
      BUTTON _LocationsFBtn,_activeBtn
    CASE 100                                      '8 --- 
      BUTTON _NamesFBtn,_markedBtn
      FN doOtherRefs(_iNames,_false)
      DELAY 200
      BUTTON _NamesFBtn,_activeBtn
    CASE 101                                      '9 --- 
      BUTTON _HazardsFBtn,_markedBtn
      FN doOtherRefs(_iHazards,_false)
      DELAY 200
      BUTTON _HazardsFBtn,_activeBtn
    CASE 109                                      '10 --- 
      BUTTON _MemosFBtn,_markedBtn
      FN doOtherRefs(_iMemos,_false)
      DELAY 200
      BUTTON _MemosFBtn,_activeBtn
    CASE 103                                      '11 --- 
      BUTTON _ChkRecFBtn,_markedBtn
      FN doChkRecord(_iChkRecord,_false)
      DELAY 200
      BUTTON _ChkRecFBtn,_activeBtn
      '-----------------------------------------------
    CASE 111                                      '12 --- 
      FN doHelp(0)
    CASE 105                                      '13 --- 
      BUTTON #_cutEntryBtn,_markedBtn
      FN doCutEntry
      DELAY 200
      BUTTON #_cutEntryBtn,_activeBtn
    CASE 107                                      '14 --- 
      BUTTON #_copyEntryBtn,_markedBtn
      FN doCopyEntry
      DELAY 200
      BUTTON #_copyEntryBtn,_activeBtn
    CASE 113                                      '15
      BUTTON #_pasteEntryBtn,_markedBtn
      FN doPasteEntry
      DELAY 200
      BUTTON #_pasteEntryBtn,_activeBtn
      '-----------------------------------------------
    CASE 114                                      'help
      FN doHelp(0)
    CASE 115   : FN doRouteStatus(_true)          'home
    CASE 116   : EDIT FIELD #_cupPriceEF + 4      'page up
    CASE 117   : SOUND "OpSound"                  'delete forward
    CASE 119   : FN doLockingLine1                'end
    CASE 121   : FN the1stBlankDateLine%          'page down
  END SELECT
  TEXT _monaco,9,0
END FN                                            'FN doFKeys


Following is just a part of the FN (called from the Main Event Loop) that calls FN doFKeys
  SELECT macEvnt%
    CASE _keyDwnEvt
      vKeyCode% = PEEK (EVENT + _evtMessage + 2)
      LONG IF vKeyCode% > 95 AND vKeyCode% < 123
        gWasFKey% = _true
        FN doFKeys (vKeyCode%)
      XELSE
Joe Wilkins