• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker How do I convert Key-code to its correct Key?

Evanski

Raccoon Lord
Forum Staff
Moderator
I'm having an Issue with UTF-8
When I have a key lets use "F1" as an example.

It's keycode is "112" However using chr(112) I get "p" because "p"'s code is "11"

I'm saving these key codes to an ini then loading those codes to there correct key to be used and customized by the player, but I want to include special keys like F1-12, Shift, Ctrl, alt, ect..

Is there something I'm doing wrong? Any help is appreciated as all ways, Thanks.

GML:
//DEFAULT GLOBAL SETTINGS
global.Player_Key_Move_Up = 122; //this is a test for F1, trying to do ord("F1") gets the code for "F"
global.Player_Key_Move_Down = ord("S");
global.Player_Key_Move_Left = ord("A");
global.Player_Key_Move_Right = ord("D");


//LOAD SETTINGS
if (file_exists(working_directory + "config.ini"))
{
    //open it
    ini_open(working_directory + "config.ini")
    //read variables
    global.Player_Key_Move_Up =        ini_read_real("KeyBinds", "Movement_Up"        ,global.Player_Key_Move_Up);
    global.Player_Key_Move_Down =    ini_read_real("KeyBinds", "Movement_Down"    ,global.Player_Key_Move_Down);
    global.Player_Key_Move_Left =    ini_read_real("KeyBinds", "Movement_Left"    ,global.Player_Key_Move_Left);
    global.Player_Key_Move_Right =    ini_read_real("KeyBinds", "Movement_Right"    ,global.Player_Key_Move_Right);
    //done
    ini_close();
}
else //SAVE SETTINGS
{
    //open it
    ini_open(working_directory + "config.ini")
    //Save variables
    ini_write_real("KeyBinds", "Movement_Up"    ,global.Player_Key_Move_Up);
    ini_write_real("KeyBinds", "Movement_Down"    ,global.Player_Key_Move_Down);
    ini_write_real("KeyBinds", "Movement_Left"    ,global.Player_Key_Move_Left);
    ini_write_real("KeyBinds", "Movement_Right" ,global.Player_Key_Move_Right);
    //done
    ini_close();
}


//MACROS- THESE ARE USED AS keyboard_check_pressed(PLAYERKEY_MOVE_UP) Becuase I dont want to type global. everytime Im lazy give me a break
#macro PLAYERKEY_MOVE_UP global.Player_Key_Move_Up
#macro PLAYERKEY_MOVE_DOWN global.Player_Key_Move_Down
#macro PLAYERKEY_MOVE_LEFT global.Player_Key_Move_Left
#macro PLAYERKEY_MOVE_RIGHT global.Player_Key_Move_Right
 

kburkhart84

Firehammer Games
I'm not clear on the issue. If you save the value 112, then you can load that value back in. My input system does this exactly(though I'm not using INI). I'm also not sure why you are trying to use chr(112) for anything. Any key that isn't a letter or number won't have an actual character for it, so the chr() function is useless here. Just use the 112 keycode value directly. You can also use the constants if you want, as mentioned just above this post.
 

Evanski

Raccoon Lord
Forum Staff
Moderator
I'm not clear on the issue. If you save the value 112, then you can load that value back in. My input system does this exactly(though I'm not using INI). I'm also not sure why you are trying to use chr(112) for anything. Any key that isn't a letter or number won't have an actual character for it, so the chr() function is useless here. Just use the 112 keycode value directly. You can also use the constants if you want, as mentioned just above this post.
Im getting the correct keycode but I want to turn it back into the actual key name
"65" -> A
"112" -> F1
 

kburkhart84

Firehammer Games
I would be glad to give you the one I use for exactly that purpose if you want it. Its part of my configuration system. It is basically a 256 item array, with some of them set to "Unknown" just in case some random keyboard has some key that isn't included. You just index it by the keycode.

