How do you integrate a custom input device with the engine input and axis mappings?

Hello, I am trying to integrate a custom input device in to UE4 and it would be awesome to have this integrate with the default input and axis mappings to make it easy to get input from the device in any class. I’ve searched the documentation and forums and have not found much info on this subject. I’m implementing my device in a Plugin, so when the module starts is probably where I need to add in my own keys. Anways, I have no idea what the best approach to doing this is without adding it to InputCoreTypes.cpp . I’ve tried calling EKeys::AddKey() from within my plugin, but get a compiler error that it can’t export the DLLmodule, if I try the same thing in a class for the Game Project it compiles fine. Any help or examples would be awesome, thanks!

After a bit of trial and error, I was able to add a custom FKey definition that shows up as an option in the action and axis mappings configuration within the editor. I did it directly in a game module, but I assume it wouldn’t be much different in a plugin. Here’s what I did:

Within my module’s header file:

struct EMyKeys
{
    static const FKey MyKeyX;
};

Within my module’s StartupModule function:

EKeys::AddKey(FKeyDetails(EMyKeys::MyKeyX, LOCTEXT("MyKeyX", "My Key X"), FKeyDetails::FloatAxis));

9500-mykey.png

to add to your answer you then call
FSlateApplication::Get().OnControllerButtonPressed(EMyKeys::MyKeyX,controllerId,0)
FSlateApplication::Get().OnControllerButtonReleased(EMyKeys::MyKeyX,controllerId,0)

whenever buttons are pressed and

FSlateApplication::Get().OnControllerAnalog(EMyKeys::MyKeyAxis, controllerId, axisvalue)

whenever you want to update your axis (in something like Tick)

Have you eventually managed to do it inside a plugin?

@getnamo, I tryed using FSlateApplication::Get().OnControllerButtonPressed(EMyKeys::MyKeyX,controllerId,0)

Unreal complains because the first parameter must be a EControllerButtons::Type. And, for the AddKey, we have FKeys. How do I create EControllerButtons related to my FKeys? Or was this function deprecated?

You first define FKeys somewhere e.g.
const FKey MyoPoseRest;

and then you register the key in some initial state (e.g. when your plugin has loaded successfully) via
EKeys::AddKey(FKeyDetails(EKeysMyo::MyoPoseRest, LOCTEXT(“MyoPoseRest”, “Myo Pose Rest”), FKeyDetails::GamepadKey));

see https://github.com/getnamo/myo-ue4/blob/master/Plugins/MyoPlugin/Source/MyoPlugin/Public/MyoDelegate.h and https://github.com/getnamo/myo-ue4/blob/master/Plugins/MyoPlugin/Source/MyoPlugin/Private/FMyoPlugin.cpp for reference implementations (used in the unofficial Myo Plugin)