Event fired when any key is pressed while the control has focus.

Parameters

<virtual key expN>

The Windows virtual-key code of the key released. For a list of virtual-key codes, see the Win32 Programmer’s Reference (search for "Virtual-key Codes" in the index).

<repeat count expN>

The number of times the keystroke is repeated based on how long the key is held down.

<key data expN>

A double-byte value that contains information about the key released, stored in separate bits. The bits of this parameter contain the following information:

Bit numbers

Description

0–7

Keyboard scan code (OEM dependent)

8

Extended key (1 if true) such as right Alt and Ctrl, and numbers on numeric keypad

9–12

Reserved

13

Context code: always 0 for onKeyDown

14

Previous key state: 1 if key was held down

15

Transition state: always 0 for onKeyDown

Property of

PaintBox

Description

Use onKeyDown and onKeyUp for complete control of keystrokes while a PaintBox object has focus. Each key is treated separately, with none of their normal relationships, and pressing and releasing the key are two separate actions. For example, holding down Shift and pressing the A key is normally interpreted as a capital "A". With onKeyDown and onKeyUp:

onKeyDown fires when the Shift is pressed

onKeyDown continues to fire as the Shift is held down

onKeyDown fires when the A is pressed

onKeyDown continues to fire if the A is held down

onKeyUp fires when the A is released

Releasing a key stops the repeat action of onKeyDown for the Shift key

onKeyUp fires when the Shift is released

To know that this was a capital "A", you would have to keep track of the fact that the Shift key was down when the A key was pressed.

A similar event, onChar is used when you want the PaintBox to respond to normal "printable" characters. For example, onChar would fire just once, getting the ASCII code for the capital "A". onKeyDown and onKeyUp deal with Windows virtual-key codes, which are not the same as the key character value in many cases.