How to use scancode instead keycode for keybinding like in EA games

How to do that ?

In EA games, whatever the keyboard layout on, the 2nd upper-left alphabet key is used as moving forward.

And I have proved this theory with a random keyboard layout I made, like QWERTY become ABCDEF.
And when I pressed B, I moved forward.

No need to modify the keybinding behavior for special adjustment due to the keyboard layout chosen.

And I want that for my game.

1 Like

Hello Haeath,

would you mind sharing some more info with us? Like, what do you mean exactly by random keyboard layout?

If I understood you correctly, you’re swapping keycaps around, which by default don’t have any effect on the keyboard output.
As for the generalization of game input by the publisher; the publisher doesn’t usually has any influence on how the game mechanics are exactly implemented. The implementation of user input may differ from game to game, as they differ in their engine.

I mean like this 3D Graphics Engine with Basic Math on CPU - CodeProject

It’s a minimalist game engine I wrote and it does support scancode keybinding instead traditional keycode keybinding.

The code is in C# .NET and here’s the keybinding function I made:

As you see, I am not using GetKeyState() or whatever, I am using a low level hook to grab the scancode by extracting it from lParam.

Described there: c# - Get correct keyboard scan code for arrow keys - Stack Overflow

Thus, since I am not doing a bunch of if to support all kind of keyboard to be able to move forward with all of them without rebinding.

Try the program with different layout, as French of German, and you will see, you still move forward by pressing W (if your keyprint is in QWERTY ofc)

If you want to create a random keyboard layout to try out the scancode scanning method instead of keycode scanning, download https://www.microsoft.com/en-us/download/details.aspx?id=22339

Hello Haeath,

thank you for the info, made it a lot clearer to me. As far as I am aware of there’s no easy way to do it (as in no source code editing), take a look at the InputCore, InputDevice modules (Source/Runtime/)
If you’re concerned about keyboard combability issues, UE4 should solve that for you. So I’m sorry, but I don’t really see a use case for that.

I see, there is no way to do that with Blueprint, I will wait for a such implementation.

Thanks anyway

I doubt there will be such an implementation in any time. scancodes are depending on ther underlaying platform. So in Linux you have different ones than in windows, don’t want to thing on all the plattforms ue supports. this is where input binding comes into play an that is well implemented.
maybe something like this plugin can help Keyboard Layout-Independent Input in Code Plugins - UE Marketplace

you can get the scancode from a keycode using c++ - have a look at the included SDL2 lib, you can use SDL_GetScancodeFromKey(SDL_Keycode key)

for example

Did you know that scancode is normalized under the USB IF standard

https://usb.org/document-library/hid-usage-tables-112

Go to page 53, and you will see, the scancode is standardized

After, yes, there are two sancodes, the hardware ones and PC ones, the USB IF standardized the hardware scancode that all keyboard respect and send to the PC.

The PC scancode depend of the OS translation table.

But we don’t care about Linux honestly, if Unreal Engine was used by Linux users and produce Linux games, we would know it already, Linux is a minority and shall not be considered into software development that can cause important restriction as this.

EA games don’t care about Linux hardware implementation since they manage the keyboard with PC scancode instead keycode.

I already have a method to do keybinding based on scancode, but you are intriguing me.

Do you mean I can invoke third-party API as SDL into Unreal Engine C++ project ?

For my method, it will be WinAPI function and make a low level keyboard hook with SetHook().

But anyway, I would like to do it via Blueprint.

yes. the module is included in UE and you can call that DLL function via CPP function call. This (your own) cpp function can then be exposed to Blueprint. sounds hacky, but this is how it goes :wink:

Alright, I will try it one day, thanks

Hi there! Looking for a good module to set this up but I don’t manage to find one, could you please bring some more informations to me if you already did scancode detection within UE?

Unreal Engine should make this the default behavior. It’s sad and disgraceful that most of the biggest budget AAA can’t get keyboard layouts correctly. I can’t cite any game made with Unreal Engine that uses scan codes instead of keycodes. All the games are layout-dependent and little care is given to those who use AZERTY or QWERTZ keyboards; let alone those from other parts of the worlds.