正确获取要在XNA中聊天的按键 [英] Correctly getting key being pressed for chat in XNA

查看:90
本文介绍了正确获取要在XNA中聊天的按键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我要直接讲,我正在尝试在自己制作的XNA游戏中创建一个聊天系统.我可以很容易地弄清正在按下哪些键,但我无法知道实际键入了什么.在我看来,他们好像在说:OemShifthello billOemPeriod OemShifthow are youOemQuestion应该看起来像Hello bill. How are you?(或者类似的东西).

So, I'm going to cut straight to it, I'm trying to make a chat system in an XNA game I'm making. I can easily figure out what keys are being pressed BUT I have no way of knowing what is actually being typed. To me, it looks like they are saying: OemShifthello billOemPeriod OemShifthow are youOemQuestion which should look like Hello bill. How are you? (or something along those lines).

处理所有这些问题的最佳方法是什么?

Whats the best way to handle all of this?

推荐答案

对于PC而言,XNA框架没有内置任何功能,可以轻松实现这一点(对于WP7和Xbox,这是另一回事).

For the PC there's nothing built in to the XNA framework making that easy (it's a different story for WP7 and the Xbox).

此处的这篇文章很好地总结了您的所有选择.

This post here summarizes pretty much all of your options fairly well.

http ://dream-forever.net/Blog/2011/08/29/getting-true-keyboard-input-into-your-xna-games/

基本上

  1. 用字符到KeyPress的映射建立一个大词典
  2. 了解XNA游戏形式的KeyDown,KeyUp,KeyPress事件
  3. 使用IMessageFilter接口
  4. 使用SetWindowsHookEx捕获关键事件

每种方法都有其优缺点,文章的作者提供了可以下载的示例.

Each of those methods have their pros and cons and the author of the post provided a sample you can download.

在做一些研究时,我还遇到了Nuclex的一个图书馆.他们通常会创建相当强大的解决方案,因此绝对值得一试.

In doing some research I also came across a library from the guys at Nuclex. They typically create fairly robust solutions so it would definitely be worth checking that out as well.

http://www.nuclex.org/blog/Notices/105-new-component-nuclex-input

要记住的重要一点是,您在PC上,实际上任何库都可以在其中运行(有一些修改/调整).因此,不要只看XNA相关样本.也可以选择DirectInput,SlimDX,SharpDX等样本,它们可能需要花费一些额外的工作才能放入您的项目.

The important thing to remember is that you're on the PC and that really ANY library will work that is out there (with some modificaton/tweakings). So don't limit yourself to looking at just XNA related samples. Samples for DirectInput, SlimDX, SharpDX etc would also be options, they may just take a little extra work to drop into your project.

这篇关于正确获取要在XNA中聊天的按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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