0

I am beginner level in programming(less than a year of experience). I am trying to use https://github.com/Sentdex/pygta5/blob/master/directkeys.py to imitate keyboard inputs in one of RPGs. I successfully managed to implement simple movements(WASD) but when I try to use game specific command as example "choose a closest enemy(Using TAB)" game doesn't react to the input. By doing some research I realized that the game most likely have internal driver level keyboard interaction which cannot be activated using Direct Inputs. I am asking for possible ways to solve the issue.

I tried to use virtual keys to try to imitate the keyboard inputs. Also, I tried to reassign one of the movement keys to "chose closest enemy button" but it produces no inputs as well. I am might start extensive research towards even lower-level keyboard interactions and see what I can do from there.

Here is small code sample

from directkeys import KeyPress, PressKey, ReleaseKey, W, ESC, C, TAB
import time
import win32gui

# open a window
handle = win32gui.FindWindow(0, "Game window")
win32gui.SetForegroundWindow(handle)

# Press and Release key
PressKey(W) 
time.sleep(3)
ReleaseKey(W)

print("Script finished")
4
  • There is low level keyboard hooks but it seems what you're trying to achieve is very easily doable by calling GetAsyncKeyState from the Windows API stackoverflow.com/questions/5592500/… Commented Aug 17, 2019 at 23:30
  • @Nina Thank you for your response, but I am trying to make the game register the key press and not just verify that it was pressed. Also, I tried GetAsyncKeyState and it returns 1 but nothing happens inside the game. Both Virtual Keys and Direct keys work for movement commands but does not work for game specific commands. Commented Aug 18, 2019 at 11:15
  • I'm not sure I understand what you mean. As in you're trying to send a key or simulate a key stroke in the game itself? If that's the case, you can use the SendInput windows API. Or the keybd_event but Microsoft recommends SendInput. There are plenty of tutorials on how to use SendInput with Python. Commented Aug 18, 2019 at 16:34
  • has solve? i need to driver level keyboard Commented Oct 9, 2019 at 15:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.