600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > PYTHON游戏脚本无法正常运行常见问题解决方案

PYTHON游戏脚本无法正常运行常见问题解决方案

时间:2019-03-31 21:19:09

相关推荐

PYTHON游戏脚本无法正常运行常见问题解决方案

1.脚本用管理员运行。

2.使用PyDirectInput库。

安装

pip install pydirectinput

在python关于按键精灵得操作中常用的有PyAutoGUI,但在使用的过程中,针对一些游戏就直接失灵了,特别是一些以DirectX来开发的游戏或软件。我通过收索相关资料了解到之所以会这样,是因为PyAutoGUI使用的是Virtual Key Codes (VKs),也就是模拟按键码。而对于这些游戏或软件来说需要使用Directinput,这样就需要直接从设备中获取数据,而不是模拟的。而这个由github上Ben Johnson开发的PyDirectInput库就是针对此而设计的。

使用:

import pydirectinput

pydirectinput.moveTo(100, 150) # 移动鼠标至坐标100,150

pydirectinput.click() # 点击鼠标左键

pydirectinput.click(200, 220) # 移动鼠标至坐标200,220,并点击左键

pydirectinput.move(None, 10) # 鼠标移动相对y位置

pydirectinput.doubleClick() # 双击鼠标左键

pydirectinput.press('esc') # 按一下esc

pydirectinput.keyDown('shift')#按下shift

pydirectinput.keyUp('shift')#弹起shift

截至目前还未完成的功能:

1.鼠标滚轮操作

2.拖拽功能

3.热键功能

4.一些特殊shift搭配的按键比如字符(ie. '!', '@', '#'等)

5.鼠标速度设置,跟随,截图等功能

6.按键截图

# -*- coding: gbk -*-

from importlib.machinery import DEBUG_BYTECODE_SUFFIXES, BuiltinImporter

from pickle import TRUE

from turtle import Turtle

from typing import List

from unittest import TextTestRunner

import pyautogui

import time

import pydirectinput

#!/usr/bin/python

# -*- coding: UTF-8 -*-

pyautogui.PAUSE= 1

pyautogui.FAILSAFE =True

souche()

def souche():

while True:

coords = pyautogui.locateCenterOnScreen('G:/saoche/tupian1.png',confidence=0.8)

print(coords)

if coords is not None:

print("zhaodaole")

#x,y =pyautogui.center(coords)

x,y = coords

pydirectinput.moveTo(x,y)

#time.sleep(0.2)

# pydirectinput.click()

#time.sleep(0.2)

pydirectinput.press('enter')

pydirectinput.press('enter')

print('dianjile')

else:

print('meizhaodao')

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。