Hey everything, I was working on something for my up coming project and I thought it would be useful for the forums
I thought that instead of having a unchangeable keyboard configuration would make the game a bit less appealing since people have different ways of using the keyboard and more comfortable ways, and I just thought I would make a game a little better by letting the user actually pick their keys on the keyboard, like start off with a default setup and then if they want to change anything they could and it would be their keyboard configuration.
It was actually not as hard as I thought it would be, but it’s a little tedious if you want it to turn out, well… better.
If you notice whenever you get the string of a keyboard event it’s in key code version so usually something like this: AKEY, TABKEY, RETKEY, ONEKEY, MINUSKEY, UPARROWKEY. And I think those look ugly in a game, it’s better just to make them what they are, A, Tab, Enter, One, -, Up Arrow. To convert all the letters, symbols and numbers was the longest part in this example because I had to get every key on the keyboard available on tutorialsforblender3D and convert them to something that just looks better. It might be overworking, but I think it’ll look more professional.
You can see how I did that in the keyboard_translations script in the .blend.
Basically, I made a hell of a lot of little lists. The first on the list, is the new name for the key, the second thing on the list was the number code of the key(number code was just easier you could of done it with the code name). The list name was the key for the keyboard. A, 1, Space, Home on the keyboard would be:
a = ['A', 97] one = ['1', 49] space = ['Space', 32] home = ['Home', 176]
I did that for every key on the keyboard that could be used in the GameKey module in Blender and I put it in another huge list.
Then I had a small loop.
When a key was pressed, it would get the number code from the event(the key that was pressed), then through a loop and check every small list in the huge list and see if the second value matched the number event number code, and if it did, the 1st value would be put on another property for the Text property to display. Easy, but long.
Now, I’m not sure if that was the best way, but it works well…
The rest is self explanatory, there’s a save script to save your new keyboard configuration when you press Start in the key configuration menu.
Tab = Move through the keys you want to change
Enter = Change the key(Selector starts flashing), then press any key and your key is changed!
Try it out, tell my what you think, and the file is in the attachments! taw taw!
forum_version.blend (214 KB)