Better yet, I'll just add it here in case someone else needs it. Just change _fhinputKeys to whatever variable name you prefer. For earlier versions than the new 2.3, you want to run this in some create event or similar. For 2.3, you could stick it in a script resource since those get ran when your game first runs. In that second case you could remove the "global." parts since any variables created in script resources in 2.3 are considered global. If I'm missing any keys that you know of, feel free to let me know(I can add them to my system too). You will notice the ordering of the thing is actually left to right, top to bottom of the physical keyboard, not in order of the actual keycodes.
Code:
for(var i = 0; i < 256; i++)
{
    global._fhinputKeys[i] = "Unknown";
}
global._fhinputKeys[vk_escape] = "Escape";
global._fhinputKeys[vk_f1] = "F1";
global._fhinputKeys[vk_f2] = "F2";
global._fhinputKeys[vk_f3] = "F3";
global._fhinputKeys[vk_f4] = "F4";
global._fhinputKeys[vk_f5] = "F5";
global._fhinputKeys[vk_f6] = "F6";
global._fhinputKeys[vk_f7] = "F7";
global._fhinputKeys[vk_f8] = "F8";
global._fhinputKeys[vk_f9] = "F9";
global._fhinputKeys[vk_f10] = "F10";
global._fhinputKeys[vk_f11] = "F11";
global._fhinputKeys[vk_f12] = "F12";
global._fhinputKeys[145] = "Scroll Lock";
global._fhinputKeys[vk_pause] = "Pause";
global._fhinputKeys[192] = "Tilde(~)";
global._fhinputKeys[49] = "1";
global._fhinputKeys[50] = "2";
global._fhinputKeys[51] = "3";
global._fhinputKeys[52] = "4";
global._fhinputKeys[53] = "5";
global._fhinputKeys[54] = "6";
global._fhinputKeys[55] = "7";
global._fhinputKeys[56] = "8";
global._fhinputKeys[57] = "9";
global._fhinputKeys[48] = "0";
global._fhinputKeys[189] = "Dash(-)";
global._fhinputKeys[187] = "Equals(=)";
global._fhinputKeys[vk_backspace] = "Backspace";
global._fhinputKeys[65] = "A";
global._fhinputKeys[66] = "B";
global._fhinputKeys[67] = "C";
global._fhinputKeys[68] = "D";
global._fhinputKeys[69] = "E";
global._fhinputKeys[70] = "F";
global._fhinputKeys[71] = "G";
global._fhinputKeys[72] = "H";
global._fhinputKeys[73] = "I";
global._fhinputKeys[74] = "J";
global._fhinputKeys[75] = "K";
global._fhinputKeys[76] = "L";
global._fhinputKeys[77] = "M";
global._fhinputKeys[78] = "N";
global._fhinputKeys[79] = "O";
global._fhinputKeys[80] = "P";
global._fhinputKeys[81] = "Q";
global._fhinputKeys[82] = "R";
global._fhinputKeys[83] = "S";
global._fhinputKeys[84] = "T";
global._fhinputKeys[85] = "U";
global._fhinputKeys[86] = "V";
global._fhinputKeys[87] = "W";
global._fhinputKeys[88] = "X";
global._fhinputKeys[89] = "Y";
global._fhinputKeys[90] = "Z";
global._fhinputKeys[219] = "L Bracket([)";
global._fhinputKeys[221] = "R Bracket(])";
global._fhinputKeys[220] = "Backslash(\\)";
global._fhinputKeys[20] = "Capslock";
global._fhinputKeys[186] = "Semi-Colon(;)";
global._fhinputKeys[222] = "Apostrophe(')";
global._fhinputKeys[13] = "Enter";
global._fhinputKeys[160] = "L Shift";
global._fhinputKeys[161] = "R Shift";
global._fhinputKeys[162] = "L Control";
global._fhinputKeys[163] = "R Control";
global._fhinputKeys[164] = "L Alt";
global._fhinputKeys[165] = "R Alt";
global._fhinputKeys[188] = "Comma(,)";
global._fhinputKeys[190] = "Period(.)";
global._fhinputKeys[191] = "Slash(/)";
global._fhinputKeys[vk_space] = "Spacebar";
global._fhinputKeys[93] = "Apps";
global._fhinputKeys[vk_insert] = "Insert";
global._fhinputKeys[vk_home] = "Home";
global._fhinputKeys[vk_pageup] = "Page Up";
global._fhinputKeys[vk_delete] = "Delete";
global._fhinputKeys[vk_end] = "End";
global._fhinputKeys[vk_pagedown] = "Page Down";
global._fhinputKeys[144] = "Numlock";
global._fhinputKeys[111] = "Numpad Slash(/)";
global._fhinputKeys[106] = "Numpad Asterisk(*)";
global._fhinputKeys[109] = "Numpad Dash(-)";
global._fhinputKeys[vk_numpad0] = "Numpad 0";
global._fhinputKeys[vk_numpad1] = "Numpad 1";
global._fhinputKeys[vk_numpad2] = "Numpad 2";
global._fhinputKeys[vk_numpad3] = "Numpad 3";
global._fhinputKeys[vk_numpad4] = "Numpad 4";
global._fhinputKeys[vk_numpad5] = "Numpad 5";
global._fhinputKeys[vk_numpad6] = "Numpad 6";
global._fhinputKeys[vk_numpad7] = "Numpad 7";
global._fhinputKeys[vk_numpad8] = "Numpad 8";
global._fhinputKeys[vk_numpad9] = "Numpad 9";
global._fhinputKeys[110] = "Numpad Period(.)";
global._fhinputKeys[107] = "Numpad Plus(+)";
global._fhinputKeys[vk_left] = "Left Arrow";
global._fhinputKeys[vk_right] = "Right Arrow";
global._fhinputKeys[vk_up] = "Up Arrow";
global._fhinputKeys[vk_down] = "Down Arrow";
 

