I’m using FInputKeyManager.GetKeyCodeFromKey() to get keycodes to pass to CoherentUI, but I’m getting that annoying linker error:
CoUITestFPSCharacter.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: unsigned short const * __cdecl FInputKeyManager::GetKeyCodeFromKey(struct FKey)const " (__imp_?GetKeyCodeFromKey@FInputKeyManager@@QEBAPEBGUFKey@@@Z) referenced in function "public: virtual void __cdecl ACoUITestFPSCharacter::Tick(float)" (?Tick@ACoUITestFPSCharacter@@UEAAXM@Z)
Usually this is because something hasn’t been included in the build file dependencies, but I’m including the InputCore module, which seems to be the relevant one. Is there a way to fix this? Or is this something that needs to be solved on Epics end?
My code looks like this:
int keyCode = *FInputKeyManager::Get().GetKeyCodeFromKey(cPressedKey);
I think that works, but I actually have no way to confirm it since I can’t seem to select forms on my hud to input text, I’ll mark it as the answer once I ensure it works.
The KeyHash solution suggested by Rama won’t be stable. The type hash of an FKey is just the Hash of the FName stored in it and the Hash of a FName is its index. Since the FName indices are, for the most part, unstable (unless they are explicitly defined in UnrealNames.h) from run to run those indices might change.
KeyHashes exist, primarily, for efficient lookups in when using the object as the key in maps, putting them in sets, and the like, which is an inherently runtime behavior so it isn’t important that it be stable from run to run.
Alright, so as a workaround, I’m trying to use FInputKeyManager.GetKeyFromCodes() instead, and simply running through each integer to create my own keymap.
Here’s the code I’m using:
for (int i = 0; i < 2000; i++)
{
FKey tempKey = (FInputKeyManager::Get().GetKeyFromCodes(i, i));
if (&tempKey != NULL)
{
keyCodeMap.Add(tempKey,i);
}
}
My problem at the moment is that not every key seems to be found. For instance, the backslash and left bracket keys don’t show up for some reason…