0

I'm working on an app that acts as a controller that connect to your PC through sockets, and allows the user to play the PC game with the app. I need to check on the server side if the app running in front is a game. If it is then app will work like a regular XBOX\PS remote, otherwise, the remote won't do anything.

How do I check if the front window of the PC is an installed game and that this game is using DirectX? Basically the app will work only with DirectX games because of the way I'm "faking the keypress". I know that it won't be compatible with other games but its fine.

MuertoExcobito
  • 9,741
  • 2
  • 37
  • 78
Ido
  • 55
  • 7
  • help? please im in strugglel. if u have some other suggestions on how to make python play direct X games it will be helpful. its like creating a Bot but i need to send the server the keys and the server will do the actions. – Ido Jan 14 '18 at 15:13

2 Answers2

1

You can use the answer here to get the 'active' window, eg. the one that would receive input. You can then use GetWindowThreadProcessId to obtain the process id from that window. Finally, list the DLLs that the process has loaded, using this answer, and search from the DirectX DLLs (likely, d3d11.dll or d3d12.dll are the ones you'd want to search for - but it depends on the game).

Note that, just because an application has D3D loaded, doesn't necessarily mean it's a game. However, it also doesn't mean that your application wouldn't be useful for whatever it is.

MuertoExcobito
  • 9,741
  • 2
  • 37
  • 78
  • thanks ! ill try to make that. will be updating if i solved it in several days. – Ido Jan 17 '18 at 15:19
  • i tried to make it work however the list of dlls doesnt return me anything. i tried printing the list only and i got that : '7316' is not recognized as an internal or external command, operable program or batch file. – Ido Jan 17 '18 at 15:45
  • tried with the word listdlls inside the os.system.. still not recognized – Ido Jan 17 '18 at 15:55
  • after some hours of checking i figured out that the problem is actually this: ctypes.windll.user32.GetWindowThreadProcessId(hwnd, ctypes.byref(pid)) this line aint seem to give back the correct Pid like os.getpid() does but i still cant find the foregroung window PID correctly... – Ido Jan 24 '18 at 19:25
0

So, thanks to MuertoExcobito i succeed doing my check and i would like to add to his answer that if you want to get the correct PID as written in the task manager. that would work :

hwnd = ctypes.windll.user32.GetForegroundWindow()
lpdw_process_id = ctypes.c_ulong()
result = ctypes.windll.user32.GetWindowThreadProcessId(hwnd, ctypes.byref(lpdw_process_id))
process_id = lpdw_process_id.value
print process_id
Ido
  • 55
  • 7