Gamebot

Member
I don't know if this will help in anyway but here it goes. This is only the idea actual code may need to be altered slightly.

You can use chr() for all keys EXCEPT vk's. However the way GM handles keys are a bit different. So...

CREATE:
Code:
// A-Z , a-z , 0-9 and all symbols above numbers plus space (The only vk here)
Keys = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 "
CHECK:
Code:
// Get keyboard key (real number)
var key = argument0; (keyboard key)
var place = argument1; (ie: global.up )
var mykey =  0;

// Check for available char keys (var keys) against our keyboard_key (key)
// Note that if we are > 127 this is all other symbols. (ie <> {} [] ; . ,)

  if (string_count(chr(key), keys) == 1 || key > 127) {   
  place = key;
}
}

     // Check for "vk" keys

    switch(argument0){
   case vk_left:         place = vk_enter ; break;
   case vk_f1:           place = vk_f1; break;
}
 
D

Deleted member 45063

Guest
Other than creating some lookup data structure you'd probably only get away with it by using some OS specific input library.

One question for your solution though @kburkhart84: Have you tried it with different keyboard layouts? Because usually symbol keys vary wildly between different keyboard layouts, the reason why games tend to rely on input libraries to do such mapping for them. I have access to a Portuguese layout, a German layout and a US layout keyboard so I can give it a try sometime during the day, but I was curious if you already had done some testing there.
 

kburkhart84

Firehammer Games
Other than creating some lookup data structure you'd probably only get away with it by using some OS specific input library.

One question for your solution though @kburkhart84: Have you tried it with different keyboard layouts? Because usually symbol keys vary wildly between different keyboard layouts, the reason why games tend to rely on input libraries to do such mapping for them. I have access to a Portuguese layout, a German layout and a US layout keyboard so I can give it a try sometime during the day, but I was curious if you already had done some testing there.
For all the input stuff I mess with, it didn't occur to me to mess with different regions, etc... I'm sure my system will work fine with all the different ones, but the description could indeed be wrong. If you know of some documentation somewhere that documents region's keycode mappings, I'd love to see it, so I can update my system to have multiple maps.
 

