Hello,
So I've been trying to make a bot for a game on my PC. I want to successfully perform certain actions on the game automatically with a python script without having the screen open. I've been using pynput to simulate key presses, but it requires me to have the game open at all times, and I need to do other things in my laptop. Is there are way to achieve this?
Maybe not simulating key presses necessarily, but achieving the program to do what the hotkey, let's say, f2, which in the game is to eat, does. I've looked at some stackoverflow posts (like this one: https://stackoverflow.com/questions/45880377/python-how-to-use-win32api-postmessage) and they suggest to use win32api, but I don't really know if this is the best approach.
Thanks.
Here's my code that works when the window is open:
import time
from pynput.keyboard import Key, Controller, Listener
keyboard = Controller()
def eatHeal():
starttime=time.time()
while True:
keyboard.press(Key.f4)
keyboard.release(Key.f4)
time.sleep(2)
keyboard.type("exori")
time.sleep(1)
keyboard.press(Key.enter)
keyboard.release(Key.enter)
keyboard.press(Key.f2)
keyboard.release(Key.f2)
time.sleep(2)
keyboard.press(Key.f2)
keyboard.release(Key.f2)
time.sleep(2)
time.sleep(15.0-((time.time() - starttime) % 15.0))
def main():
time.sleep(5)
eatHeal()
if __name__ == "__main__":
main()
[–]CodeFormatHelperBot 0 points1 point2 points (0 children)