【UE4】クリップボードから文字列を取得、設定 Copy&Paste

PC、スマホ等で日常的にやっている Copy&Paste をUE4から制御できる機能を紹介します。

FPlatformApplicationMisc クラスの ClipboardCopy(), ClipboardPaste() を使うことで可能です。

実際にやってみます。
BPには公開されていないのでラッピングした関数を用意します。

#include "HAL/PlatformApplicationMisc.h"

void UMyBlueprintFunctionLibrary::ClipboardCopy(const FString& Str)
{
	FPlatformApplicationMisc::ClipboardCopy(*Str);
}

void UMyBlueprintFunctionLibrary::ClipboardPaste(FString& Dest)
{
	FPlatformApplicationMisc::ClipboardPaste(Dest);
}


利用するためにモジュールも追加する必要があります。

PublicDependencyModuleNames.AddRange( new string[]
{
// ...
"ApplicationCore",
// ...
}
);


関数を呼ぶWidgetを作成。

f:id:shuntaendo:20200903185413p:plain:w300 f:id:shuntaendo:20200903185616p:plain:w380


こんな感じになりました。

f:id:shuntaendo:20200903191633g:plain


流行りの?Editor Utility Widget と相性良さそうですね。
使用したい機会があったら参考にしてみてください。


UE Version : 4.25.3-13942748