0 Favourites

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

  • 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!

  • 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...

  • here is capx

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • Thanks for the information podpathos.

    I'll see it.

    Many thanks!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)