My script make a while True: begin with the F4 pressed, but I want it to stop when the F2 is pressed, how can I do it?
I’m trying this (using pyhook) but doesn’t work…
def onKeyboardEvent(event):
if event.KeyID == 115: #F4
while True:
selectAndCopy(468,722)
getClipboard()
time.sleep(2)
if event.KeyID == 113:
break
return True
You’re not changing
eventwithin your loop, so you wouldn’t expectevent.KeyIDto suddenly become 113 when it was 115 previously.What you might do is, on handling an F4 keypress, start a timer that does the selectAndCopy every two seconds. When you get another event with an F2 keystroke, kill the timer.
It could look something like this:
You would have to provide or find implementations of
startTimer()andstopTimer().