Python Forum
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Release kbhit
#3
Can use msvcrt.kbhit() with msvcrt.getch() then call should be done only when key is pressed.
Always run from command line(cmd) when doing stuff like this,or can get unwanted result.
import msvcrt
import time

def stop_me(timeout=15):
   '''None Blocking version'''
   start_time = time.time()
   while True:
       if msvcrt.kbhit():
           key = msvcrt.getch()
           if key == chr(27).encode():
               return 'Esc key pushed'
       if time.time() - start_time > timeout:
           return f'Did not manage to stop me in {timeout} sec'

if __name__ == '__main__':
    print(stop_me())
Reply


Messages In This Thread
Release kbhit - by Epilepsy - May-26-2018, 03:49 AM
RE: Release kbhit - by Larz60+ - May-26-2018, 07:43 AM
RE: Release kbhit - by snippsat - May-26-2018, 10:47 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to get mouse coordinates on click and release OhNoSegFaultAgain 1 3,011 May-17-2019, 06:56 PM
Last Post: buran
  Python 3.4: the only release to create .EXE standalone without .dll samsonite 7 5,842 Feb-28-2019, 09:20 AM
Last Post: samsonite
  How to release control of file jmair 2 2,803 Oct-03-2018, 08:22 PM
Last Post: jmair
  How to release Memory of GPU! majinbuu 1 2,632 May-11-2018, 05:06 AM
Last Post: j.crater
  3.6.2 is latest stable release right? And "path length" Fran_3 3 3,349 Aug-01-2017, 02:04 PM
Last Post: Fran_3
  How to I make my program release memory? Plecto 11 10,729 Dec-18-2016, 10:03 PM
Last Post: wavic

Forum Jump:

User Panel Messages

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