TheouAegis

Member
It's keycode is "112" However using chr(112) I get "p" because "p"'s code is "11"
It returns "p" because 112 is the ASCII code for "p". A key's code and a character's code are two different values. chr() translates the ASCII character code.

ASCII codes are very handy to have referenced. Just Google "ascii chart" and knock yourself out. You can start doing all kinds of fun algorithms with that information on hand.
 

Yal

🐧 *penguin noises*
GMC Elder
I would be glad to give you the one I use for exactly that purpose if you want it. Its part of my configuration system. It is basically a 256 item array, with some of them set to "Unknown" just in case some random keyboard has some key that isn't included. You just index it by the keycode.

Better yet, I'll just add it here in case someone else needs it. Just change _fhinputKeys to whatever variable name you prefer. For earlier versions than the new 2.3, you want to run this in some create event or similar. For 2.3, you could stick it in a script resource since those get ran when your game first runs. In that second case you could remove the "global." parts since any variables created in script resources in 2.3 are considered global. If I'm missing any keys that you know of, feel free to let me know(I can add them to my system too). You will notice the ordering of the thing is actually left to right, top to bottom of the physical keyboard, not in order of the actual keycodes.
Code:
for(var i = 0; i < 256; i++)
{
    global._fhinputKeys[i] = "Unknown";
}
global._fhinputKeys[vk_escape] = "Escape";
global._fhinputKeys[vk_f1] = "F1";
global._fhinputKeys[vk_f2] = "F2";
global._fhinputKeys[vk_f3] = "F3";
global._fhinputKeys[vk_f4] = "F4";
global._fhinputKeys[vk_f5] = "F5";
global._fhinputKeys[vk_f6] = "F6";
global._fhinputKeys[vk_f7] = "F7";
global._fhinputKeys[vk_f8] = "F8";
global._fhinputKeys[vk_f9] = "F9";
global._fhinputKeys[vk_f10] = "F10";
global._fhinputKeys[vk_f11] = "F11";
global._fhinputKeys[vk_f12] = "F12";
global._fhinputKeys[145] = "Scroll Lock";
global._fhinputKeys[vk_pause] = "Pause";
global._fhinputKeys[192] = "Tilde(~)";
global._fhinputKeys[49] = "1";
global._fhinputKeys[50] = "2";
global._fhinputKeys[51] = "3";
global._fhinputKeys[52] = "4";
global._fhinputKeys[53] = "5";
global._fhinputKeys[54] = "6";
global._fhinputKeys[55] = "7";
global._fhinputKeys[56] = "8";
global._fhinputKeys[57] = "9";
global._fhinputKeys[48] = "0";
global._fhinputKeys[189] = "Dash(-)";
global._fhinputKeys[187] = "Equals(=)";
global._fhinputKeys[vk_backspace] = "Backspace";
global._fhinputKeys[65] = "A";
global._fhinputKeys[66] = "B";
global._fhinputKeys[67] = "C";
global._fhinputKeys[68] = "D";
global._fhinputKeys[69] = "E";
global._fhinputKeys[70] = "F";
global._fhinputKeys[71] = "G";
global._fhinputKeys[72] = "H";
global._fhinputKeys[73] = "I";
global._fhinputKeys[74] = "J";
global._fhinputKeys[75] = "K";
global._fhinputKeys[76] = "L";
global._fhinputKeys[77] = "M";
global._fhinputKeys[78] = "N";
global._fhinputKeys[79] = "O";
global._fhinputKeys[80] = "P";
global._fhinputKeys[81] = "Q";
global._fhinputKeys[82] = "R";
global._fhinputKeys[83] = "S";
global._fhinputKeys[84] = "T";
global._fhinputKeys[85] = "U";
global._fhinputKeys[86] = "V";
global._fhinputKeys[87] = "W";
global._fhinputKeys[88] = "X";
global._fhinputKeys[89] = "Y";
global._fhinputKeys[90] = "Z";
global._fhinputKeys[219] = "L Bracket([)";
global._fhinputKeys[221] = "R Bracket(])";
global._fhinputKeys[220] = "Backslash(\\)";
global._fhinputKeys[20] = "Capslock";
global._fhinputKeys[186] = "Semi-Colon(;)";
global._fhinputKeys[222] = "Apostrophe(')";
global._fhinputKeys[13] = "Enter";
global._fhinputKeys[160] = "L Shift";
global._fhinputKeys[161] = "R Shift";
global._fhinputKeys[162] = "L Control";
global._fhinputKeys[163] = "R Control";
global._fhinputKeys[164] = "L Alt";
global._fhinputKeys[165] = "R Alt";
global._fhinputKeys[188] = "Comma(,)";
global._fhinputKeys[190] = "Period(.)";
global._fhinputKeys[191] = "Slash(/)";
global._fhinputKeys[vk_space] = "Spacebar";
global._fhinputKeys[93] = "Apps";
global._fhinputKeys[vk_insert] = "Insert";
global._fhinputKeys[vk_home] = "Home";
global._fhinputKeys[vk_pageup] = "Page Up";
global._fhinputKeys[vk_delete] = "Delete";
global._fhinputKeys[vk_end] = "End";
global._fhinputKeys[vk_pagedown] = "Page Down";
global._fhinputKeys[144] = "Numlock";
global._fhinputKeys[111] = "Numpad Slash(/)";
global._fhinputKeys[106] = "Numpad Asterisk(*)";
global._fhinputKeys[109] = "Numpad Dash(-)";
global._fhinputKeys[vk_numpad0] = "Numpad 0";
global._fhinputKeys[vk_numpad1] = "Numpad 1";
global._fhinputKeys[vk_numpad2] = "Numpad 2";
global._fhinputKeys[vk_numpad3] = "Numpad 3";
global._fhinputKeys[vk_numpad4] = "Numpad 4";
global._fhinputKeys[vk_numpad5] = "Numpad 5";
global._fhinputKeys[vk_numpad6] = "Numpad 6";
global._fhinputKeys[vk_numpad7] = "Numpad 7";
global._fhinputKeys[vk_numpad8] = "Numpad 8";
global._fhinputKeys[vk_numpad9] = "Numpad 9";
global._fhinputKeys[110] = "Numpad Period(.)";
global._fhinputKeys[107] = "Numpad Plus(+)";
global._fhinputKeys[vk_left] = "Left Arrow";
global._fhinputKeys[vk_right] = "Right Arrow";
global._fhinputKeys[vk_up] = "Up Arrow";
global._fhinputKeys[vk_down] = "Down Arrow";
I would use a ds_map for this instead of an array, since there can be some pretty big gaps between some keycodes. When getting the display string from the ds_map, just return a placeholder like "<unknown key>" if the map value is undefined.
 
