String from key code

Get help using Construct 2

Post » Wed Apr 03, 2013 10:05 pm

I'm using Keyboard.StringFromKeyCode(Keyboard.LastKeyCode) to retrieve the name of the last key pressed, for my control config.

For whatever reason it works perfectly for everything but the arrow keys; up, right, and left return a blank string and down returns "(".

Same results in 2 projects. Anyone else have this problem?
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Post » Wed Apr 03, 2013 10:53 pm

Yeah seems it only works for letters and numbers. You better handle other keys yourself.
http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Wed Apr 03, 2013 11:17 pm

Ah. I didn't try it with anything other than letters and the arrow keys. Not really sure how to go about that without an event for every key :\

@Ashley would it be possible to add the rest of the strings at some point? Tokinsom2013-04-04 07:18:51
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Post » Thu Apr 04, 2013 2:07 pm

Yeah. Someone suggested I add an expression to wrap the browser fromCharCode function, but it turns out the browser's function is nearly completely useless. So I'll have to rewrite it to not use that function :P
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Wed Apr 10, 2013 8:34 pm

@Ashley Thanks for fixing this in r125. There still aren't any strings for the arrow keys, however. Could you please add those in the next build?
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Post » Wed Apr 10, 2013 8:51 pm

The arrow keys use the unicode symbols for arrows pointing left, up, right and down. They appeared fine for me, but maybe you're using a different font? Perhaps that was too clever to try and use symbols, and I should just replace them with words...
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Wed Apr 10, 2013 9:24 pm

Aha. I'm using a custom bitmap font so that would explain it. Not sure how that's supposed to work with the spritefont plugin though..What would the arrows be on the charmap?Tokinsom2013-04-10 21:30:43
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Post » Wed Apr 10, 2013 10:55 pm

Well, a left arrow is U+2190. A lot of spritefont engines don't support non-ASCII characters, which is quite a big limitation (good luck if you speak a non-latin language). Luckily C2 and all modern browsers support unicode, so you should be able to do something like: if keystring = "?", set to "left arrow".
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580


Return to How do I....?

Who is online

Users browsing this forum: makkancs and 25 guests