convert keycode to string

0 favourites
  • 9 posts
From the Asset Store
This collection of music is the beautiful performance of rather small strings ensemble (8 first violins, 6 second violin
  • Was wondering how do i display the keycode shown as the key letter/number that is pressed?

  • I played around a little after reading your question and came up with a partial solution:

    Create a global variable called keyPressed

    Then create an event for Keyboard any key pressed

    what I do then is the following in my event sheet:

    Keyboard On any key pressed System Set keyPressed to Keyboard.LastKeyCode

    Then I have another action in the event that sets the text of a text object called keyPressedText to the keyboard lastkeycode like this:

    keyPressText Set text to keyPressed

    This does what I want, the only issue is that the value of Keyboard.LastKeyCode is a number that represents which key was pressed, if anyone has a way to actually get the name of the key. I guess you could always create an array of the keys and their values and pull from it based on the LastKeyCode... hope this helps a little....

  • I just re-read your initial question and realized you have already gotten as far as I have most likely. So sorry if I wasted your time with my reply. There must be a way to pull it as they have a list that is hooked up to the keypress action. Unless they are pulling them from an array or something...

  • I just re-read your initial question and realized you have already gotten as far as I have most likely. So sorry if I wasted your time with my reply. There must be a way to pull it as they have a list that is hooked up to the keypress action. Unless they are pulling them from an array or something...

    It's alright. Yeah, there doesn't seem to be an expression for this. Maybe Ashley can comment on this?

  • Ashley this could make a good addition as an expression for the keyboard plugin? Painless to integrate too with String.fromCharCode(65) == 'A'.

  • One time bump. Still think it would be really handy.

  • Ashley Yes this is a hassle. Could we please get a function whereby we can retrieve the string from the last keypress/release?

  • So we never did get that expression did we....

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • cmontville89

    Yes we did..

    https://www.scirra.com/manual/113/keyboard

    StringFromKeyCode

    Convert a numerical key code back in to a string representation. For example this turns the key code 65 in to the string "A".

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)