Getting keycode from a Keyboard

Discussion and feedback on Construct 2

Post » Tue Nov 22, 2016 12:25 am

I read a lot of posts about which the keyboard has a specific "key code" for each key pressed. And there's differences between indexing that code for QWERTY/AZERTY keyboards.

But, my question is ¿How I can get that "code"?
For example, i want to get the key code of "ctrl" and "p" keys, So that at the moment of pressing them: another event occurs.

And in c2 to create an event like: if key code is down of "..." & "..." -> something happen.

Sorry, if my english isn't excellent ~
B
11
S
2
G
2
Posts: 13
Reputation: 1,144

Post » Tue Nov 22, 2016 1:41 am

I think this post is useful for you.

https://www.reddit.com/r/olkb/comments/ ... y_keycode/
B
22
S
9
G
9
Posts: 38
Reputation: 6,128

Post » Tue Nov 22, 2016 1:51 am

In addition to @shinichild:

If you simply need the key codes "offline", so not live inside a program, you can create a helper, which shows the key code for the currently pressed button by accessing the expression "Keyboard.LastKeyCode".
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Tue Nov 22, 2016 2:04 am

Not sure why you need a particular key code.

Try the following and see if it may help you out:

1. In your layout, insert new object and choose the keyboard.
2. In your event sheet, "add event" and choose keyboard. Under Keyboard, select "On Key Pressed" -> "Key". When prompted to choose the key you want, just press the "P" on whatever keyboard you are using and C2 will record that key.
3. Go back to the same keyboard event in 2 above and "add another condition" and follow the prompts above. When prompted for a key, press the "Ctrl". At this point you will have two conditions that you want met (Ctrl + P) before your chosen action happens.
4. Then create the action you want to take place.

Caution: Probably most of the world uses the "QWERTY", but there are many other designs as you have found out and it would be difficult to capture all possible corresponding key codes anyway.

One solution is to create you own custom controls on the HUD such as sprite arrows. That way, all and sundry will have to use that set of controls as designed by yourself.

Good luck!
B
21
S
14
G
15
Posts: 14
Reputation: 16,248

Post » Tue Nov 22, 2016 10:16 am

@shinichild and @randomly thank you guys!
@KoolEcky I know, but it's more to learn how the keyboard works, thanks anyways ;)
B
11
S
2
G
2
Posts: 13
Reputation: 1,144


Return to Construct 2 General

Who is online

Users browsing this forum: brupibo and 12 guests