Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I send keys to a game I am playing,using python?

Tags:

python

key

I am playing deus ex human revolution,and there are things you can access with the correct 4 digit code.

I was wondering if you could make a script to brute force it sending keystrokes to the game. I have tried using send keys but i could not make it work.Any ideas?Thanks.

Python:

-SendKeys

This is what I have tried,which I found here:

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')

The way I am trying at first is open the game with the script,put a time delay to load the save game,and I open a terminal to hack it, but the key is not send.

-pywinauto:

Using pywinauto I have this:

from pywinauto import application
import time

app=application.Application()
app.connect_(title_re = "Deus Ex: Human Revolution - The Missing Link", class_name = "DeusExHRE")

Now I am searching which dialogs are available.

AutoHotKeys:

So except from python,I am trying with AutoHotKeys:

This works:

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

The keydelay is the minimum I found that didn't miss any buttons.I am looking for a way to make it faster,maybe by using a different send method.

Updated:

-pywinauto -autohotkeys

like image 332
IordanouGiannis Avatar asked Oct 18 '25 18:10

IordanouGiannis


2 Answers

Have you ever tried this ?

like image 125
Axel Isouard Avatar answered Oct 20 '25 07:10

Axel Isouard


You've probably already thought of this but just in case, make sure you try your solution(s) in a couple of places. IIRC, there's a couple of spots in Deus Ex where you have to discover the code in-game before you can use it, even though the code itself is hard-wired into the game.

What'd be really cool is if you got something to do the hacking mini-games automatically. :)

like image 22
ChrisC Avatar answered Oct 20 '25 06:10

ChrisC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!