Class TKeysPressed

Unit

Declaration

type TKeysPressed = class(TObject)

Description

Tracking the "pressed" state of keys. Allows you to query is key (TKey) pressed, and is some character (Char type) pressed.

Hierarchy

  • TObject
  • TKeysPressed

Overview

Fields

Public Keys: TKeysBooleans;
Public Characters: TCharactersBooleans;

Methods

Public function Modifiers: TModifierKeys;
Public procedure KeyDown(const Key: TKey; const CharKey: char);
Public procedure KeyUp(const Key: TKey; out CharKey: char);
Public procedure Clear;

Properties

Public property Items [Key:TKey]: boolean read GetItems;

Description

Fields

Public Keys: TKeysBooleans;

Check is a key (TKey) pressed.

This array is read-only from outside of this class! Always Keys[K_None] = false.

Public Characters: TCharactersBooleans;

Check is a character pressed.

This array is read-only from outside of this class! Always Characters[#0] = false.

Note that since a given character may be generated by various key combinations, this doesn't work as reliably as Keys array. For example, consider pressing a, then shift, then releasing a — for a short time character 'A', and not 'a', should be pressed.

Although we do our best (have some mapping tables to track characters), and in practice this works Ok. But still checking for keys on Keys array, when possible, is advised.

Methods

Public function Modifiers: TModifierKeys;

Check which modifier keys are pressed. The result it based on current Keys[K_Ctrl], Keys[K_Shift] etc. values.

Public procedure KeyDown(const Key: TKey; const CharKey: char);

Call when key is pressed. Pass TKey, and corresponding character (Char).

Pass Key = K_None if this is not representable as TKey, pass CharKey = #0 if this is not representable as char. But never pass both Key = K_None and CharKey = #0 (this would have no meaning).

Public procedure KeyUp(const Key: TKey; out CharKey: char);

Call when key is released. Never pass Key = K_None here.

It returns which character was released as a consequence of this key release.

Public procedure Clear;

Mark all keys as released. That is, this sets all Keys and Characters items to False. Also resets internal arrays used to track Characters from KeyDown and KeyUp.

Properties

Public property Items [Key:TKey]: boolean read GetItems;

Check is a key (TKey) pressed.

Returns the same values as are in the Keys table. Although this is more comfortable: it's a default property of this class, so you can write simply KeysPressed[K_X] instead of KeysPressed.Keys[K_X].


Generated by PasDoc 0.15.0.