// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "IAutomationDriver.h" #include "WaitUntil.h" #include "Misc/Timespan.h" #include "InputCoreTypes.h" class FAutomatedApplication; class IElementLocator; class IAsyncDriverSequence; class IAsyncActionSequence; class IAsyncDriverElement; class IAsyncDriverElementCollection; class FDriverConfiguration; class FModifierKeysState; class FAsyncAutomationDriverFactory; class FAsyncAutomationDriver : public IAsyncAutomationDriver , public TSharedFromThis { public: virtual ~FAsyncAutomationDriver(); virtual TAsyncResult Wait(FTimespan Timespan) override; virtual TAsyncResult Wait(const FDriverWaitDelegate& Delegate) override; virtual TSharedRef CreateSequence() override; virtual TAsyncResult GetCursorPosition() const override; virtual TAsyncResult GetModifierKeys() const override; virtual TSharedRef FindElement(const TSharedRef& ElementLocator) override; virtual TSharedRef FindElements(const TSharedRef& ElementLocator) override; virtual TSharedRef GetConfiguration() const override; /** * Saves a shared pointer to the action sequence object to ensure it remains in memory until execution is complete. * @param Sequence shared pointer to the action sequence. * @return true if the pointer has been saved successfully; false if another pinned sequence is currently being executed. */ bool PinActionSequence(const TSharedPtr& Sequence); /** * Resets an internally stored shared pointer to the previously pinned action sequence object so that it can be deleted. * @param Sequence shared pointer to the action sequence. * @return true if the pointer has been reset successfully; false if the provided sequence hasn't been pinned previously or if it is still executing */ bool UnpinActionSequence(const TSharedPtr& Sequence); public: void TrackPress(int32 KeyCode, int32 CharCode); void TrackPress(EMouseButtons::Type Button); void TrackRelease(int32 KeyCode, int32 CharCode); void TrackRelease(EMouseButtons::Type Button); bool IsPressed(int32 KeyCode, int32 CharCode) const; bool IsPressed(EMouseButtons::Type Button) const; int32 ProcessCharacterForControlCodes(int32 CharCode) const; private: FAsyncAutomationDriver( const TSharedRef& InApplication, const TSharedRef& InConfiguration) : Application(InApplication) , Configuration(InConfiguration) { } void Initialize(); private: const TSharedRef Application; const TSharedRef Configuration; TSharedPtr PinnedSequence; TSet PressedModifiers; TSet PressedKeys; TSet PressedChars; TSet PressedButtons; TMap CharactersToControlCodes; friend FAsyncAutomationDriverFactory; }; class FAsyncAutomationDriverFactory { public: static TSharedRef Create( const TSharedRef& AutomatedApplication); static TSharedRef Create( const TSharedRef& AutomatedApplication, const TSharedRef& Configuration); }; class FAutomationDriverFactory; class FAutomationDriver : public IAutomationDriver , public TSharedFromThis { public: virtual ~FAutomationDriver(); virtual bool Wait(FTimespan Timespan) override; virtual bool Wait(const FDriverWaitDelegate& Delegate) override; virtual TSharedRef CreateSequence() override; virtual FVector2D GetCursorPosition() const override; virtual FModifierKeysState GetModifierKeys() const override; virtual TSharedRef FindElement(const TSharedRef& ElementLocator) override; virtual TSharedRef FindElements(const TSharedRef& ElementLocator) override; virtual TSharedRef GetConfiguration() const override; public: void TrackPress(int32 KeyCode, int32 CharCode); void TrackPress(EMouseButtons::Type Button); void TrackRelease(int32 KeyCode, int32 CharCode); void TrackRelease(EMouseButtons::Type Button); bool IsPressed(int32 KeyCode, int32 CharCode) const; bool IsPressed(EMouseButtons::Type Button) const; private: FAutomationDriver( const TSharedRef& InApplication, const TSharedRef& InAsyncDriver) : Application(InApplication) , AsyncDriver(InAsyncDriver) { } private: const TSharedRef Application; const TSharedRef AsyncDriver; friend FAutomationDriverFactory; }; class FAutomationDriverFactory { public: static TSharedRef Create( const TSharedRef& AutomatedApplication); static TSharedRef Create( const TSharedRef& AutomatedApplication, const TSharedRef& Configuration); };