Gorilla.Controller.Input
Unit Gorilla.Controller.Input.pasClasses
- TGorillaInputMessageBuffer = class ( TObject )
- TGorillaInputHandler = class ( TThread )
- TGorillaHotKeyInputItem = class ( TCollectionItem )
- TGorillaHotKeyCombinations = class ( TOwnedCollection )
- TGorillaHotKeyItem = class ( TCollectionItem )
- TGorillaHotKeyCollection = class ( TOwnedCollection )
- TGorillaInputSequenceHotKeyItem = class ( TCollectionItem )
- TGorillaInputSequenceHotKeyCollection = class ( TOwnedCollection )
- TGorillaInputSequenceItem = class ( TCollectionItem )
- TGorillaInputSequenceCollection = class ( TOwnedCollection )
- TGorillaInputThread = class ( TThread )
- TGorillaInputController = class ( TGorillaController )
Records
- record TGorillaHotKeyInputRaw
- record TGorillaHotKeyRaw
- record TGorillaInputMessage
- record TGorillaInputSequenceBufferItem
Mics. types
- type PGorillaHotKeyInputRaw = pointer to TGorillaHotKeyInputRaw;
- type TGorillaInputHandlerClass = class of TGorillaInputHandler;
TGorillaHotKeyInputRaw
Fields
Methods
- public procedure Sort
(
)
;
In the end all inputs need to be sorted from low to high value.
- public function Contains
(
const
AInput :
TGorillaHotKeyInputRaw
)
: Boolean
;
Compares both inputs to verify if AInput exists in Self.
- public function ToString ( ) : string ;
TGorillaHotKeyRaw
Fields
Methods
- public function Create ( ) : TGorillaHotKeyRaw ; static;
- public procedure AddInput
(
const
AInput :
TGorillaHotKeyInputItem
)
;
Adds a collection item to raw format
- public procedure Sort
(
)
;
In the end all inputs need to be sorted from low to high value.
- public function GetWeight
(
)
: Integer
;
Returns the weight / importance of a raw hotkey. Due to double declaration of input codes, we need a priority handling done by the hotkey weights. The more input codes are used, the more important the hotkey is.
- public function Contains
(
const
AKey :
TGorillaHotKeyRaw
)
: Boolean
;
Checks if the supplied raw key is available in the source raw key. This is used for none explicit hotkey search.
- public function ToString
(
)
: string
;
Outputs the structure as string for debugging purposes.
TGorillaInputMessage
TGorillaInputMessageBuffer
A stack buffer for storing a limited number of inputs.
Ancestors
Members
Fields
Methods
- public constructor Create ( ) ;
- public destructor Destroy ( ) ;
- public procedure Lock ( ) ;
- public procedure Unlock ( ) ;
- public procedure Clear ( ) ;
- public procedure ClearSelectedMessages ( AMode : TGorillaInputMode ) ;
- public procedure Add ( const AMessage : TGorillaInputMessage ) ; virtual;
- public procedure Remove ( const ACode : NativeInt ) ; virtual;
- public function Get ( const ACode : NativeInt; out AMessage : TGorillaInputMessage ) : Boolean ; virtual;
- public function Contains ( const ACode : NativeInt ) : Boolean ; virtual;
- public function Count ( ) : Integer ;
- public function GetRawKey ( const AMode : TGorillaInputMode ) : TGorillaHotKeyInputRaw ; virtual;
TGorillaInputHandler
Custom input handler class as basis class for keyboard and gamepad handlers.
Remarks
The handler registers itself in constructor and unregisters itself on destructor.Ancestors
Members
Fields
- protected FController :
TGorillaInputController
- protected FKind :
TGorillaInputDeviceType
- protected FEnabled :
Boolean
- protected FSensitivity :
Integer
- protected FBuffer :
TGorillaInputMessageBuffer
- protected FChanged :
Boolean
- protected FMeasure :
TStopwatch
Methods
- public constructor Create ( ACtrl : TGorillaInputController ) ;
- public destructor Destroy ( ) ;
- protected procedure SetEnabled ( const AValue : Boolean ) ; virtual;
- protected procedure SetSensitivity ( const AValue : Integer ) ; virtual;
- protected procedure Execute ( ) ; override;
- protected procedure DoChange ( const AMode : TGorillaInputMode ) ; virtual;
- protected procedure DoBeginExecute ( ) ; abstract virtual;
- protected procedure DoEndExecute ( ) ; abstract virtual;
- protected procedure DoRequestInput ( ) ; abstract virtual;
- public function GetDeviceKind ( ) : TGorillaInputDeviceType ; class abstract virtual;
- public procedure Changed
(
const
AMode :
TGorillaInputMode
)
;
Called by the handler itself, when the buffer has changed and the input controller needs to check for hotkeys.
Properties
TGorillaHotKeyInputItem
The combination item is a part of the combination collection, representing a virtual keyboard, virtual gamepad or mouse event.
Ancestors
Members
Fields
Methods
- protected function GetDisplayName ( ) : string ; override;
- protected procedure SetDisplayName ( const AValue : string ) ; override;
- protected procedure SetKind ( const AValue : TGorillaInputDeviceType ) ;
- protected procedure SetCode ( const AValue : NativeInt ) ;
- protected procedure DoUpdate ( ) ; virtual;
- public procedure Assign ( Source : TPersistent ) ; override;
Properties
TGorillaHotKeyCombinations
Is the collection which holds the input combination.
Ancestors
Members
Properties
TGorillaHotKeyItem
Setup input combinations to react on specific input combinations. It is possible to combine different input devices, f.e. "E" + "Right Mouse Click"
Ancestors
Members
Fields
- protected FName :
string
- protected FEnabled :
Boolean
- protected FTag :
NativeInt
- protected FTriggerOnActivate :
Boolean
- protected FTriggerOnDeactivate :
Boolean
- protected FCombinations :
TGorillaHotKeyCombinations
- protected FLockTime :
Cardinal
- protected FLastTriggerTime :
Int64
- protected FAction :
TAction
- protected FOnTriggered :
TGorillaOnHotKeyTriggered
Methods
- public constructor Create ( ACollection : TCollection ) ;
- public destructor Destroy ( ) ;
- protected procedure SetCombinations ( const AValue : TGorillaHotKeyCombinations ) ; virtual;
- protected function GetDisplayName ( ) : string ; override;
- protected procedure SetDisplayName ( const AValue : string ) ; override;
- protected procedure SetEnabled ( const AValue : Boolean ) ; virtual;
- protected procedure SetTriggerOnActivate ( const AValue : Boolean ) ; virtual;
- protected procedure SetTriggerOnDeactivate ( const AValue : Boolean ) ; virtual;
- public procedure ClearInputs
(
)
;
Clears all added inputs
- public procedure Update
(
)
;
In case an existing hotkey was changed, you need to update its rawmap. Call this method to rebuild the rawmap of the hotkey.
- public function AddInput
(
const
AKind :
TGorillaInputDeviceType; const
ACode :
NativeInt
)
: TGorillaHotKeyInputItem
;
Adds an input as part of the hotkey combination
- public function GetOrAddInput
(
const
AKind :
TGorillaInputDeviceType; const
ACode :
NativeInt
)
: TGorillaHotKeyInputItem
;
Tries to return an existing input hotkey or if it doesnt exist, it will add as new input information.
- public function IndexOfInput
(
const
AKind :
TGorillaInputDeviceType; const
ACode :
NativeInt
)
: Integer
;
Returns the index of hotkey input in collection. In case it doesnt exist, the method will return -1.
- public function GetRawKey
(
)
: TGorillaHotKeyRaw
;
Returns the binary format of a hotkey combination.
- public procedure Trigger
(
const
ACurrentInput :
TGorillaHotKeyRaw; const
AMode :
TGorillaInputMode
)
;
virtual;
You can trigger manually a specific hotkey for simulation purposes.
- public function TriggerSync
(
const
ACurrentInput :
TGorillaHotKeyRaw; const
AMode :
TGorillaInputMode
)
: Boolean
;
virtual;
You can trigger manually a specific hotkey for simulation purposes. The method will automatically be synchronized with the main thread.
Properties
- public Tag : NativeInt
- published Name : string
- published Enabled : Boolean
Defines if the hotkey is enabled or not. If not, it will not be considered while hotkey detection.
read FEnabled
write SetEnabled - published TriggerOnActivate : Boolean
Defines if the hotkey getting triggered when all inputs are activated (f.e. keydown).
read FTriggerOnActivate
write SetTriggerOnActivate - published TriggerOnDeactivate : Boolean
Defines if the hotkey getting triggered when all inputs are deactivated (f.e. key up)
read FTriggerOnDeactivate
write SetTriggerOnDeactivate - published Combinations : TGorillaHotKeyCombinations
A collection with all components setting up this specific input combination.
read FCombinations
write SetCombinations - published Action : TAction
- published LockTime : Cardinal
TGorillaHotKeyCollection
Provides a collection of hotkey items, where keyboard, mouse and gamepad inputs can be combined.
Ancestors
Members
Fields
- protected FUpdateRawMap :
Boolean
- protected FOnActivatedRawMap :
TGorillaRawHotKeyMap
- protected FOnDeactivatedRawMap :
TGorillaRawHotKeyMap
Methods
- public destructor Destroy ( ) ;
- public procedure Assign ( Source : TPersistent ) ; override;
- public procedure SetUpdateRawMap
(
)
;
Call this method to flag the hotkey collection for updating the raw keymap.
- public procedure UpdateRawMap
(
)
;
Clears the previous raw map, creates a new rawkey for each hotkey and adds it to the hashmap. This method getting called by the TGorillaInputController.Execute method.
TGorillaInputSequenceHotKeyItem
A linked hotkey inside of the sequence hotkey collection.
Ancestors
Members
Fields
Methods
Properties
TGorillaInputSequenceHotKeyCollection
This kind of collection holds the hotkeys for triggering a specific sequence.
Ancestors
TGorillaInputSequenceItem
A input sequence is a descriptive plan for executing hotkeys one after another.
Ancestors
Members
Fields
- protected FName :
string
- protected FEnabled :
Boolean
- protected FSensitivity :
Integer
- protected FHotKeys :
TGorillaInputSequenceHotKeyCollection
- protected FOnTriggered :
TOnGorillaInputSequenceTriggered
- protected FAction :
TAction
Methods
- public constructor Create ( ACollection : TCollection ) ;
- public destructor Destroy ( ) ;
- protected procedure SetHotKeys ( const AValue : TGorillaInputSequenceHotKeyCollection ) ; virtual;
- protected function GetDisplayName ( ) : string ; override;
- protected procedure SetDisplayName ( const AValue : string ) ; override;
- public procedure Assign ( Source : TPersistent ) ; override;
- public procedure Trigger
(
)
;
virtual;
Trigger a specific sequence manually. Used for simlution purposes.
- public procedure TriggerSync
(
)
;
virtual;
Trigger a specific sequence manually. Used for simlution purposes. The method will be automatically synced with main thread.
Properties
TGorillaInputSequenceCollection
A input sequence collection contains a number of sequence item, which hold a serial execution plan for hotkeys.
Ancestors
TGorillaInputThread
The input thread checks for hotkeys and sequences and dispatches those feedbacks to main thread. It is unperformant to this in main thread.
Ancestors
Members
Fields
Methods
- public constructor Create ( const AController : TGorillaInputController ) ;
- public destructor Destroy ( ) ;
- protected procedure Execute ( ) ; override;
- protected procedure LockController ( ) ;
- protected procedure UnlockController ( ) ;
- protected procedure DoCleanupDeactivatedMessages
(
)
;
We need to cleanup deactivation messages, because those shall only be called once.
- protected procedure DoExecuteSequenceDetection ( ) ; virtual;
- protected procedure DoPushHotKeyToSequenceBuffer ( const AHotKey : TGorillaHotKeyItem ) ; virtual;
- protected procedure CheckForHotKeys
(
const
AMode :
TGorillaInputMode
)
;
Method getting called on FEvent set by handlers. The routine will check the controllers hotkey collection for activated & deactivated hotkeys.
TGorillaInputController
The input controller handles keyboard or gamepad input.
Remarks
By this asynchronous feedback component fast input controlling is possible.Ancestors
Members
Fields
- protected FClassLock :
TCriticalSection
- protected FHandlerClasses :
TGorillaInputHandlerClassList
- protected FCS :
TCriticalSection
- protected FThread :
TGorillaInputThread
- protected FSupported :
TGorillaInputDeviceTypes
- protected FHandlers :
TGorillaInputHandlerList
- protected FHotKeys :
TGorillaHotKeyCollection
- protected FSequences :
TGorillaInputSequenceCollection
- protected FSequenceBuffer :
TGorillaInputSequenceBuffer
- protected FOnMouseDown :
TGorillaInputMouseEvent
- protected FOnMouseUp :
TGorillaInputMouseEvent
- protected FOnMouseDblClick :
TGorillaInputMouseEvent
- protected FOnMouseMove :
TGorillaInputMouseMoveEvent
- protected FOnMouseWheel :
TGorillaInputMouseWheelEvent
- protected FOnKeyDown :
TGorillaInputKeyEvent
- protected FOnKeyUp :
TGorillaInputKeyEvent
- protected FOnGamePadConnect :
TGorillaInputGamePadEvent
- protected FOnGamePadDisconnect :
TGorillaInputGamePadEvent
- protected FOnGamePadButtonDown :
TGorillaInputGamePadButtonEvent
- protected FOnGamePadButtonUp :
TGorillaInputGamePadButtonEvent
- protected FOnGamePadTrigger :
TGorillaInputGamePadTriggerEvent
- protected FOnGamePadFeedback :
TGorillaInputGamePadFeedbackEvent
Methods
- public constructor Create ( AOwner : TComponent ) ;
- public destructor Destroy ( ) ;
- protected procedure SetSequences ( const AValue : TGorillaInputSequenceCollection ) ; virtual;
- protected procedure SetHotKeys ( const AValue : TGorillaHotKeyCollection ) ; virtual;
- protected procedure SetEnabled ( AValue : Boolean ) ; override;
- protected function GetEnabled ( ) : Boolean ; override;
- protected procedure SetSupported ( const AValue : TGorillaInputDeviceTypes ) ; virtual;
- protected procedure SetupHandlers
(
)
;
virtual;
Creates a handler for each registered handler class.
- protected procedure FreeHandlers
(
)
;
virtual;
Stops all handler threads and removes them from handlers list.
- protected procedure RegisterHandler
(
const
AHandler :
TGorillaInputHandler
)
;
virtual;
Registers threadsafe a specific handler in the controller.
- protected procedure UnregisterHandler
(
const
AHandler :
TGorillaInputHandler
)
;
virtual;
Unregisters threadsafe a specific handler in the controller.
- protected procedure DoClearSequenceBuffer
(
)
;
virtual;
Clears the sequence buffer (threadsafe).
- public procedure RegisterHandlerClass
(
const
AClass :
TGorillaInputHandlerClass
)
;
class virtual;
Registers a specific handler class in the input controller management.
- public procedure UnregisterHandlerClass
(
const
AClass :
TGorillaInputHandlerClass
)
;
class virtual;
Unregisters a specific handler class from input controller management.
- public procedure Initialize
(
)
;
class virtual;
Used to create available handler classes on unit initialization.
- public procedure Finalize
(
)
;
class virtual;
Used to destroy all registered handler classes on unit finalization.
- public function GetHandler
(
const
ADevice :
TGorillaInputDeviceType
)
: TGorillaInputHandler
;
virtual;
Request a specific input handler defined by the supplied type. If no handler with this device type can be found, the method returns nil.
- public function AddHotKey
(
const
AName :
string
)
: TGorillaHotKeyItem
;
virtual;
Adds a new empty hotkey item to the collection. You need to add inputs to this item afterwards.
- public function GetOrAddHotKey
(
const
AName :
string
)
: TGorillaHotKeyItem
;
virtual;
Tries to get an eventually existing hotkey or tries to add as new hotkey, if it doesnt exist.
- public function IndexOfHotKey
(
const
AName :
string
)
: Integer
;
overload virtual;
Tries to find a hotkey by name in collection and returns its index, otherwise it will return -1.
- public function IndexOfHotKey
(
const
AKey :
TGorillaHotKeyItem
)
: Integer
;
overload virtual;
Tries to find a hotkey by the instance itself in collection and returns its index, otherwise it will return -1.
- public function HotKeyExists
(
const
AName :
string
)
: Boolean
;
virtual;
Checks if a hotkey with a specific name already exists.
- public procedure RemoveHotKey
(
const
AName :
string
)
;
overload virtual;
Removes a hotkey from collection by its name.
- public procedure RemoveHotKey
(
const
AKey :
TGorillaHotKeyItem
)
;
overload virtual;
Removes a hotkey from collection by the instance itself.
- public function AddSequence
(
const
AName :
string; const
AHotKeys :
TArray<Gorilla.Controller.Input.TGorillaHotKeyItem>
)
: TGorillaInputSequenceItem
;
virtual;
Adds a new hotkey sequence to the input controller. In case no hotkeys are supplied, the method returns nil.
- public function GetPersistentMessage
(
const
ADevice :
TGorillaInputDeviceType; const
ACode :
NativeInt; out
AMessage :
TGorillaInputMessage
)
: Boolean
;
virtual;
The system supports persistent messages like the mouse position.
- public function GetLastMousePosition ( out APos : TPoint ) : Boolean ;
- public function GetLastGamePadTriggers ( out APos : TPoint ) : Boolean ;
- public function GetLastGamePadThumbstickPosLeft ( out APos : TPointF ) : Boolean ;
- public function GetLastGamePadThumbstickPosRight ( out APos : TPointF ) : Boolean ;
- public procedure NotifyMessage
(
const
AMode :
TGorillaInputMode
)
;
virtual;
In case a handler has detected some input, it will call this method to inform the input thread to check for hotkeys and sequences.
- public procedure DispatchKeyMessage
(
const
AMode :
TGorillaInputMode; const
AKey :
Integer
)
;
virtual;
Raw keyboard message dispatch method, which forwards data threadsafe to assigned event callback.
- public procedure DispatchMouseMessage
(
const
AEvent :
TGorillaMouseState; const
AStates :
TGorillaMouseStates; const
APos :
TPointF; const
AFlags :
Integer
)
;
virtual;
Raw mouse message dispatch method, which forwards data threadsafe to assigned event callback.
- public procedure DispatchGamePadMessage
(
const
AEvent :
NativeInt; const
AButtons :
TGorillaGamePadButtons; const
AMode :
TGorillaInputMode; const
APos :
TPointF; const
AFlags :
UInt64
)
;
virtual;
Raw gamepad message dispatch method, which forwards data threadsafe to assigned event callback.
- public procedure SetCursorPos
(
APoint :
TPoint
)
;
Sets mouse cursor position asynchronously.
Properties
- public Handlers : TObjectList<Gorilla.Controller.Input.TGorillaInputHandler>
- public SequenceBuffer : TQueue<Gorilla.Controller.Input.TGorillaInputSequenceBufferItem>
- published Enabled : Boolean
- published Supported : TGorillaInputDeviceTypes
By this property you can enable devices for capturing inputs. Only those devices will be considered for hotkey checks.
read FSupported
write SetSupported - published HotKeys : TGorillaHotKeyCollection
A published list of all available hotkeys. A HotKey is a combination of input values from keyboard, mouse or gamepad source.
read FHotKeys
write SetHotKeys - published Sequences : TGorillaInputSequenceCollection
A published list of all available hotkey sequences. A Sequence allows you to combine predefined hotkeys for sequential execution.
read FSequences
write SetSequences