KB Tester utility helps you see what value to check for when a key is pressed.

KBTester is a utility/demo I made to help out with coding your keyboard_check routines. It is born out of frustration and necessity for handling certain inputs from a very fundamental input device for computer games, the standard keyboard, which are not supported out of the box.

If you program keyboard input in your games, you’ll find that, for most keys on a computer’s keyboard, you can use vk_constants and ord(letter)… but for some odd reason YYG didn’t create a vk_constant for every key on the keyboard, and don’t plan to. Not only that, but there are certain keys that don’t return the right value for ord() to work with keyboard_check.

For example, say you want to check if the period key is pressed. You might think that you can do keyboard_check(vk_period) but to your surprise, there is no vk_period constant defined in GML. So, then it must be that you need to do keyboard_check(ord(“.”)) only… it doesn’t work!

That’s because ord(“.”) returns a value of 46. But for some reason, if you want keboard_check() to return true when the period key is pressed, you need to check for the value 190. Why? Why are certain keys on the standard keyboard treated as second-class citizens? Because, sadly it’s not in YYG’s vision to improve keyboard support.

To paraphrase a certain “Evil YoYo Games Employee” who commented on my suggestions for ways the current keyboard support badly needs to be improved:

<paraphrase>Why should we improve keyboard support when you can just research what codes map to your keyboard keys, make an extension that has a few constants in it, and then hope that these will work with all keyboards and all target platforms? Just code it once and then put it up on the Marketplace. Now that the marketplace exists to provide stopgap coverage of GM:S shortcomings, we don’t have to pay our own programmers to fix those holes anymore.</paraphrase>

So, I guess we’re supposed to figure out the numbers and then code some constants for the missing vk_constants, and use those. This, despite the helpfile recommending against using hardcoded numeric values in keyboard_check because you never know if it’ll work on the target platform if it’s not Windows/Mac/Ubuntu:

NOTE: These functions are designed for Windows/Mac/Ubuntu desktop platforms only. You may find some of the in-built variables and constants aren’t valid on other platforms and many of the functions won’t work on mobiles.
Now, each key is normally defined by a number, called the ascii code, and you can directly input this number into these functions and they will work fine… But, as it’s a bit difficult to remember so many numbers and the relationship that they have with your keyboard, GameMaker: Studio has a series of constants for the most used keyboard special keys and a special function ord() to return the number from ordinary typed characters (either letters or numbers).

The implication is that, YYG seem to be saying, “Despite the promise of GM:S to be a development environment that supports multiple target platforms, we didn’t see the need to ensure that your code will run the same on all target platforms we support, or all region/localities, or with all keyboard layouts. After looking into it we decided it was too hard for us to deal with, so we’re passing it along to you to figure out for yourself. So just be aware that these may or may not work on all platforms, and that’s all the info we’re going to give you about that. You’re on your own to figure out how to solve keyboard input from any platforms that don’t work with our keyboard input functions.”

Well, for whatever reason, YYG doesn’t provide FULL keyboard coverage between ord() and vk_constants, and it’s not in their vision to address this shortcoming, so I guess you’re going to have to go out and find some reference that will tell you what numbers represent what key, and then hope they still work.

In the meantime, you can use KBTester, press a key, and get the answer without having to hunt the info down on the internet and hope it’s correct. If you’re having trouble getting keyboard_check to work, and need to verify that the magic number you’re using is indeed the right one, you can run KBTester. Press the key you want to use, and KBTester will tell you the value that GameMaker sees when it is pressed.

Updated: 2016-Oct-20 — 9:07 pm

Leave a Reply