Determine keyboard or gamepad in C++
I want to detect based off any key or gamepad event if the input is a keyboard or gamepad.
I want to recreate this in c++:
I can't find that "Any Key" event anywhere in code, are those some sort of dynamic nodes?
I've looked through the classes PlayerController, PlayerInput, InputComponent, InputCoreTypes, KismetInputLibrary (which is where I thought the Any Key event would be). I don't see a way to get any key that was pressed and determine what input device it is.
I've search through a lot of posts, but don't see a real way to do this through code.
Any thoughts on how to detect gamepad/keyboard/mouse through c++?
Thanks for any help!
asked Feb 27 '19 at 07:48 PM in C++ Programming
This seems kind of hacky, but I could not find any other way to grab if any key was pressed and determine what input device that key was. So I created a BindAction for each device and and that action has every possible input type for that device. It was pretty easy to grab them from InputCoreTypes.h and paste the actions into DefaultInput.ini
Then I just update with an enum value what device is active.
answered Feb 28 '19 at 03:52 PM
Set up in Input, an action mapping like you have up there. Then in the C++, Add
Define an event like the following:
This should fire based on your inputs.
You will have to have your C++ class inheriting from the right class. Assuming the inputs are set up correctly, this should fire the event and you should be able to handle it in the event.
I think you need a reference to an APlayerController or derived class. If you have it working in BP, why don't you expose a C++ method to blueprint and call that from within the BP instead.
I am pretty sure you really need a different handler for each key grouping however. The keypress themselves are not passed in. It's probably easier to set up a series of BindActions instead.
Follow this question
Once you sign in you will be able to subscribe for any updates here