1. Hey! Guest! The 32nd GMC Jam will take place between Feb 22nd, 12:00 UTC (Friday noon) and Feb 25th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

GMS 2 (Solved) I need help getting the Constant of a certain keyboard character

Discussion in 'Programming' started by EvanSki, Feb 11, 2019.

  1. EvanSki

    EvanSki Member

    Joined:
    Apr 17, 2018
    Posts:
    301
    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: Feb 12, 2019 at 12:39 AM
  2. Binsk

    Binsk Member

    Joined:
    Jun 22, 2016
    Posts:
    482
    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.
     
  3. EvanSki

    EvanSki Member

    Joined:
    Apr 17, 2018
    Posts:
    301
    Thanks :)
     
  4. jo-thijs

    jo-thijs Member

    Joined:
    Jun 20, 2016
    Posts:
    2,748
    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?
     
  5. EvanSki

    EvanSki Member

    Joined:
    Apr 17, 2018
    Posts:
    301
    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("\\")
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice