Keyboard keycode

Get help using Construct 2

Post » Tue Mar 05, 2013 12:39 pm

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.
B
44
S
15
G
9
Posts: 1,096
Reputation: 11,013

Post » Tue Mar 05, 2013 12:43 pm

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.
B
7
S
2
Posts: 18
Reputation: 891

Post » Tue Mar 05, 2013 12:51 pm

@ninonic

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.

B
44
S
15
G
9
Posts: 1,096
Reputation: 11,013

Post » Tue Mar 05, 2013 3:07 pm

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.Kyatric2013-03-05 15:08:11
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791

Post » Tue Mar 05, 2013 4:45 pm

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.
B
6
S
1
Posts: 67
Reputation: 986

Post » Tue Mar 05, 2013 4:56 pm

@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.
B
44
S
15
G
9
Posts: 1,096
Reputation: 11,013

Post » Tue Mar 05, 2013 5:12 pm

@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
B
44
S
15
G
9
Posts: 1,096
Reputation: 11,013

Post » Tue Mar 05, 2013 5:41 pm

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.
B
6
S
1
Posts: 67
Reputation: 986

Post » Fri Jul 05, 2013 10:10 am

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.
B
6
Posts: 3
Reputation: 260


Return to How do I....?

Who is online

Users browsing this forum: adi pratama and 27 guests