• 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 (Solved) I need help getting the Constant of a certain keyboard character

Evanski

Raccoon Lord
Forum Staff
Moderator
So the enter key is vk_enter.

what is the Constant of "\"

The UTF8 code of it is 220.

Im using this in a switch statement like so:
Code:
switch(keyboard_lastchar) //what to do based on certain keys
    {
       
        case(ord(220)) : text += "\\"; break;
       
        default: text += keyboard_lastchar; break;
    }
but it gives the error of needing the Case to be a Constant.
I cant use
Code:
ord("\")
because it turns the whole line into a string.


So how do I write it so that I can get a input for pressing the "\" key
 
Last edited:

Binsk

Member
You can just use the key code without the ord and it will work just fine.

The issue is using a function inside of the case.
Using ord("\\") is identical to just using 220.
 

jo-thijs

Member
So the enter key is vk_enter.

what is the Constant of "\"

The UTF8 code of it is 220.

Im using this in a switch statement like so:
Code:
switch(keyboard_lastchar) //what to do based on certain keys
    {
    
        case(ord(220)) : text += "\\"; break;
    
        default: text += keyboard_lastchar; break;
    }
but it gives the error of needing the Case to be a Constant.
I cant use
Code:
ord("\")
because it turns the whole line into a string.


So how do I write it so that I can get a input for pressing the "\" key
You can just use the key code without the ord and it will work just fine.

The issue is using a function inside of the case.
Using ord("\\") is identical to just using 220.
1) The function "ord" returns the ASCII code of a characer, not the UTF8 code, so ord("\\") returns 92, not 220.
2) "keyboard_lastchar" contains a character, not a number. You need to have a case "\\" instead.
3) I'm not sure if the key code for the \-key is consistent over keyboards, but for me it's 226.

EDIT: nvm point 1
EDIT: I still get 92 returned from ord("\\") and 92 seems to be the UTF8 code of \ when I look it up as well. Why did you think it was 220?
 
Last edited by a moderator:

Evanski

Raccoon Lord
Forum Staff
Moderator
1) The function "ord" returns the ASCII code of a characer, not the UTF8 code, so ord("\\") returns 92, not 220.
2) "keyboard_lastchar" contains a character, not a number. You need to have a case "\\" instead.
3) I'm not sure if the key code for the \-key is consistent over keyboards, but for me it's 226.

EDIT: nvm point 1
EDIT: I still get 92 returned from ord("\\") and 92 seems to be the UTF8 code of \ when I look it up as well. Why did you think it was 220?
I had keyboard_last key read back to as a string, pressed the key it gave me 220

but my problem was that my code wasnt allowing \ to be a valid key to press, so it works just fine as ord("\\")
 
Top