0

Is it possible to create an AFK bot that only sends input to one window? The idea is that this would allow you to use your PC normally, but your game character would move around with, for example, presses of the "w, a ,s ,d" keys.

I've tried a lot of different things, and ended up coding the following script in Python:

import pyautogui
import time

window_name = "Rechner"

delay = 5

message = "1"


pyautogui.hotkey('winleft', '1')
time.sleep(delay)

# Type the message
pyautogui.typewrite(message, interval=1)

pyautogui.press('enter')

but it didn't work.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Knax Tom
  • 1
  • 1
  • What you have will send a key exactly once and then end. Don't you think you will need some kind of loop? – Tim Roberts Jan 08 '23 at 00:55
  • What "didn't work?" what happens? Tim made a great point. in any case, maybe [this](https://stackoverflow.com/questions/21917965/send-keys-to-a-inactive-window-in-python). also see [this](https://stackoverflow.com/a/1230643/4935162) – Yarin_007 Jan 08 '23 at 00:59

1 Answers1

0

You can do the following:

from pynput.keyboard import Key, Controller
import time
keyboard = Controller()

time.sleep(1)
keyboard.press('w')

If you want it to press something like the enter key, then you would type in:

keyboard.press(key.enter)

I hope this helps.

Edit: Oops I just realized that you were trying to figure out how to do it with Pyautogui, and I answered for Pynput.

Waluigi6
  • 1
  • 3
  • The language and the method does not really matter, the main thing is that it works. Thank you very much for youre awnser – Knax Tom Jan 08 '23 at 20:38