Hey,
What I want to do is have the A button on an Xbox controller trigger a left mouse click. So that pressing the A button on the gamepad has the exact same effect as clicking the left mouse button.
I was wondering if this would be possible to do through C++ in Unreal, or if there was another way.
I have the source code to a program which does this, but I’m not really a programmer and I am unsure whether it is even relevant. http://altcontroller.net/faq.aspx
Does anyone have any ideas, or whether such a thing is possible?
But actually, I know I can set action mappings in the .ini so that the two buttons have the same effect, but can I make so that the A button is actually ‘creating’ a left click? (If so I can’t work out how to do that in the .ini.)
Meaning that, pressing the A button would also click buttons in in-game menus etc. as if they were left clicked.
Here is a working example for a custom player controller in c++. It injects a native windows input event, so it only works on Windows platforms.
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/PlayerController.h"
#include "MyPlayerController.generated.h"
/**
*
*/
UCLASS()
class MY_API AMyPlayerController : public APlayerController
{
GENERATED_BODY()
AMyPlayerController();
UFUNCTION(BlueprintCallable, Category = "My")
static void LeftMouseButtonDown();
UFUNCTION(BlueprintCallable, Category = "My")
static void LeftMouseButtonUp();
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyPlayerController.h"
#include "AllowWindowsPlatformTypes.h"
#include "WinUser.h"
//Constructor
AMyPlayerController::AMyPlayerController()
: APlayerController()
{
//... custom defaults ...
}
void AMyPlayerController::LeftMouseButtonDown()
{
INPUT Input = { 0 };
Input.type = INPUT_MOUSE;
Input.mi.dx = 256; // If you need to set the position
Input.mi.dy = 256; // If you need to set the position
Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
SendInput(1, &Input, sizeof(INPUT));
}
void AMyPlayerController::LeftMouseButtonUp()
{
INPUT Input = { 0 };
Input.type = INPUT_MOUSE;
Input.mi.dx = 256; // If you need to set the position
Input.mi.dy = 256; // If you need to set the position
Input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(1, &Input, sizeof(INPUT));
}