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
  Loop back through loop based on user input, keeping previous changes loop made? hbkpancakes 2 136 Nov-21-2020, 02:35 AM
Last Post: hbkpancakes
  user input for multi-dimentional list without a prior iteration using input() Parshaw 6 353 Sep-22-2020, 04:46 PM
Last Post: Parshaw
  converting user input to float troubles RecklessTechGuy 3 397 Aug-17-2020, 12:41 PM
Last Post: deanhystad
  Validating user input WJSwan 2 360 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 454 Jun-24-2020, 02:10 PM
Last Post: pyzyx3qwerty
  if the input is not number, let user input again teatea 14 969 Jun-02-2020, 07:03 PM
Last Post: ibutun
  How to allow user input only if certain requirements are met vininhosts 3 460 May-28-2020, 06:15 PM
Last Post: micseydel
  Python - Most effective way to correct keyboard-user-input. ppel123 8 695 Apr-08-2020, 07:41 AM
Last Post: ppel123
  User input & Dictionary tfernandes 5 696 Apr-03-2020, 07:12 PM
Last Post: tfernandes
  User Input and CSV File Davy_Jones_XIV 2 902 Mar-24-2020, 08:43 AM
Last Post: Davy_Jones_XIV

Forum Jump:

User Panel Messages

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