使用 DirectX 检查前面 window 是否为游戏\
Checking if the front window is a Game\ using DirectX
我正在开发一款应用程序,该应用程序充当控制器,通过插座连接到您的 PC,并允许用户使用该应用程序玩 PC 游戏。我需要在服务器端检查前面的应用运行是否是游戏。如果是,那么应用程序将像普通的 XBOX\PS 遥控器一样工作,否则,遥控器将不会执行任何操作。
如何查看PC前端window是否安装了游戏,并且该游戏使用的是DirectX?由于我 "faking the keypress" 的方式,该应用程序基本上只能与 DirectX 游戏一起使用。我知道它不会与其他游戏兼容,但它很好。
您可以使用答案 here to get the 'active' window, eg. the one that would receive input. You can then use to obtain the process id from that window. Finally, list the DLLs that the process has loaded, using this 答案,并从 DirectX DLL 中搜索(很可能,d3d11.dll 或 d3d12.dll 是您想要搜索的 - 但它取决于游戏)。
请注意,仅仅因为一个应用程序加载了 D3D,并不一定意味着它是一个游戏。但是,这也不意味着您的应用程序无论如何都没有用。
所以,感谢 MuertoExcobito,我成功地完成了检查,我想在他的回答中补充一点,如果你想获得任务管理器中写入的正确 PID。
那行得通:
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
我正在开发一款应用程序,该应用程序充当控制器,通过插座连接到您的 PC,并允许用户使用该应用程序玩 PC 游戏。我需要在服务器端检查前面的应用运行是否是游戏。如果是,那么应用程序将像普通的 XBOX\PS 遥控器一样工作,否则,遥控器将不会执行任何操作。
如何查看PC前端window是否安装了游戏,并且该游戏使用的是DirectX?由于我 "faking the keypress" 的方式,该应用程序基本上只能与 DirectX 游戏一起使用。我知道它不会与其他游戏兼容,但它很好。
您可以使用答案 here to get the 'active' window, eg. the one that would receive input. You can then use
请注意,仅仅因为一个应用程序加载了 D3D,并不一定意味着它是一个游戏。但是,这也不意味着您的应用程序无论如何都没有用。
所以,感谢 MuertoExcobito,我成功地完成了检查,我想在他的回答中补充一点,如果你想获得任务管理器中写入的正确 PID。
那行得通:
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