[Keyboard]How do I know which key is pressed?

Get help using Construct 2

Post » Thu Oct 11, 2012 3:11 pm

Hello Everyone,

I'm trying to figure how can I do the following:

- I have a numeric sequence on the screen let's say 12345 (this is generated randomlly).
- So I want to compare if the user pressed the same sequence: 1-2-3-4-5

But, It seems that C2 cannot capture the key pressed.
Wish I'd like to do is something like:

- Capture the pressed key
- If this key = [first number on the sequence]
      do....

With the current actions I think I have to do
if keypressed=1
    compare if [first number on the sequence =1]
                 do...

if keypressed=2
            ....
if keypressed=3
               ....

Too much work.
Am I correct? Am I wrong?
Could you please let me know your opinion?

Thanks!
Image
Image
B
26
S
2
G
1
Posts: 71
Reputation: 2,662

Post » Thu Oct 11, 2012 4:39 pm

use array to store radnom sequence in array (w5,h2), to store keys pressed, and to compare them

gvar - npress

on (sommething)
   +for "i" from 0 to 4 => set at x: loopindex, value round(radndom(1,6))

npress not=5
   + key "1" pressed => set at XY: (npress,2), value: 1
                         add 1 to npress
   + key "2" pressed => set at XY: (npress,2), value: 2
                         add 1 to npress
...

npress=5
   + compare at x,y - (comapre random sequence and key stored in array) = > do something...
    reset radnom sequence...
    set npress to 0


I know it's quick and ugly but it may give you general direction...
podpathos2012-10-11 16:42:24
B
12
S
2
G
2
Posts: 96
Reputation: 1,583

Post » Thu Oct 11, 2012 6:26 pm

here is capx
B
12
S
2
G
2
Posts: 96
Reputation: 1,583

Post » Thu Oct 11, 2012 7:11 pm

Thanks for the information podpathos.

I'll see it.

Many thanks!
Image
Image
B
26
S
2
G
1
Posts: 71
Reputation: 2,662


Return to How do I....?

Who is online

Users browsing this forum: Timedoor Indones and 24 guests