D

Deleted member 45063

Guest
For all the input stuff I mess with, it didn't occur to me to mess with different regions, etc... I'm sure my system will work fine with all the different ones, but the description could indeed be wrong. If you know of some documentation somewhere that documents region's keycode mappings, I'd love to see it, so I can update my system to have multiple maps.
Digging a bit into it, if you have a linux system you can easily create keymaps for your keyboard with dumpkeys. These will have a specific text-based format (as explained in keymaps). I couldn't find any place to download prebuilt files (but there must be one somewhere, just didn't search for very long). Exporting the layout of my current US keyboard yields this 7532 line text file. In theory it should be able to parse this in GameMaker according to the intended keyboard layout. Of course that you would still need to be able to identify which keymap to use, so at some point you're likely to have to go native.
 
In other words, no there is no inbuilt way to do such a thing and on top of that, because keyboards can't be standardised (due to different regions and setups involving different keys) there's no generalised solution to this. It's a pain in the arse, but sometimes that's the way things are (like resolutions). Do the best you can with all the information in this thread (which is great might I say) and then deal with problems as they arise.
 

Evanski

Raccoon Lord
Forum Staff
Moderator
It returns "p" because 112 is the ASCII code for "p". A key's code and a character's code are two different values. chr() translates the ASCII character code.

