caveskelton
caveskelton

Reputation: 143

Simulating Keypresses using pydirectinput too slow

So I want to simulate keypresses in my testgame in less than 0.05 intervals. I used pyautogui which adds auto-pause of 0.1s between key-press which can be disabled by pyautogui.pause = 0.03 which works but you cannot use pyautogui in games and only pydirectinput works(because games use scancodes and not VK is what someone told me)

pydirectinput documentation says they have the pause function but it does not works as pydirectinput.pause= 0.03 is still greater than 0.1 is this some coding problem in their module? how can I fix it any other module there or I myself can go do the low-level key press using pywin32 or something if it is not too hard?

Upvotes: 1

Views: 4458

Answers (2)

It was just a problem of capitalization.

You want to use pydirectinput.PAUSE=0.03.

The PyDirectInput docs could use some love.

Like DanishDeveloper said if you browse the __init__.py file for the package you can see some definitions, for version 1.0.4 it's set as PAUSE=0.1.

import pydirectinput

def pressFast(key, N=500):
  pydirectinput.PAUSE=0.01
  for x in range(N):
    pydirectinput.press(key)

Upvotes: 1

DanishDeveloper
DanishDeveloper

Reputation: 11

The only thing that worked for me was going into pythons library folder and finding the _ _ init _ _ .py and in that, there is a line at the top defining the pause, you can change it there, and that changes the speed of the functions tho i dont know why the developer didnt add a simple pause function implemented.

Upvotes: 0

Related Questions