Is there a way to simulate the left click of the mouse with a game pad?
Iād like to know this as well. Havenāt been able to find a solution.
What are you trying to achieve exactly? You can have an action mapping with multiple inputs i.e.
Not exactly. Iām trying to use the gamepad to activate āon clickedā events.
Gotcha. This isnāt currently possible. Are you controlling the mouse cursor with your game pad(with Ramaās plugin maybe; ~ Set Mouse Position - SET the mouse position to any values of your choosing!)? if so, you could do this: Send a line trace from the mouse position towards the Y axis (assuming Y axis is your depth) and trigger a hit if it finds anything.
Sorry that this isnāt really what you were looking for, but itās the best I can do
Cheers!
Thanks for the reply. I wish there was a way to do click events with the gamepad but this should work.
yep exactly at least there usually always is a work around (Iāve always found a work around for what Iāve tried doing). but this topic seems to have been tossed around a bit so maybe we will see this feature added in the future.
Hello, sorry to drag this up. But did this work for you?
I am trying to setup multiple cursors for my game, so I have each player moving around a widget that I can get a screen position from, is it even possible to get raycast hits on widgets casting from screen to world?
Any advice you have would be great. Thanks!
This sounds like another similar thread, which I ran into while trying to find workarounds myself. I posted what I ended up doing here: Gamepad Menu Navigation Issues - Programming & Scripting - Unreal Engine Forums
(Not sure on etiquette of copy/pasting the same post, so Iāll just link it.)
TLDR is - if you put the input button you want to use in the player controller or pawn, and have it set a variable to true when pressed, and then re-setting that variable to false when released, you can cast to the player with your widget each frame, and run that through a branch tied to that variable.
Then, you can have that go through a sequence, each one going to a new branch, which is tied to āIs Hoveredā which is then tied to each button you want to use.
These branches then only output on ātrueā āIs Hoveredā responses from the buttons, and feed into whatever you want that button to do.
Hopefully this is kinda what youāre looking for? The other thread was a bit more specific about how they were hoping to use this spoofing of mouse clicks, Iām assuming itās for a menu widget or something similar.
I found a solution for the left click event that triggers UI āon clickedā events.
Iāve looked into this because I want a handtracker to move the mouse and also click things.
Youāll have to go into c++ to make it work, but its not too complicated and if you struggle with it, let me know.
So add a new c++ class which inherits from player controller (this is nog mandatory but its nice to have it in a player controller) Then in your .h file add 2 functions like so:
public:
UFUNCTION(BlueprintCallable)
void TriggerMouseLMBDown();
UFUNCTION(BlueprintCallable)
void TriggerMouseLMBUp();
The blueprint callable makes it so that you can trigger the function from blueprints.
The first function simulates the click down and the second function the release. You need both.
Then in the .cpp file add the code below.
The first part triggers any LMB click events and the part below that handles the UI clicks.
void AHandTrack_PlayerController::TriggerMouseLMBDown()
{
//trigger the mouse click event. This will fire any lmb click events within blueprints.
FViewportClient* Client = GEngine->GameViewport->Viewport->GetClient();
FKey MouseLMB = EKeys::LeftMouseButton;
Client->InputKey(GEngine->GameViewport->Viewport, 0, MouseLMB, EInputEvent::IE_Pressed);
//Trigger mouse clicks in UI
//Get our slate application
FSlateApplication& SlateApp = FSlateApplication::Get();
//create a pointer event
FPointerEvent MouseDownEvent(
0,
SlateApp.CursorPointerIndex,
SlateApp.GetCursorPos(),
SlateApp.GetLastCursorPos(),
SlateApp.GetPressedMouseButtons(),
EKeys::LeftMouseButton,
0,
SlateApp.GetPlatformApplication()->GetModifierKeys()
);
//send the mouse event to the slate handler
TSharedPtr<FGenericWindow> GenWindow;
SlateApp.ProcessMouseButtonDownEvent(GenWindow, MouseDownEvent);
}
void AHandTrack_PlayerController::TriggerMouseLMBUp()
{
//trigger the mouse click release event
FViewportClient* Client = GEngine->GameViewport->Viewport->GetClient();
FKey MouseLMB = EKeys::LeftMouseButton;
Client->InputKey(GEngine->GameViewport->Viewport, 0, MouseLMB, EInputEvent::IE_Released);
//trigger the UI mouse click
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);
}
For my hand tracking solution in the blueprint I trigger the mouse click down on a hand pinch.
Donāt forget to also trigger the mouse click up events with a small delay or on a button release.
In your instance you can detect a specific button press and then trigger the mouse click down function and trigger the mouse click up on button release.
nice! good job ~
Itās not the greatest solution, and is quite tedious depending on how much you have in your HUD, but this works for me at least. I found I needed to overlay my non-btn UMG elements that had click events with a transparent btn, that way you can use the OnHovered and Unhovered events to set a boolean. Then you can simply collapse all your click logic into a function, and call that from your pawn/characterās BP.
Itās not the best solution, but itās simple to understand at least.