ASCII codes are very handy to have referenced. Just Google "ascii chart" and knock yourself out. You can start doing all kinds of fun algorithms with that information on hand.
In other words, no there is no inbuilt way to do such a thing and on top of that, because keyboards can't be standardised (due to different regions and setups involving different keys) there's no generalised solution to this. It's a pain in the arse, but sometimes that's the way things are (like resolutions). Do the best you can with all the information in this thread (which is great might I say) and then deal with problems as they arise.
I may try and see if I can get away with using Ascii if not I may look into figuring out the keyboard_map functions
 

kburkhart84

Firehammer Games
I may try and see if I can get away with using Ascii if not I may look into figuring out the keyboard_map functions
I can tell you that ASCII codes won't work for this...there are no valid codes for F1, etc... as I understand things, so you will still need to figure out using the vk_ keycodes.

I would use a ds_map for this instead of an array, since there can be some pretty big gaps between some keycodes. When getting the display string from the ds_map, just return a placeholder like "<unknown key>" if the map value is undefined.
This isn't a bad idea...but I think I'll just keep it as arrays. There are indeed gaps, but I don't think they are worth trying to optimize out at I only have 256 values in the array. I automatically put "Unknown" in the array wherever there isn't a key, so keeping the array is really nice and efficient, and I don't think switching to a ds_map would really get me any gains that would be worth it.

Digging a bit into it, if you have a linux system you can easily create keymaps for your keyboard with dumpkeys. These will have a specific text-based format (as explained in keymaps). I couldn't find any place to download prebuilt files (but there must be one somewhere, just didn't search for very long). Exporting the layout of my current US keyboard yields this 7532 line text file. In theory it should be able to parse this in GameMaker according to the intended keyboard layout. Of course that you would still need to be able to identify which keymap to use, so at some point you're likely to have to go native.
I don't have a Linux system running currently(I've used VMs and dual-boot to get Ubuntu running in the past though). I also don't have anything set up for different regions except for American English. I'm likely going to just do some googling and figure things out, there is likely documentation somewhere about it. I would also need both a way to figure out what the region is so I can have it use that array of codes instead...and I would want to find some people with those different regional settings so I can properly test on real regional keyboards.
 

kburkhart84

Firehammer Games
From what I can tell, most keycodes don't change. Which would make sense, since it would be imperative that they work uniformly. This article mentions differences between browsers and OS.
I just looked at some pics of keyboards here. For an AZERTY keyboard, would the keycodes for A and Q for example be switched(so the code stays around the same physical area), or would the keycode follow the letter? And on the Latin American keyboard, they put the ñ where the semi-colon goes on English keyboards, as well as adding a < and > key between left shift and letter Z(since they put the semi-colon where those are in English keyboards). Any ideas what keycode changes were made, and if they tried to keep the physical locations the same keycodes or any idea exactly what is being done for those keys? I'm hoping the majority aren't changed, but who knows?
 
D

Deleted member 45063

