开发者

print a string in an external application (python 3.1)

开发者 https://www.devze.com 2023-01-19 18:03 出处:网络
Suppose I have a game and a python script running. In this game, to speak you just type whatever you want and hit enter. This python script has a button on it that I want to output a predefined string

Suppose I have a game and a python script running. In this game, to speak you just type whatever you want and hit enter. This python script has a button on it that I want to output a predefined string into the game, and hit enter automatically (essentially, the button causes the character to speak the string). What would be the easiest way to implement this?

(just t开发者_Python百科he actual 'send string to game and hit enter' thing, not the buttons and stuff)


Assuming your game is not running in the console (in that case you could use stdin), sendkeys might be an option on Windows. It allows you to send keystrokes to a certain window - in this case, the game window.

If the game is scriptable, you should of course use the game's own scripting options if available.


It depends on what hooks the game provides. If it doesn't provide any hooks, you may want to look into whatever your windowing system uses for automation. I've only done this sort of thing in Linux where I could use X's XTest extension (xte).

0

精彩评论

暂无评论...
验证码 换一张
取 消