Python Forum
How to time a user's input - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to time a user's input (/thread-29397.html)



How to time a user's input - Tbot1000 - Aug-31-2020

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!


RE: How to time a user's input - buran - Aug-31-2020

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


RE: How to time a user's input - Larz60+ - Aug-31-2020

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