Guest
I just looked at some pics of keyboards here. For an AZERTY keyboard, would the keycodes for A and Q for example be switched(so the code stays around the same physical area), or would the keycode follow the letter? And on the Latin American keyboard, they put the ñ where the semi-colon goes on English keyboards, as well as adding a < and > key between left shift and letter Z(since they put the semi-colon where those are in English keyboards). Any ideas what keycode changes were made, and if they tried to keep the physical locations the same keycodes or any idea exactly what is being done for those keys? I'm hoping the majority aren't changed, but who knows?
Well, I can tell in the German layout (QWERTZ) with GM, Z seems to work as expected (Z actually maps to Z, which can be really annoying when it was meant to be in a different position, but oh well). Other examples:
- Dash is the same, but equals doesn't really work with keyboard_key as it is since it requires Shift + 0.
- Shift seems to return always 16 regardless of right or left shift
- 222 is apostrophe in your array but in the German layout it is ä
etc etc. So there are differences (my guess is GM does try to abstract away the more common keycodes like letters and such but it doesn't do that for the remaining ones, this because I know of some non-GM games that tell me to press Z and in the German keyboard I need to press Y due to the whole QWERTZ situation, or vice versa).

Btw, to test I just created a sample project that draws the value of keyboard_key.

EDIT: Ohh and in the German layout there is also a < > between left shift and Y (or Z in US layout), in fact it is actually < > | (all three of them xD). If I press it without any modifiers it outputs 226

EDIT 2: The < > | key on my laptop's German keyboard is to the right of the right alt, but the keycode is the same since it is the effectively the same keyboard layout, just the physical keys are in different places.
 
Last edited by a moderator:

kburkhart84

Firehammer Games
Well, I can tell in the German layout (QWERTZ) with GM, Z seems to work as expected (Z actually maps to Z, which can be really annoying when it was meant to be in a different position, but oh well). Other examples:
- Dash is the same, but equals doesn't really work with keyboard_key as it is since it requires Shift + 0.
- Shift seems to return always 16 regardless of right or left shift
- 222 is apostrophe in your array but in the German layout it is ä
etc etc. So there are differences (my guess is GM does try to abstract away the more common keycodes like letters and such but it doesn't do that for the remaining ones, this because I know of some non-GM games that tell me to press Z and in the German keyboard I need to press Y due to the whole QWERTZ situation, or vice versa).

Btw, to test I just created a sample project that draws the value of keyboard_key.

EDIT: Ohh and in the German layout there is also a < > between left shift and Y (or Z in US layout), in fact it is actually < > | (all three of them xD). If I press it without any modifiers it outputs 226

EDIT 2: The < > | key on my laptop's German keyboard is to the right of the right alt, but the keycode is the same since it is the effectively the same keyboard layout, just the physical keys are in different places.

There you go, so at least in this case it seems that letters' keycodes follow the letter around, but other characters can be quite different, as some of them don't even exist(as base keys without modifiers) on different keyboards, while other characters that are only output as modified keypresses have their own dedicated base key. I wonder if there is any documentation on this kind of thing somewhere.

About the two shifts returning the same...did you try using keyboard_check_direct()? I use that when on Windows(and haven't done much testing outside of Windows anyway) because it lets you use left and right shift/alt/ctl as separate codes.
 
D

Deleted member 45063

Guest
About the two shifts returning the same...did you try using keyboard_check_direct()? I use that when on Windows(and haven't done much testing outside of Windows anyway) because it lets you use left and right shift/alt/ctl as separate codes.
Well, if I check for it explicitly I can differentiate, but in my example project I was focused only on checking the keycode reported by GM on keyboard_key
 

kburkhart84

Firehammer Games
Well, if I check for it explicitly I can differentiate, but in my example project I was focused only on checking the keycode reported by GM on keyboard_key
Indeed, this is kinda why I wasn't too worried about testing on other platforms than Windows so much, because I have no idea what GM is doing behind the scenes with the non-direct checking. I more understand the direct keycode checking but that doesn't happen except on Windows according to the manual.
 
X

Xenosis

Guest
function key_to_letter(key) {
var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
return string_char_at(letters, (key - 64));
}
 

Yal

🐧 *penguin noises*
GMC Elder
function key_to_letter(key) {
var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
return string_char_at(letters, (key - 64));
}
Only works if the key is a letter key, and the OP specifically had issues with the function keys mapping to values in the letter range.
 
Top