Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8150939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:12:43+00:00 2026-06-06T15:12:43+00:00

I’m making a reflex game. Here’s the output – __________________________________________________________________________ Reflex game initiated. Press

  • 0

I’m making a reflex game. Here’s the output –

__________________________________________________________________________
Reflex game initiated. Press ENTER to begin the game, and then press ENTER 
after the asterisks are printed to measure your reflexes!.


*************************

Your result: 0.285606 seconds.
logout

[Process completed]
__________________________________________________________________________

There’s one small problem though – There’s 0-10 seconds (based on a random variable) after you press enter to start the game and before the stars are printed. During that time, if the player presses ENTER, it’s logged as their reflex time. So I need a way to stop my code from reading their ENTER button before the stars are printed. The code –

#!/usr/bin/perl

use Time::HiRes qw(sleep);
use Time::HiRes qw(gettimeofday);

#random delay variable
$random_number = rand();

print "Reflex game initiated. Press ENTER to begin the game, and then press ENTER after         the asterisks are printed to measure your reflexes!.\n";

#begin button
$begin = <>;

#waits x milliseconds
sleep(10*$random_number);

#pre-game
$start = [ Time::HiRes::gettimeofday() ];

print "\n****************************\n";

#user presses enter
$stop = <>;

#post game
$elapsed = Time::HiRes::tv_interval($start);

#delay time print
print "Your result: ".$elapsed." seconds.\n";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T15:12:45+00:00Added an answer on June 6, 2026 at 3:12 pm

    Repeating from the original answer by CanSpice:

    Looks like Term::ReadKey may help.

    #!perl
    
    use strict;
    use warnings;
    use 5.010;
    
    use Term::ReadKey;
    
    say "I'm starting to sleep...";
    ReadMode 2;
    sleep(10);
    ReadMode 3;
    my $key;
    while( defined( $key = ReadKey(-1) ) ) {}
    ReadMode 0;
    say "Enter something:";
    chomp( my $input = <STDIN> );
    say "You entered '$input'";
    

    Here’s what happens:

    • ReadMode 2 means “put the input mode into regular mode but turn off echo”. This means that any keyboard banging that the user does while you’re in your computationally-expensive code won’t get echoed to the screen. It still gets entered into STDIN‘s buffer though, so…
    • ReadMode 3 turns STDIN into cbreak mode, meaning STDIN kind of gets flushed after every keypress. That’s why…
    • while(defined($key = ReadKey(-1))) {} happens. This is flushing out the characters that the user entered during the computationally-expensive code. Then…
    • ReadMode 0 resets STDIN, and you can read from STDIN as if the user hadn’t banged on the keyboard.

    When I run this code and bang on the keyboard during the sleep(10), then enter some other text after the prompt, it only prints out the text I typed after the prompt appeared.

    Strictly speaking the ReadMode 2 isn’t needed, but I put it there so the screen doesn’t get cluttered up with text when the user bangs on the keyboard.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.