Get key pressed

Hi, In my player controller I am doing
InputComponent->BindKey(EKeys::AnyKey, IE_Pressed, this, &AfpsPlayerController::KeyPress);
to get an event if any key is pressed (or mouse button…etc), but how can in my function KeyPress get witch key (FKey) was pressed?

and how can I dont consume the key pressed?
the bindings done with BindAction in my character doesnt work if i use BindKey(EKeys::AnyKey… in my controller.

When you call UInputComponent::BindKey, the component creates a FInputKeyBinding, binds its KeyDelegate to your function and adds it to the UInputComponent::KeyBindings array, which fortunately is a public field, so you can do this yourself.

FInputKeyBinding has methods to bind to functions which signature can receive a FKey. Epic just didn’t write that accessor version for it on UInputComponent::BindKey. FInputKeyBinding can even be bound to functions with custom additional variables (which is what I ended up using).

// .h
UFUNCTION()
void OnKeyPressed(FKey InKey);
UFUNCTION()
void OnKeyReleased(FKey InKey);

// .cpp
const FInputChord KeyChord(EKeys::AnyKey); // The key without any modifiers

FInputKeyBinding KB = FInputKeyBinding(KeyChord, EInputEvent::IE_Pressed);
KB.KeyDelegate.BindDelegate(this, &UYourClass::OnKeyPressed);
KB.bConsumeInput = false; // This defines if it should consume the input
InputComponent->KeyBindings.Emplace(MoveTemp(KB));

KB = FInputKeyBinding(KeyChord, EInputEvent::IE_Released);
KB.KeyDelegate.BindDelegate(this, &UYourClass::OnKeyReleased);
KB.bConsumeInput = false;
InputComponent->KeyBindings.Emplace(MoveTemp(KB));

For the UInputComponent::BindXXX methods, you can also set bConsumeInput on their return value:

InputComponent->BindAction(...).bConsumeInput = false;