convert keycode to string

Get help using Construct 2

Post » Fri Jan 11, 2013 5:13 am

Was wondering how do i display the keycode shown as the key letter/number that is pressed?
B
50
S
11
G
7
Posts: 274
Reputation: 8,146

Post » Fri Jan 11, 2013 5:47 am

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....
B
49
S
11
G
10
Posts: 1,833
Reputation: 14,418

Post » Fri Jan 11, 2013 5:53 am

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...
B
49
S
11
G
10
Posts: 1,833
Reputation: 14,418

Post » Fri Jan 11, 2013 6:09 am

[QUOTE=BluePhaze] 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...[/QUOTE]

It's alright. Yeah, there doesn't seem to be an expression for this. Maybe @Ashley can comment on this?
B
50
S
11
G
7
Posts: 274
Reputation: 8,146

Post » Fri Jan 11, 2013 12:52 pm

@Ashley this could make a good addition as an expression for the keyboard plugin? Painless to integrate too with String.fromCharCode(65) == 'A'.
Moderator
B
72
S
13
G
11
Posts: 900
Reputation: 11,783

Post » Fri Jan 18, 2013 4:05 pm

One time bump. Still think it would be really handy.
B
50
S
11
G
7
Posts: 274
Reputation: 8,146

Post » Thu Mar 21, 2013 11:26 pm

@Ashley Yes this is a hassle. Could we please get a function whereby we can retrieve the string from the last keypress/release?
B
31
S
8
G
5
Posts: 436
Reputation: 5,836

Post » Fri Jan 15, 2016 4:25 pm

So we never did get that expression did we....
B
7
S
1
Posts: 15
Reputation: 482

Post » Fri Jan 15, 2016 7:39 pm

@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".
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
53
S
16
G
8
Posts: 6,157
Reputation: 19,744


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 21 guests