SDL TextInput(使用新的1.3结构)
好吧,我一直在研究 SDL 中的文本输入(如何将击键数据转换为字母并将它们附加到名为 Text 的 std::string 中),并且大多数教程都以这种方式进行了介绍:
//If a key was pressed
if(event->type == SDL_KEYDOWN )
{
//If the key is a lowercase letter
else if( (event->key.keysym.unicode >= (Uint16)'a' ) && (event->key.keysym.unicode <= (Uint16)'z' ) )
{
//Append the character
Text += (char)event->key.keysym.unicode;
}
}
但是经过一些搜索,我发现了一个请在 SDL 标头中注明 .unicode 已弃用并使用 SDL_TextInputEvent/SDL_TextEditingEvent。 SDL 文档 wiki 中有一些关于它的参考,但是我找不到任何有关如何使用它的示例。例如,如何使用新结构编写上面的代码片段?
Okay, I have been studying text input in SDL (how to turn the keystrokes data into letters and append them to a std::string called Text) and most of the tutorials have covered it this way:
//If a key was pressed
if(event->type == SDL_KEYDOWN )
{
//If the key is a lowercase letter
else if( (event->key.keysym.unicode >= (Uint16)'a' ) && (event->key.keysym.unicode <= (Uint16)'z' ) )
{
//Append the character
Text += (char)event->key.keysym.unicode;
}
}
However after some searching, I found a note in the SDL headers saying .unicode is deprecated and to use SDL_TextInputEvent/SDL_TextEditingEvent. There is some reference to it in the SDL documentation wiki, however I couldn't find any example on how to use it. For instance, how would I write the above snippet using the new structure?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试本教程。
You might give this tutorial a try.