How do I create a typing simulator

  • I am trying to create a typing simulator and I need to calculate the speed of the typing and I don't know how I can do this.

  • You need to save the time when typing starts in a variable: gameStart=time

    When the last correct character is typed, you can calculate the speed:

    speed= (number of characters) / (time-gameStart)

    Multiply it by 60 to get characters per minute.

    If you need to count words per minute, this might be a little more complex.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You need to save the time when typing starts in a variable: gameStart=time

    When the last correct character is typed, you can calculate the speed:

    speed= (number of characters) / (time-gameStart)

    Multiply it by 60 to get characters per minute.

    If you need to count words per minute, this might be a little more complex.

    Hi

    Thanks for answering. I just want to count the characters.

    So I have to register the initial time and count all the characters the user typed at the same time that I need to divide it per initial time? Wiil I get this value in real time (as the user type the characters?) I read something about PPM but I don't know how to implement it.

  • Yes, you can display the speed in real time.

    speedPerSecond= (correctlyTypedCharacters) / (time-gameStartTime)

    speedPerMinute=speedPerSecond*60

    If you want round this number to two decimal places:

    speedPerMinute = round(speedPerMinute * 100) / 100

    I believe PPM refers to "Pages per minute" and it's used to measure performance of printers and photocopiers:)

  • Thank you

  • I think I am doing something wrong. The value is increasing instead of showing the typing speed

    A summary of my code:

    On any key pressed: call checkKey()
                        call calculateTime()
                        controllStartGame = 0 : controllStartGame = 1
                                                startGame = wallclocktime
    on calculateTime: System keyOrder isTrue: add 1 to totalHits
    
    on checkKey:  speedPerSecond= (totalHits) / (startGame)
                  speedPerMinute=speedPerSecond*60
                  textObject : set text to round(speedPerMinute * 100) / 100[/code:19tt8cxv]
  • "startGame = wallclocktime" should only be executed once on start of the game (level), not on every pressed key.

    This formula is also incorrect:

    speedPerSecond= (totalHits) / (startGame)

    Change it to:

    speedPerSecond= (totalHits) / (wallclocktime-startGame)

  • "startGame = wallclocktime" should only be executed once on start of the game (level), not on every pressed key.

    It happens once when the user press the 1st key but I moved this command to the start of the layout.

    [quote:3ijb3v58]This formula is also incorrect:

    speedPerSecond= (totalHits) / (startGame)

    Change it to:

    speedPerSecond= (totalHits) / (wallclocktime-startGame)

    I fixed the formula but the time continues to increase as the keys are pressed.

  • Could you please share a simple example in CAPX?

  • Thank you!

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