简体   繁体   中英

Direct Input in Euro Truck Simulator not working

I'm trying to create autonomous truck in Euro Truck Simulator 2, using PIL for image capture, OpenCV for image processing and tensorflow for action prediction.

The only problem is I am not able to send input to Euro Truck Simulator 2 game. I am using Windows 10, capturing in 1280x720 windowed mode. Using Win32 Direct Input API as described below

Stackoverflow Answer implementation of Direct Input in Python

I am using PressKey function for W (0x11 Code) key and sleeping execution for 5 secs and then ReleaseKey to release the key.

The truck just won't move, the window is in focus while the script is running and also I can manually drive the truck as usual

PressKey(0x11)
time.sleep(5)
ReleaseKey(0x11)
time.sleep(1)

Note: I have also tried using pyautogui. Looping 50 times and pressing the key each time

I know the solution to the problem. You can solve this problem with pydirectinput and pyautogui library.

You can visit to see more information about it

import pyautogui
import pydirectinput
pydirectinput.keyDown('w')
time.sleep(5)
pydirectinput.keyUp('w')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM