简体   繁体   English

欧洲卡车模拟器中的直接输入不起作用

[英]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.我正在尝试在 Euro Truck Simulator 2 中创建自动驾驶卡车,使用 PIL 进行图像捕获,使用 OpenCV 进行图像处理,使用 tensorflow 进行动作预测。

The only problem is I am not able to send input to Euro Truck Simulator 2 game.唯一的问题是我无法向 Euro Truck Simulator 2 游戏发送输入。 I am using Windows 10, capturing in 1280x720 windowed mode.我正在使用 Windows 10,以 1280x720 窗口模式进行捕获。 Using Win32 Direct Input API as described below使用 Win32 直接输入 API,如下所述

Stackoverflow Answer implementation of Direct Input in Python Python中直接输入的Stackoverflow Answer实现

I am using PressKey function for W (0x11 Code) key and sleeping execution for 5 secs and then ReleaseKey to release the key.我正在使用 W(0x11 代码)键的 PressKey 功能和睡眠执行 5 秒,然后 ReleaseKey 释放键。

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.注意:我也尝试过使用 pyautogui。 Looping 50 times and pressing the key each time循环50次,每次按下按键

I know the solution to the problem.我知道问题的解决方案。 You can solve this problem with pydirectinput and pyautogui library.您可以使用 pydirectinput 和 pyautogui 库解决此问题。

You can visit to see more information about it您可以访问以查看有关它的更多信息

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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