是否可以使用 select(2) 来监视 SDL 文本输入事件? [英] Is it possible to use select(2) to watch for SDL text input events?

查看:59
本文介绍了是否可以使用 select(2) 来监视 SDL 文本输入事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们必须使用事件驱动编程来编写服务器和客户端 - 我们使用 select(2) 从标准输入和套接字读取.我正在使用 SDL2 和 SDL2_TTF 库为客户端制作接口.问题是我不知道如何让 select(2) 为 SDL 文本输入事件工作,所以我无法将客户端连接到我的界面.我该怎么做?是否有文件描述符可用于在 SDL 窗口上查看我的输入?

We have to program a server and a client using event-driven programming - we use select(2) to read from stdin and sockets. I'm making an interface for the client using the SDL2 and SDL2_TTF libraries. The problem is I don't know how to make select(2) work for SDL text input events, so I cannot connect the client to my interface. How should I do that? Is there a file descriptor I can use to watch my input on the SDL window?

我忘了提:我们必须使用select(2)

推荐答案

是否有文件描述符可用于在 SDL 窗口中查看我的输入?

Is there a file descriptor I can use to watch my input on the SDL window?

没有.您能做的最好的事情是通过 SDL_GetWindowWMInfo() &SDL_SysWMinfo 结构.

Nope. Best you can do is get some platform-specific window handles via SDL_GetWindowWMInfo() & the SDL_SysWMinfo struct.

您或许可以在 x11.display 上使用 ConnectionNumber()select(2) ,但这确实是特定于 X11 的.

You might be able to use ConnectionNumber() on x11.display and select(2) on it but that's really X11-specific.

我该怎么做?

让主/GUI/SDL 线程通过本地套接字上的 write(2) 将消息发送到您的网络线程,网络线程也select(2)上.对于网络线程到主线程的通信,您可以使用 SDL_PushEvent() 和唤醒SDL_WaitEvent()的自定义事件.

Have the main/GUI/SDL thread send messages to your networking thread via write(2) on a local socket which the networking thread also select(2)s on. For network thread to main thread communication you can use SDL_PushEvent() with a custom event to wake up SDL_WaitEvent().

这篇关于是否可以使用 select(2) 来监视 SDL 文本输入事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