How do I detect keyboard keycode 97?

Get help using Construct 2

Post » Tue Jan 19, 2016 8:52 am

So, I'm trying to test whether Construct 2 can detect the keycode for both "A" and "a", turns out Construct can only detect keycode 65 (for "A") and not 97 (for "a") because the debug text object doesn't show anything when I use event On keyboard key code 97 pressed.

Does anyone know how do I detect "a" keycode? Because I want to do something different when the keycode for "A" and "a" are pressed.

thanks.
B
45
S
13
G
2
Posts: 173
Reputation: 5,326

Post » Tue Jan 19, 2016 9:19 am

It's the same key on the keyboard, so the keycode would be the same. I guess you could also check if shift held down.

Here is a list of the keycodes reported by javascript, which C2 uses:
http://www.cambiaresearch.com/articles/ ... -key-codes
97 is Numpad 1 in that list.

I think what you wanted was the charCode which could give you a 97 for "a", but the keyboard object doesn't provide that.
B
89
S
30
G
95
Posts: 5,157
Reputation: 63,450

Post » Tue Jan 19, 2016 9:25 am

Daggio wrote:So, I'm trying to test whether Construct 2 can detect the keycode for both "A" and "a", turns out Construct can only detect keycode 65 (for "A") and not 97 (for "a") because the debug text object doesn't show anything when I use event On keyboard key code 97 pressed.

Does anyone know how do I detect "a" keycode? Because I want to do something different when the keycode for "A" and "a" are pressed.

thanks.


Not sure why Keyboard.LastKeyCode doesn't return full ASCII codes. Maybe @Ashley can clarify.


Since all lower case letters are equal to the keycode for the uppercase + 32, you could do it in Events.

For instance,

IF SHIFT (or CAPS) IS DOWN set keyvariable to Keyboard.LastKeyCode+32
ELSE set keyvariable Keyboard.LastKeyCode

Would this be of use?
If your vision so exceeds your ability, then look to something closer.
Moderator
B
129
S
29
G
77
Posts: 5,196
Reputation: 54,299

Post » Tue Jan 19, 2016 10:43 am

@R0J0hound : yes, I think you're right, it's charCode that I want. I just didn't remember it, if only I can get charCode for C2

@zenox98 : I haven't tried that, I tried this
Keyboard On A pressed AND keyboard Shift is down | Do action here

but then both this event and the event without shift is down are triggered, so I didn't use it.
B
45
S
13
G
2
Posts: 173
Reputation: 5,326

Post » Tue Jan 19, 2016 1:00 pm

Daggio wrote:Keyboard On A pressed AND keyboard Shift is down | Do action here

but then both this event and the event without shift is down are triggered, so I didn't use it.


So adding a shift is NOT down to the first event would prevent that, right?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Tue Jan 19, 2016 7:11 pm

You can use the browser object to get the charcode instead of the keycode. It can't be a trigger, so instead a list of keys pressed that tick is made and looped over.
https://dl.dropboxusercontent.com/u/542 ... rcode.capx
B
89
S
30
G
95
Posts: 5,157
Reputation: 63,450

Post » Wed Jan 20, 2016 4:57 am

@LitteStain: ah,of course. How come I didn't see the obvious fix??

@R0J0hound: I'll try that capx, hopefully it's good enough. thanks.
B
45
S
13
G
2
Posts: 173
Reputation: 5,326


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 1 guest