INKEY$ Can't Distinguish F1-F15 on Macintosh Extended Keyboard (49710)



The information in this article applies to:

  • Microsoft QuickBASIC 1.0
  • Microsoft BASIC Interpreter for Apple Macintosh 2.0
  • Microsoft BASIC Interpreter for Apple Macintosh 2.1
  • Microsoft BASIC Interpreter for Apple Macintosh 3.0
  • Microsoft BASIC Compiler

This article was previously published under Q49710

SUMMARY

The INKEY$ function returns the same value, decimal 16 (or hexadecimal 10), when any function key from F1 through F15 is pressed on a Macintosh Extended Keyboard. This means that you can trap the function keys F1 through F15, but you cannot distinguish one from another. This is a design limitation, as explained further below.

MORE INFORMATION

The only way for a program to trap keys in Macintosh QuickBASIC 1.00 is to use the INKEY$ function. This means that a program that requires key trapping must be designed to have one or more small loops that poll for keyboard input using the INKEY$ function waiting for the user to press a key. INKEY$ traps the function keys F1 through F15 but always returns the same value, decimal 16.

This behavior is a result both of how keyboard input is designed on the Macintosh and of how BASIC handles keyboard input. Key events on the Macintosh return two representations for the key:

  1. The character code, which is essentially the ASCII representation.
  2. The key code, which represents a specific key on the keyboard. The key code is different for different models of the keyboard, and it isn't affected by any of the modifier keys like the SHIFT, OPTION, or COMMAND key.
BASIC queues the character codes and ignores the key code. Because Apple designed function keys so that they always return a decimal 16 for the character code, a BASIC program cannot distinguish among the function keys by using the character code. The function keys can be differentiated only by looking at their key codes, but that information cannot be obtained in a BASIC program.

To distinguish among the function keys, you must be able to call the Toolbox routine GetNextEvent. However, GetNextEvent doesn't work from QuickBASIC (or BASIC) because QuickBASIC itself intercepts all system events before GetNextEvent can receive them. For more information on why GetNextEvent does not work from QuickBASIC, search for the word GetNextEvent.

Modification Type:MinorLast Reviewed:1/8/2003
Keywords:KB49710