Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to time a user's input
#1
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!
Reply
#2
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

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

There are other packages, see: https://pypi.org/search/?q=keyboard
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Unable to access the user input value given to daterangepicker klllmmm 1 360 May-26-2021, 09:16 PM
Last Post: nilamo
  Problem restricting user input in my rock paper scissors game ashergreen 6 688 Mar-25-2021, 03:54 AM
Last Post: deanhystad
  LinkedList by User Input SantiagoPB 5 810 Mar-03-2021, 09:54 PM
Last Post: deanhystad
  User input/picking from a list AnunnakiKungFu 2 431 Feb-27-2021, 12:10 AM
Last Post: BashBedlam
  Generate Random operator, take user input and validate the user mapypy 4 467 Feb-03-2021, 08:41 PM
Last Post: nilamo
  Loop back through loop based on user input, keeping previous changes loop made? hbkpancakes 2 711 Nov-21-2020, 02:35 AM
Last Post: hbkpancakes
  user input for multi-dimentional list without a prior iteration using input() Parshaw 6 755 Sep-22-2020, 04:46 PM
Last Post: Parshaw
  converting user input to float troubles RecklessTechGuy 3 742 Aug-17-2020, 12:41 PM
Last Post: deanhystad
  Validating user input WJSwan 2 690 Jul-06-2020, 07:21 AM
Last Post: menator01
  Hi, I need help with defining user's input and applying it to code. jlmorenoc 2 702 Jun-24-2020, 02:10 PM
Last Post: pyzyx3qwerty

Forum Jump:

User Panel Messages

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