[英]How to switch focus between multiple pygame apps?
There are two games (A and B), on the left and right screen sides. 屏幕左右两侧有两个游戏(A和B)。 The game A responds to mouse clicks, the game B — to left/right keydowns.
游戏A响应鼠标单击,游戏B响应左/右键按下。 There is also a server which handles games behaviour:
还有一个处理游戏行为的服务器:
I run games as two separate subprocesses (using subprocess.Popen I start a.py
and b.py
). 我将游戏作为两个单独的子
a.py
运行(使用a.py
我启动a.py
和b.py
)。 Where a.py
and b.py
are simple pygame games that listen my server events inside their game loop. 其中
a.py
和b.py
是简单的pygame游戏,它们在游戏循环内监听我的服务器事件。
Is it possible to share event loop between two different pygame windowed apps? 是否可以在两个不同的pygame窗口化应用之间共享事件循环? Or may be it's better to change focus in some OS-specific way?
还是以某些特定于操作系统的方式更改焦点更好?
Okay, I have got a solution which works like a charm. 好的,我有一个像魅力一样的解决方案。
Since we have a server for handling some game events, we decided to grab a focus inside one game and share all keyboard events to other games through the server using web sockets. 由于我们有一台用于处理某些游戏事件的服务器,因此我们决定将重点放在一个游戏中,并使用Web套接字通过服务器将所有键盘事件共享给其他游戏。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.