Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit/AppGameKit Studio Showcase / SCT - ScanCodeTranslator, new plugin to handle different keyboard layouts.

Author
Message
Haxx0r
8
Years of Service
User Offline
Joined: 18th Apr 2016
Location:
Posted: 14th Sep 2024 02:02 Edited at: 15th Sep 2024 15:18
Hello everybody, last time I used AppGameKit was as a little know-nothing high schooler. Now I am out of college and living life and wanted to make some games again as a hobby. Here is a plugin I made that was very useful to me and I hope it is to you as well. Currently only supports Windows 32 bit and 64 bit. I compiled the plugin with VS2022 so it should work on anything with Windows 10 or newer. I statically linked in the Visual C++ runtime so no need for your end users to install any runtimes but the trade off is the larger file size. I included the source code (just a single C file) if you want to compile it yourself (and you probably should not be using random DLLs from the internet anyways...). No special compilation instructions needed. Just build as a DLL and you are off to the races. Should compile with any compiler made in the last 20 or more years.

Okay, what does this plugin even do and most importantly why do I need it?

Lets take a step back and I will explain the problem!
The world is a big place with many languages and cultures and many people have different keyboards with different layouts, different keys, etc. For example: I am living in the US but I am from Germany and I still have a German keyboard in my shelf and it includes funny letters like: ä, ü, ö and some strange stuff like my Y is where your Z is on your US keyboard layout. It can get even funnier, the French don't use WASD to move in games. They use ZQSD (called a AZERTY keyboard). If you use the built in AppGameKit functions, this will be a total mess. If you program your game to use WASD then your game will be unplayable for users with a French keyboard as the keys are totally scattered around.

Here is the first important lesson: AppGameKit does not care WHERE a key is, only WHAT symbol is on the key. So if you ask if for the W key, it will go find which key has a little W printed on it and not care where it is. This is great for most apps! It means you can handle text input without needing to worry about symbol is on the pressed key, it will always be a W! It works very very poorly for games however. With a game, I want my WASD keys for movement to be next to each other similar to the arrow keys. There is no importance in WHAT symbol is on a key but WHERE the keys are. I want French users to play with ZQSD.

Now, I could detect the system language and check for different keys but this does not work because the user might have their language set to something other than their keyboard layout (for example: me, I have Windows in German but normally use a US keyboard). There is also the problem that there are many many languages and many many keyboard layouts. I can't possibly program them all in advance!

Now comes the second part of the lesson: scan codes! Scan codes are different from key codes because the symbol on the key does not matter. With a scan code, I just look up WHERE the key is. So the physical key that is a W key for your US layouts has the scan code: 0x0011. This means I can use the scan codes to always have the right keys! If a French user plays my game, their game will automatically work with ZQSD!! No work needed for us to do that! And US players will automatically have WASD. This works great!

The sad part is that AppGameKit has no concept of scan codes at all

So this is what my plugin solves. All it does is translate scan codes to key codes. It does not provide any input functions at all, it does not check if a key is pressed, etc. You give it a scan code and it tells you what AppGameKit key to use from this list: https://www.appgamekit.com/documentation/guides/scancodes.htm

How do I use this plugin?

It is very easy.

You call the only function in the DLL: GetUserKey with a key code from https://www.appgamekit.com/documentation/guides/scancodes.htm and it gives you back what key is actually located there on the user's keyboard. Basically, look at a standard US keyboard layout. Pick the location of the key that you want to use, use the AppGameKit key code from the above link and the function will give back to you the key code that is located there. Basically, it auto translates the key code.

Here is a short example of how to use this:
In this example we check if the Z key is pressed. We do this because on a German keyboard, a Z and a Y are swapped. So if you run this example program
on a computer with a German keyboard, you actually press the Y key to get the message in the example to show up.


Is there anything left to do?
Only more testers are needed right now. I only have a US and German keyboard to test with. I used the Windows Win32 API to translate the keys so it should automatically work with any keyboard layout, no need to program them in. However, I don't know anything about languages that don't have at least a semi-latin Alphabet like Russian for example. If you have a Russian keyboard or a non-Latin keyboard. Please try out my plugin and report back! Thank you!

License:
I am giving this to the public domain and take no responsibility of any kind for this plugin. Use at your own risk and I don't claim this to be fit for any purpose implied or otherwise.

Thank you for your time!
Sorry for the cringy user name. I was young and dumb...
Haxx0r
8
Years of Service
User Offline
Joined: 18th Apr 2016
Location:
Posted: 14th Sep 2024 02:18
Sorry, classic mistake. Did not actually include the plugin!

Attachments

Login to view attachments
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 14th Sep 2024 10:24 Edited at: 14th Sep 2024 10:26
Welcome back i guess,

i think you wanted to use iKeyCode in GetRawKeyPressed() command instead of the KEY_Z in your example.
Most of the time I provide the ability to rebind the keys but this might not be veasable for Mobile games where atention span is a minimum and your app has to deliver without any changes so your conversion might be verry usefull here.
Can your addin be used on other platforms ?
It seems to work on my German Cherry keyboard with german layout where the Z and Y is switched.
And maybe you want to take a look at AGK's Repository and push your changes there
Haxx0r
8
Years of Service
User Offline
Joined: 18th Apr 2016
Location:
Posted: 15th Sep 2024 15:18 Edited at: 15th Sep 2024 15:28
Yep, that is wanted I wanted to do. Thank you! I will update the example code.

EDIT: and to answer your other question. Currently the plugin is Windows and Windows 64 bit only. It uses platform specific APIs and I do not currently have a Mac to develop with.
GemGames
6
Years of Service
User Offline
Joined: 31st May 2018
Location: Edmonton, Alberta, Canada
Posted: 17th Sep 2024 00:42
Thanks for this valuable plug-in, and for making it even public domain! Much appreciated.
Azamaticon
3
Years of Service
User Offline
Joined: 1st Oct 2021
Location:
Posted: 18th Sep 2024 19:24 Edited at: 18th Sep 2024 19:26
Strange. An error appears when connecting the plugin. Is there a virus in the plugin? Because after launching the project, the plugin files disappeared from the folder...

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-11-21 09:32:50
Your offset time is: 2024-11-21 09:32:50