Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to time a user's input
Hello again!

For a text-based game I am making, combat is an essential part. I have chosen to make a timed system, where the quicker you press a certain key the more damage you do. Obviously you can use the input command, however there is no way you can time that, as the user stops moving through the code until a key is pressed. If anyone knows a way to do this, I would greatly appreciate it. Thanks!
imho, the main problem with input is that you need to pres Enter. so basically you need to explore the ways to read key pressed. this will depend on the OS.
otherwise the solution is simple - get before and after time and calculate the difference
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

as buran explained you need to control hotkeys on the keyboard.
Take a look at this package:
github code location:
specifically this part:
Quote:Complex hotkey support (e.g. ctrl+shift+m, ctrl+space) with controllable timeout.

There are other packages, see:

Possibly Related Threads…
Thread Author Replies Views Last Post
  Matplotlib - close multple plots with user input Positron79 0 71 Dec-01-2021, 05:26 PM
Last Post: Positron79
  Exit function from nested function based on user input Turtle 5 537 Oct-10-2021, 12:55 AM
Last Post: Turtle
  Unable to access the user input value given to daterangepicker klllmmm 1 825 May-26-2021, 09:16 PM
Last Post: nilamo
  Problem restricting user input in my rock paper scissors game ashergreen 6 1,445 Mar-25-2021, 03:54 AM
Last Post: deanhystad
  LinkedList by User Input SantiagoPB 5 1,505 Mar-03-2021, 09:54 PM
Last Post: deanhystad
  User input/picking from a list AnunnakiKungFu 2 901 Feb-27-2021, 12:10 AM
Last Post: BashBedlam
  Generate Random operator, take user input and validate the user mapypy 4 1,342 Feb-03-2021, 08:41 PM
Last Post: nilamo
  Loop back through loop based on user input, keeping previous changes loop made? hbkpancakes 2 1,355 Nov-21-2020, 02:35 AM
Last Post: hbkpancakes
  user input for multi-dimentional list without a prior iteration using input() Parshaw 6 1,164 Sep-22-2020, 04:46 PM
Last Post: Parshaw
  converting user input to float troubles RecklessTechGuy 3 1,044 Aug-17-2020, 12:41 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020