0

OS: Windows 11
Python Version: 3.9

I was playing around with pyautogui module with the below code.

import pyautogui
from time import time

start = time()
print(start)

while True:
    current = time()
    if current - start >= 5:
        break
    pyautogui.press('right')
print(current)

Description of the above code:
Press the right arrow key for 5 seconds without any delay.

Observation
It presses right arrow key for 5 seconds and exits.
But even after it exits, right arrow key is being pressed for quite some time. So my guess is, windows is not fast enough to process the right arrow key press at which speed python is running the command. Hence it's keeping the key presses in a queue/ buffer and processes them until the buffer is cleared, even after the program is exited a while back.

Is there a way to see, from python, whether that windows key input buffer is empty or not?

RatDon
  • 3,403
  • 8
  • 43
  • 85
  • it may press it hundreds times because loop can be repeated hundreds times in 5 seconds - maybe you should sleep inside loop to send less `press('right')` – furas Sep 13 '22 at 12:55
  • @furas Through the question I'm not looking for correcting my code. It was not meant for any production code. It was meant for exploring and understanding the module. While doing that, i stumbled upon something which tickled my curiosity. – RatDon Sep 21 '22 at 16:35

0 Answers0