Guglielmo La Mastra
Guglielmo La Mastra

Reputation: 1

Simulate Keyboard Event, without using the keyboard

Short: Is it possible to write a program that presses a key as if it was input from the keyboard? If yes: how?

Long: I want to make bots for games, which is not permitted. I know how to write programs to type keystrokes but the problem is that there seems to be a difference between keystrokes entered via software and actual keystrokes from the keybord. Obviously games block those kind of "automatic" inputs and accept only real ones. Is it possible to bypass them? if yes how?

I tried python win32api, AutoHotKey(Ahk) send and controlsend. Everything worked outside the game, nothing on it.

Upvotes: 0

Views: 130

Answers (1)

Leo Aqua
Leo Aqua

Reputation: 26

I think most games check how long the key is pressed, So this: [key down] -> ~0ms -> [key up] means that the game thinks you're automating the keyboard (or it doesn't recognize the keypress). Add this function to your script:

import pyautogui
import time
import random

def delayed_key(key):
    pyautogui.keyDown(key)
    time.sleep(random.uniform(0.05, 0.1)) # adjust these values to your liking
    pyautogui.keyUp(key)

It randomizes the time a key is held down to simulate human input. Hope it helps.

-Leo

Upvotes: 0

Related Questions