Search code examples
pythonpyautogui

How do i enter an arbitrary number into a field using pyautogui?


Im trying to make pyautogui type in the variable, which is a number that keeps changing.

I tried Typewrite() and keyDown().

This is the code:

pyautogui.keyDown("enter")
pyautogui.keyDown(count)
count += scale

I hoped that it would put in the variable and click enter. The enter part works btw. It didn't paste the variable as i hoped.


Solution

  • Try this:

    pyautogui.keyDown("enter")
    pyautogui.keyDown(str(count))
    count += scale'
    

    If count is an integer, you first need to convert it to a string str().

    If you need to enter a number above 9, you will need to do this:

    for c in str(count):
        pyautogui.keyDown(c)
    

    Because there's no "10" or above key on your keyboard. "1" and "0" will need to be pressed individually.