Class TInputShortcut

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type TInputShortcut = class(TObject)

Description

An input shortcut represents a keyboard and/or mouse shortcut for some command. Up to two key shortcuts may be assigned to a single item, and one mouse shortcut, and one character shortcut.

Normal "key shortcut" is identified by Keys.TKey value.

"Character shortcut" differs from "key shortcut" because it's identified by produced character. We don't deal here how this character is produced (for example, character "X" may produced on normal systems by Shift + "x" or by pressing "x" while "caps lock" is on; but this is not dealt with in this unit (it's usually provided by operating system / GUI toolkit to GLWindow unit), we just get characters passed to TMatrixNavigator.KeyDown and such methods.)

Hierarchy

Overview

Methods

Protected procedure Changed; virtual;
Public constructor Create(AKey1: TKey; AKey2: TKey; ACharacter: Char; AMouseButtonUse: boolean; AMouseButton: TMouseButton);
Public procedure MakeDefault;
Public procedure AssignFromDefault(Source: TInputShortcut);
Public procedure Assign(Source: TInputShortcut; CopyDefaults: boolean);
Public procedure MakeClear;
Public function IsPressed(KeysDown: PKeysBooleans; CharactersDown: PCharactersBooleans; const MousePressed: TMouseButtons): boolean;
Public function IsKey(Key: TKey; ACharacter: Char): boolean;
Public function IsMouseButton(AMouseButton: TMouseButton): boolean;
Public function IsEvent(MouseEvent: boolean; Key: TKey; ACharacter: Char; AMouseButton: TMouseButton): boolean;
Public function Description(const NoneString: string): string;

Properties

Public property Key1: TKey read FKey1 write SetKey1;
Public property Key2: TKey read FKey2 write SetKey2;
Public property Character: Char read FCharacter write SetCharacter;
Public property MouseButtonUse: boolean read FMouseButtonUse write SetMouseButtonUse;
Public property MouseButton: TMouseButton read FMouseButton write SetMouseButton;
Public property DefaultKey1: TKey read FDefaultKey1 write FDefaultKey1;
Public property DefaultKey2: TKey read FDefaultKey2 write FDefaultKey2;
Public property DefaultCharacter: Char read FDefaultCharacter write FDefaultCharacter;
Public property DefaultMouseButtonUse: boolean read FDefaultMouseButtonUse write FDefaultMouseButtonUse;
Public property DefaultMouseButton: TMouseButton read FDefaultMouseButton write FDefaultMouseButton;
Public property OnChanged: TInputShortcutChangedFunc read FOnChanged write FOnChanged;

Description

Methods

Protected procedure Changed; virtual;
 
Public constructor Create(AKey1: TKey; AKey2: TKey; ACharacter: Char; AMouseButtonUse: boolean; AMouseButton: TMouseButton);

Constructor. Key/mouse shortcuts passed here are interpreted as the default shortcuts (so they will be used in subsequent MakeDefault) and they are also the initial values for Key1, Key2 etc. properties.

Public procedure MakeDefault;
 
Public procedure AssignFromDefault(Source: TInputShortcut);

This assigns to this object the default values from Source.

Public procedure Assign(Source: TInputShortcut; CopyDefaults: boolean);

This copies Source properties to this object. It always copies "current" properties (Key1, Key2, Character, MouseButtonUse, MouseButton), and optionally (if CopyDefaults) also copies the DefaultXxx properties.

Public procedure MakeClear;

This sets both keys to K_None, Character to #0 and MouseButtonUse to False, effectively making this input shortcut impossible to enter by the user.

Public function IsPressed(KeysDown: PKeysBooleans; CharactersDown: PCharactersBooleans; const MousePressed: TMouseButtons): boolean;

Given a set of currently pressed keys and mouse buttons, decide whether this input is currently pressed.

You can pass Nil as KeysDown, then it will be assumed that no keys are currently pressed. (Otherwise, the contents pointed to by KeysDown pointer will never be modified; KeysDown is a pointer only to allow you to pass Nil here). Note that we assume that KeysDown behave like TGLWindow.KeysDown property, i.e. KeysDown[K_None] is always False.

Analogously, you can pass Nil as CharactersDown.

Public function IsKey(Key: TKey; ACharacter: Char): boolean;

Check does given Key or ACharacter correspond to this input shortcut. If Key = K_None and ACharacter = #0, result is always False.

Public function IsMouseButton(AMouseButton: TMouseButton): boolean;

Check does given mouse button correspond to this input shortcut. In practice, just checks MouseButtonUse and if True, compares AMouseButton with MouseButton.

Public function IsEvent(MouseEvent: boolean; Key: TKey; ACharacter: Char; AMouseButton: TMouseButton): boolean;

Check does given key/character (if not MouseEvent) or mouse button (if MouseEvent) correspond to this input shortcut.

Basically, this is a "dispatcher" that simply calls IsKey or IsMouseButton method. Depending on the MouseEvent value, some of the other parameters (Key/ACharacter or AMouseButton) are simply ignored.

This is often comfortable method if you want to squeeze calling IsKey and IsMouseButton into one procedure in the implementation — see e.g. TMatrixWalker.EventDown.

Public function Description(const NoneString: string): string;

Describe this input shortcut. If it's not active at all (like after MakeClear), we will use NoneString.

Properties

Public property Key1: TKey read FKey1 write SetKey1;

Key shortcuts for given command. You can set any of them to K_None to indicate that no key is assigned.

Public property Key2: TKey read FKey2 write SetKey2;
 
Public property Character: Char read FCharacter write SetCharacter;

Character shortcut for given command. You can set this to #0 to indicate that no character shortcut is assigned.

Public property MouseButtonUse: boolean read FMouseButtonUse write SetMouseButtonUse;

Mouse shortcut for given command. You can set MouseButtonUse to False if you don't want to use this.

Public property MouseButton: TMouseButton read FMouseButton write SetMouseButton;
 
Public property DefaultKey1: TKey read FDefaultKey1 write FDefaultKey1;

Default values for properties key/mouse. You can change them — this will change what MakeDefault does.

Note that setting these properties doesn't automatically set corresponding "current" property. E.g. DefaultKey1 := K_Space; doesn't change the value of Key1 property — only DefaultKey1 changes. You can explicitly change Key1 property, or just call MakeDefault afterwards, if you want this to happen.

Public property DefaultKey2: TKey read FDefaultKey2 write FDefaultKey2;
 
Public property DefaultCharacter: Char read FDefaultCharacter write FDefaultCharacter;
 
Public property DefaultMouseButtonUse: boolean read FDefaultMouseButtonUse write FDefaultMouseButtonUse;
 
Public property DefaultMouseButton: TMouseButton read FDefaultMouseButton write FDefaultMouseButton;
 
Public property OnChanged: TInputShortcutChangedFunc read FOnChanged write FOnChanged;

If assigned, this will be called always right after the key/character/mouse shortcut value changed. Note that this is called only when the "current" values (Key1, Key2, Character, MouseButtonUse, MouseButton) changed, and it's not called when just the DefaultXxx values changed.


Generated by PasDoc 0.11.0 on 2008-09-12 11:58:31