Keyboard keycode

0 favourites
  • 9 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • Hi,

    is it possible to return the keycode and the key pressed with the Keyboard Event.

    I want to allow custom keys for the player to set.

    I would like to show the player what key they have pressed rather than the keycode which isnt much use to them. I suppose i could create some sort of lookup table for all the options but i am not sure if the keycode relates to the same key on all keyboards.

    Thanks.

  • I'm not exactly sure if this is what you mean, but...

    you could create a text box and set it to what ever that person types until a button or key is pressed, eg. enter, it then sets that custom key.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • thanks but not really. I need both the keycode and the actual key pressed.

    Mainly so i can set variables using the keycode and display the key chosen on screen.

  • The keycode you can get from the keyboard plugin.

    For the character related to the code I've faced the same issue as you and started a plugin allowing to do this "translation" with a simple expression.

    You can check it out here (example capx provided).

    To answer the question as whether keycodes are different from a keyboard to another, I have an AZERTY keyboard and A = 65, Q = 81.

    Let me know if this is different on QWERTY.

    The plugin provided here is not an official/supported release and keys like "Shift" or "Escape" will return nothing but some blank space.

    The space keyboard will return a "SPACE" mention because so far it's the only key I've "intercepted" and replaced so far.

    Use at your own risks, no warranty whatsoever.

  • I haven't actually tried using the Dictionary object, but in the meantime you should be able to create a dictionary object that holds the name of every applicable keyboard key as a value, with the associated dictionary key set as the keycode.

    This way, when someone presses a key and you read the keycode, you can compare it against the dictionary and get the actual key name.

  • Kyatric

    Thanks for that i will check it out. The key codes are the same on my qwerty keyboard as yours. I assume the codes are just standard ascii.

    grimwolf

    Thanks , I had thought of using the dictionary object but as i said i wasnt totally sure the keys on all keyboards map to the same keycode.

  • Kyatric

    Your plugin works fine, although keys 1 to 9 on the numeric keypad ( with numlock on ) doesnt show numbers it shows lowercase letters a to i.

    Not a major problem but maybe a bit confusing for someone defining their own keys <img src="smileys/smiley1.gif" border="0" align="middle" />

  • I'm almost certain all keyboards use the same keycodes. If I'm right those codes are what are used in any game to determine exactly what a particular key press should do. While searching online for key code definitions I've not found multiple forms either.

  • Yes, all keycodes are the same, they are based off of the ASCII chart that you can pretty much be googled online (all hail our google overlords). Most programmers would use the HEX values and decipher them into binary for commands, but in scirra, im pretty sure they use the decimal value as a way to track the key presses (most likely all in capital letters).

    (A:) Dec value = 65, HEX = 41

    (B:) Dec value = 66, HEX = 42

    etc.

    If you do not understand how HEX works, instead of just numbers, it goes from 0 - F, meaning it counts down from 0 1 2 3 4 5 6 7 8 9 A B C D E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F, and so on.

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