Key Events Overview

  • Key events
  • Guidelines for assigning Key UP or Key Down keys
  • Details for the Key parameter

Key events

  • Key Down
  • Key Up
  • While Key Down

Guidelines for Assigning Key Up or Key Down Keys

  • You may assign most keys as a KeyDown or KeyUp event. However, when you do, the triggered procedure overrides any other function the key may have performed.
  • Do not use:
  • Ctrl, Shift, or Alt alone
  • Esc, Tab, Enter, or Print Screen either alone or in combination with other keys.
  • Ctrl+Alt+Delete
  • Ctrl+Alt+Shift+Delete
  • Ctrl+Scroll Lock
  • Ctrl+Shift+Scroll Lock
  • Ctrl+Alt+Scroll Lock
  • Pause
  • Ctrl+Pause (regardless of other modifiers like Shift and Alt)
  • You may assign a key that would normally invoke a menu or Help. If no procedure is assigned, the normal action is invoked. Keys that are affected are:
Key Accelerator Action
Ctrl+O File Open
Ctrl+P File Print
F1 Help Contents
Shift+F1 Context Help
F10 Select Frame Menu
Alt+F4 Close Window (Note: The window will close after the procedure is done.)

Details for the Key parameter

The low-order byte represents the Windows virtual keycode of the key that was pressed. For ASCII letters and numbers, this corresponds to the ASCII code for that character.

The high order byte has information about the state of the Alt, Control, and Shift keys. The other bits are currently reserved and should not be used. The values are:

GefModAlt &h01
GefModControl &h02
GefModShift &h04

To extract just the high order byte containing the modifier states and the low order byte containing the key code, you can use the following sample code:

modifiers=key / 256

keycode=key mod 256

Since the modifiers are bit values, you must use the binary AND operator to test them.

Example

If modifiers And gefModAlt Then
  ' do something
End If