Skip to content

Commit

Permalink
Add vset /action/keyboard [key_name] [duration]. Update to v0.3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
qiuwch committed May 17, 2017
1 parent d8b8f7b commit 99e0cc6
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 2 deletions.
43 changes: 42 additions & 1 deletion Source/UnrealCV/Private/Commands/ActionHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ void FActionCommandHandler::RegisterCommands()
Help = "Set the distance of binocular stereo camera";
CommandDispatcher->BindCommand("vset /action/eyes_distance [float]", Cmd, Help);


/*
Cmd = FDispatcherDelegate::CreateRaw(this, &FActionCommandHandler::ResumeGame);
Help = "Resume the game";
CommandDispatcher->BindCommand("vset /action/game/resume", Cmd, Help);
*/

Cmd = FDispatcherDelegate::CreateRaw(this, &FActionCommandHandler::Keyboard);
Help = "Send a keyboard action to the game";
CommandDispatcher->BindCommand("vset /action/keyboard [str] [float]", Cmd, Help);
}

FExecStatus FActionCommandHandler::PauseGame(const TArray<FString>& Args)
Expand All @@ -44,3 +48,40 @@ FExecStatus FActionCommandHandler::SetStereoDistance(const TArray<FString>& Args
return FExecStatus::Error("Expect argument: eye distance");
}
}

/** Return a TFunction to Release the Keyboard */
TFunction<void(void)> FActionCommandHandler::GetReleaseKey(FKey Key)
{
UWorld* World = this->GetWorld();
return [=]() {
World->GetFirstPlayerController()->InputKey(Key, EInputEvent::IE_Released, 0, false);
};
}

FExecStatus FActionCommandHandler::Keyboard(const TArray<FString>& Args)
{
if (Args.Num() != 2)
{
return FExecStatus::InvalidArgument;
}
FString KeyName = Args[0];

UWorld* World = this->GetWorld();
FKey Key(*KeyName);
// The valid KeyName can be found in https://wiki.unrealengine.com/List_of_Key/Gamepad_Input_Names

// Not sure about the meaning of parameters: DeltaTime, NumSamples, bGamepad
// They are not clearly documented in
// https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/GameFramework/UPlayerInput/InputAxis/index.html
// and https://github.com/EpicGames/UnrealEngine/blob/release/Engine/Source/Runtime/Engine/Private/UserInterface/PlayerInput.cpp#L254
float Delta = 1; // Delta is always 1 for key press, this is how hard this button is pressed
float DeltaTime = FCString::Atof(*Args[1]);
int32 NumSamples = 1;
bool bGamepad = false;
// The DeltaTime is not used in the code.
World->GetFirstPlayerController()->InputAxis(Key, Delta, DeltaTime, NumSamples, bGamepad);
FTimerHandle TimerHandle;
World->GetTimerManager().SetTimer(TimerHandle, GetReleaseKey(Key), DeltaTime, false);

return FExecStatus::OK();
}
4 changes: 4 additions & 0 deletions Source/UnrealCV/Private/Commands/ActionHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ class FActionCommandHandler : public FCommandHandler

/** vset /action/eyes_distance [float] */
FExecStatus SetStereoDistance(const TArray<FString>& Args);

/** vset /action/keyboard [key_name] [delta] */
FExecStatus Keyboard(const TArray<FString>& Args);
TFunction<void(void)> GetReleaseKey(FKey Key);
};
2 changes: 1 addition & 1 deletion UnrealCV.uplugin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"FileVersion" : 3,
"Version" : 4,
"VersionName": "0.3.5",
"VersionName": "0.3.6",
"FriendlyName": "Unreal CV",
"Description": "UnrealCV is a plugin to connect computer vision algorithm and the games built by Unreal Engine",
"Category" : "Science",
Expand Down
4 changes: 4 additions & 0 deletions docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ CHANGELOG
Development branch
==================

- v0.3.6 :
- Change docs from markdown to reStructuredText
- Add docker to automate tests
- Add :code:`vset /action/keyboard [key_name] [delta]`
- v0.3.5 : Add vexec to support the invocation of blueprint functions, Add :code:`GetWorld()` in :code:`FCommandHandler`.
- v0.3.4 : Delay the object mask painting from initialization code
- v0.3.3 : Add :code:`vget /scene/name`
Expand Down
8 changes: 8 additions & 0 deletions docs/reference/commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ vget /unrealcv/status
vget /unrealcv/help
(v0.2) List all available commands and their help message

4. Action commands
------------------

See :file:`Source/UnrealCV/Private/Commands/ActionHandler.h(.cpp)`

vset /action/keyboard [key_name] [delta]
(v0.3.6) Valid key_name can be found in `here <https://wiki.unrealengine.com/List_of_Key/Gamepad_Input_Names>`__

Run UE4 built-in commands
-------------------------

Expand Down

0 comments on commit 99e0cc6

Please sign in to comment.