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 KeyString: String);
Public procedure KeyUp(const Key: TKey; out KeyString: String);
Public procedure Clear;

Properties

Public property Items [constKey:TKey]: boolean read GetItems;
Public property Strings [constKeyString:String]: Boolean read GetStrings;

Description

Fields

Public Keys: TKeysBooleans;

Check is a key (TKey) pressed.

This array is read-only from outside of this class! Always Keys[keyNone] = 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[keyCtrl], Keys[keyShift] etc. values.

Public procedure KeyDown(const Key: TKey; const KeyString: String);

Call when key is pressed. Pass TKey, and corresponding character (as String, since it may be UTF-8 character).

Pass Key = keyNone if this is not representable as TKey, pass KeyString = '' if this is not representable as String. But never pass both Key = keyNone and KeyString = '' (this would mean that nothing was pressed, as least nothing that can be represented by CGE).

Public procedure KeyUp(const Key: TKey; out KeyString: String);

Call when key is released. Never pass Key = keyNone 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 [constKey:TKey]: boolean read GetItems;

Check is a key (TKey) pressed. Returns the same values as are in the Keys table. It's a default property of this class, so you can write e.g. Window.Pressed[keyX] instead of Window.Pressed.Keys[keyX].

Public property Strings [constKeyString:String]: Boolean read GetStrings;

Does an UTF-8 key represented by this String is pressed. Note that internallly we only track 8-bit keys (Char) for now, but this will change some day.


Generated by PasDoc 0.16.0.