I found this code on here somewhere and I would like to make it to stop printing until the key pressed is up again. I made it wait for a different key in order to print again but then if I had to type something like "Google" it would only print something for one "O" when I want it to print for both. I'm trying 2 days now to do it with no success. Any help would be appreciated instead of the classic 2-3 dislikes I'm getting in this site.
from random import *
from pyHook import HookManager
from win32gui import PumpMessages, PostQuitMessage
class Keystroke_Watcher(object):
def __init__(self):
self.hm = HookManager()
self.hm.KeyDown = self.on_keyboard_down
self.hm.HookKeyboard()
def on_keyboard_up(self, event):
return False
def on_keyboard_down(self, event):
space = False
try:
if event.KeyID == 32:
print('space')
space = True
x = randint(0, 1)
if space == False:
if x == 0:
print(x)
else:
print(x)
finally:
return True
def shutdown(self):
PostQuitMessage(0)
self.hm.UnhookKeyboard()
watcher = Keystroke_Watcher()