Hello there,
im trying to listen for an Action that has an AnyKey [Keyboard] binding. In my function i want to check the actual key that was pressed. My Question is how do i found out which key was pressed when I receive the Inputaction.callbackContext on for this action? Right now the path is always /Keyboard/anyKey but i have to map the key to some commands. You can see it in the code below:
public void OnHackMode(InputAction.CallbackContext callbackContext)
{
if (callbackContext.performed && cheatMode)
{
//SubscribeForMode(false);
Debug.Log("Activating Cheat for key: " + callbackContext.control.path);
OnNext(callbackContext.control);
}
}
public void OnNext(InputControl value)
{
if (value.path == CancelKey)
{
//disposableObserver.Dispose();
disposableObserver = null;
cheatMode = false;
}
List<InputHackMode> hackModeList = GetHackModeList();
string path = value.path.Substring(value.path.LastIndexOf("/")+1);
foreach (var mode in hackModeList)
{
if(mode.InputKey == path)
{
if(mode.SubModes is null || mode.SubModes.Count == 0)
{
mode.ExecuteOnSelected.ForEach(c => c.Execute(gameObject));
//disposableObserver.Dispose();
disposableObserver = null;
cheatMode = false;
}
else
{
//disposableObserver.Dispose();
disposableObserver = null;
listenForMode = mode;
//SubscribeForMode(true);
}
return;
}
}
}
Before i just listened to the InputSystem.onAnyButtonPress.Subscribe(this); but i could not resolve if the button was in a performed state. So i switched to an action.
I asked this question in another forum earlier but im kind of on a schedule and hope someone here can help me ^^