Closed Kroeltje closed 5 years ago
I've managed to get it to work looking at the code used internally in the AnalogCursor.cpp
Here is my code: `void AHandTrack_PlayerController::TriggerMouseLMBDown() { FViewportClient* Client = GEngine->GameViewport->Viewport->GetClient(); FKey MouseLMB = EKeys::LeftMouseButton; Client->InputKey(GEngine->GameViewport->Viewport, 0, MouseLMB, EInputEvent::IE_Pressed);
FSlateApplication& SlateApp = FSlateApplication::Get();
//FKey Key = InKeyEvent.GetKey();
FPointerEvent MouseDownEvent(
0,
SlateApp.CursorPointerIndex,
SlateApp.GetCursorPos(),
SlateApp.GetLastCursorPos(),
SlateApp.GetPressedMouseButtons(),
EKeys::LeftMouseButton,
0,
SlateApp.GetPlatformApplication()->GetModifierKeys()
);
//FPointerEvent MouseDownEvent (0, SlateApp.CursorPointerIndex, SlateApp.GetCursorPos(), SlateApp.GetLastCursorPos(), 1.0f, true, SlateApp.GetPlatformApplication()->GetModifierKeys());
TSharedPtr<FGenericWindow> GenWindow;
SlateApp.ProcessMouseButtonDownEvent(GenWindow, MouseDownEvent);
}
void AHandTrack_PlayerController::TriggerMouseLMBUp() { FViewportClient* Client = GEngine->GameViewport->Viewport->GetClient(); FKey MouseLMB = EKeys::LeftMouseButton; Client->InputKey(GEngine->GameViewport->Viewport, 0, MouseLMB, EInputEvent::IE_Released);
FSlateApplication& SlateApp = FSlateApplication::Get();
FPointerEvent MouseUpEvent(
0,
SlateApp.CursorPointerIndex,
SlateApp.GetCursorPos(),
SlateApp.GetLastCursorPos(),
SlateApp.GetPressedMouseButtons(),
EKeys::LeftMouseButton,
0,
SlateApp.GetPlatformApplication()->GetModifierKeys()
);
TSharedPtr<FGenericWindow> GenWindow;
SlateApp.ProcessMouseButtonUpEvent(MouseUpEvent);
}`
It both generates click events and clicks in menus.
I'm building a project where you can use a handtracker to navigate UI. I manage to set the position of the mouse cursor on hand movement but I don't know how to simulate a mouse click.
The following piece of code does not simulate a mouse click that works in UI. It just trigger the mouse LMB event. FViewportClient* Client = GEngine->GameViewport->Viewport->GetClient(); FKey MouseLMB = EKeys::LeftMouseButton; Client->InputKey(GEngine->GameViewport->Viewport, 0, MouseLMB, EInputEvent::IE_Pressed);
I was hoping to find a hint in your code but I don't understand how you simulate mouse clicks in the UI. Can you help me out?