[英]How can I send keys to a game I am playing,using python?
我正在玩人類革命的deus,你可以使用正確的4位數代碼訪問。
我想知道你是否可以制作一個劇本來強制它向游戲發送擊鍵。 我嘗試使用發送密鑰,但我無法使其工作。任何想法?謝謝。
-SendKeys
這是我試過的,我在這里找到:
import win32com.client
import time
import SendKeys
import os
from ctypes import *
shell = win32com.client.Dispatch("WScript.Shell")
os.startfile('C:\\....exe')
time.sleep( 150 )
shell.SendKeys('1')
我最初嘗試的方式是用腳本打開游戲,加載保存游戲的時間延遲,我打開一個終端來破解它,但密鑰不發送。
-pywinauto:
使用pywinauto我有這個:
from pywinauto import application
import time
app=application.Application()
app.connect_(title_re = "Deus Ex: Human Revolution - The Missing Link", class_name = "DeusExHRE")
現在我正在搜索哪些對話框可用。
所以除了python,我正在嘗試使用AutoHotKeys:
這有效:
SetKeyDelay 180
F12::
Send {0 down}
Send {0 up}
Send {0 down}
Send {0 up}
Send {0 down}
Send {0 up}
Send {0 down}
Send {0 up}
Send {Backspace down}
Send {Backspace up}
Return
keydelay是我發現的最小,沒有錯過任何按鈕。我正在尋找一種方法,使其更快,可能通過使用不同的發送方法。
更新:
-pywinauto -autohotkeys
你試過這個嗎?
你可能已經想過這個,但為了以防萬一,請確保你在幾個地方嘗試你的解決方案。 IIRC,在Deus Ex中有幾個地方你必須在使用之前發現游戲中的代碼,即使代碼本身已經硬連接到游戲中。
真的很酷,如果你有自動做黑客迷你游戲的東西。 :)
有些年頭晚了,但無論如何回答,因為其他人可能會像我一樣面臨同樣的問題......
在Windows中,您可以使用win32api將密鑰發送到活動應用程序,但您必須為其提供掃描代碼,以使其適用於某些類型的應用程序,如游戲
要發送單個密鑰,您必須擁有它的虛擬密鑰代碼 ,您可以通過使用解決方案在此處或通過使用字典(您可以在Google中輕松找到或自己制作)獲得該密鑰代碼
import win32api, time
# in this example i'm using a dictionary (that i called VK_CODE)
# to map the keys to their respective virtual key codes
# Sending the key a
i = 'a'
# send key down event
win32api.keybd_event(VK_CODE[i], win32api.MapVirtualKey(VK_CODE[i], 0), 0, 0)
# wait for it to get registered.
# You might need to increase this time for some applications
time.sleep(.05)
# send key up event
win32api.keybd_event(VK_CODE[i], win32api.MapVirtualKey(VK_CODE[i], 0), win32con.KEYEVENTF_KEYUP, 0)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.