How to move mouse cursor with Gamepad stick?

Hi, I’ve enabled mouse cursor for a sort of menu stage and it moves and is controlled just fine with the mouse input, but how do I move it with the Gampead stick? Is this possible in BP at all?

Are you using a Microsoft Wired Xbox 360 Gamepad?

Use Rama’s plugin to move mouse cursor in BP How could I Set mouse position via Blueprint? - Programming & Scripting - Unreal Engine Forums

All you just need is to set your gamepad stick to control BP function moving mouse cursor.

Yes, I am.

Go into the Project Settings and within the Input, set it up so you can use one of the Analog sticks as well as the mouse cursor. They should be listed as something like gamepad joystick x or something like that. Obviously you will need to setup the axis within blueprint but this would most probs be similar to how the default controls are setup with a character. I would supply a picture but I am not on my own computer at the moment. Let me know how you get on.

Hi, thanks for the suggestion, but as far as I know there you can create Input events with Gamepad Left and Right X and Y axes but there’s no configuration there on making the mouse controllable by Gamepad and I haven’t found how to manually modify mouse position in BP.

I’m on 4.2 and can’t go to 4.4 in this project (the plugin is in 4.4) or I will get a bunch of errors. I’ve asked Rama if he could please provide me with a 4.2 older built but haven’t got a response yet.

Hey Albert, I recently had to do this as well. This isn’t perfect but it should get you on the right direction.

I used Rama’s code for setting the cursor position in blueprints. (As a disclaimer I don’t know C++ so this is sort of hobbled together)

Go to file Add Code to Project.
Create a new class from PlayerController and call it NewPlayerController

in the .h file:

#pragma once

#include "Kismet/BlueprintFunctionLibrary.h"
#include "GameFramework/PlayerController.h"
#include "MyNewPlayerController.generated.h"

class YOURPROJECT_API AMyNewPlayerController : public APlayerController


	UFUNCTION(BlueprintCallable, Category = "YOURCATEGORY")
	static bool Viewport__SetMousePosition(const APlayerController* ThePC, const float& PosX, const float& PosY);

In the .cpp file:

#include "YOURPROJECT.h"
#include "MyNewPlayerController.h"

AMyNewPlayerController::AMyNewPlayerController(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)

bool AMyNewPlayerController::Viewport__SetMousePosition(const APlayerController* ThePC, const float& PosX, const float& PosY)
		if (!ThePC) return false;

		//Get Player
		const ULocalPlayer * VictoryPlayer = Cast<ULocalPlayer>(ThePC->Player);
		//PlayerController::Player is UPlayer

		if (!VictoryPlayer) return false;

		//get view port ptr
		const UGameViewportClient * VictoryViewportClient =
			Cast < UGameViewportClient >(VictoryPlayer->ViewportClient);

		if (!VictoryViewportClient) return false;

		FViewport * VictoryViewport = VictoryViewportClient->Viewport;

		if (!VictoryViewport) return false;

		//Set Mouse
		VictoryViewport->SetMouse(int32(PosX), int32(PosY));

		return true;

After rebuilding, open your playercontroller blueprint and reparent it to your new playercontroller.
Right click, and enter “Set mouse” and you should see the new node you created, under whatever category you entered in the .h file.

This is my playercontroller, controlling the cursor with the D pad:

1 Like

Hi. Do you know how to simulate mouse click with gamepad? I basically want to click on a menu button with gamepad. How can I go about it?
Any help would be greatly appreciated.

I couldn’t figure out a way to do that, but if your widget has focus, you can use the left analog stick or D-Pad to select buttons and use the A button on the gamepad to click them. It only works for buttons. That is in 4.6 though. You can also trace to get the widget under the cursor position, I done that with a 3D widget component in 4.6. You wouldn’t use the actual cursor, just an icon on screen that represents the cursor.

FViewportClient* Client = GEngine->GameViewport->Viewport->GetClient();
Client->InputKey(GEngine->GameViewport->Viewport, 0, Key, EInputEvent::IE_Pressed);

Then you can just make a Key variable in BP, assign “Mouse Left Click” to default value.

Awesome, thanks for that example. I’ve been looking for that!

Using timeline for incrementing variable’s vaue is the most deeply disturbing thing I saw in years.

1 Like