操作系统和实现独立访问键盘?
我用MSVC++制作了一个FPS游戏,它在Windows上运行得很好。 但现在我试图让它变得可移植(至少我想创建一个linux和一个Windows版本),所以我决定将IDE更改为Code::Blocks,将框架更改为wxWidgets。 但不同系统上的虚拟键码和扫描码似乎不同。
早些时候,我经历过,即使在同一操作系统但不同的计算机上,虚拟键码也可能不同(我收到关于他们无法控制角色的错误报告(取决于数字锁定状态,哈哈,不是笑话),当更改使用扫描码而不是 virtkey 代码的代码) (编辑:使用wxWidgets,数字键盘上的virtkey和扫描代码根据数字锁定状态具有不同的值,砰!)
现在使用wxWidgets,看起来wxKeyEvent::GetRawKeyCode和之前从WM_KEYDOWN的lParam获得的代码是不同的。 我还在 Linux (ubuntu) 上从 GetRawKeyCode 获得了完全不同的扫描代码。
好吧,我可以通过按下所有键并查看它给出的代码来制作自己的扫描代码表,但 ubuntu 在我的笔记本电脑上运行的唯一问题是,笔记本电脑没有全键盘...... 但我需要所有这些才能使控制设置发挥作用。
所以问题是:是否有一种标准的跨平台方法可以为相同的密钥(更准确地说是相同位置的密钥)获取相同的代码? (至少在 Windows 和 Linux 上)
I made an FPS game with MSVC++ which is running very well on Windows. But now I am trying to make it portable (at least I want to create a linux and a Windows version), so I decided to change the IDE to Code::Blocks and the framework to wxWidgets. But it seems the virtual key codes and scan codes are different on different systems.
Earlier I experienced that the virtual keycodes may be different even on the same operating system but different computer (I got bug reports about they unable to control the character (depending on the numlock state, lol, not joke), which is fixed when change the code to use scancodes instead of virtkey codes)
(edit: with wxWidgets both virtkey and scan codes on the numpad has different values depending on numlock state, bang!)
Now with wxWidgets it seems the wxKeyEvent::GetRawKeyCode and the code obtained earlier from WM_KEYDOWN's lParam are different. And I also get a completely different scan code on linux (ubuntu) from GetRawKeyCode.
Well I can make my own scan code table by pressing all the keys and seeing what code it gives, but the only problem that ubuntu runs on my laptop, and the laptop does not have a full keyboard...
But I need all of them to make Control Settings work.
So the question: Is there a standard and cross-platform way to get the same code for the same key (the key at the same position to be more precise)? (at least on windows and linux)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您还没有考虑过,您也许可以使用 SDL。
In case you haven't considered it already, you might be able to use SDL.
这是一个 FPS,您使用的较低级图形工具包会产生巨大的差异(我假设您没有在 wxWidgets 中编写 3D 图形)。 如果您使用 OpenGL,您是否查看过GLUT 可以做什么?
glutKeyboardFunc 和 glutSpecialFunc 与 glutGetModifiers 对于跨平台键盘代码来说就足够了,GLUT 甚至可以用于其他输入设备。
但说实话,我仍然不明白这与 wxWidgets 有什么关系。
This being an FPS, the lower-level graphics toolkit you are using makes a huge difference (I'm assuming that you're not writing 3d graphics in wxWidgets). If you're using OpenGL, have you looked at what GLUT can do?
The glutKeyboardFunc and glutSpecialFunc combined with glutGetModifiers could be sufficient for cross-platform keyboard code, and GLUT can even be used for other input devices.
To be honest though, I still don't see how this could possibly have anything to do with wxWidgets.
我的观点是,使用 wxWidgets 来编写快节奏的 3D 游戏是完全错误的。 在“硬核”游戏开发中,您应该使用它来开发支持工具,例如编辑器和转换器。
SDL 是最佳选择。 这可能看起来很基本,但一旦你开始向 SDL 的邪恶诸神献祭小孩子,就会出现诸如 SDL_image 之类的东西 (非常适合读取多种图像文件格式 - 就我有时仅使用 SDL 来读取例如 JPEG)或 SDL_mixer(读取和播放基本音频 - OGG、WAV 等所需的唯一解决方案)。
因此,SDL 就是您的最佳选择。 一旦您开始使用 SDL_gfx,即使是 2D 图形支持也很好。 SDL 乍一看可能很基础,但是一旦您计算了围绕它构建的所有额外库,并且编写了一些围绕它的包装器,您就会发现 SDL 是基本必需品和易于高级使用之间的完美平衡。
我很乐意以任何方式为您提供有关 SDL 的帮助,因为我发现它非常棒。
My opinion is that it's completely wrong to use wxWidgets to code fast-paced 3D games. In "hardcore" game development,you should use it to develop supporting tools, such as editors and converters.
SDL is the way to go. It may seem quite basic, but once you start sacrificing small children to the unholy gods of SDL, stuff like SDL_image (perfect for reading numerous image file formats - to the extent I sometimes use SDL solely to read e.g. JPEG) or SDL_mixer (sole solution you need for reading and playing basic audio - OGG, WAV, ...).
So look no further than SDL. Even the 2D graphics support is good once you start using SDL_gfx. SDL may at first seem basic, but once you count in all the extra libraries built around it, and once you code a few wrappers around it, you'll see SDL is the perfect balance between bare necessities and ease of advanced use.
I'll be happy to assist you in any way with SDL since I find it so awesome.
我可能会误解您在这里看到的内容,但是请查看返回的原始密钥代码将导致硬件、操作系统、配置和平台差异,因此您应该查看 按键事件返回的虚拟键码。
编辑:也许 wxWidgets 只是不能正确处理它
(值得怀疑)。numlock 键的问题是“迫使”您通过使用原始扫描代码来解决这个问题(效果很差)。
如果是这种情况,您不需要放弃您所做的事情,但是如果您添加 SDL 只是为了输入内容,您会发现返回 SDL_keysym 的调用不仅仅是返回硬件扫描码(您对“修复”无能为力),但还将其映射到 unicode 字符和虚拟符号,我认为这就是您正在寻找的。 希望他们的调用不会出现数字锁定修饰符问题。
I might be misunderestimating what your seeing here, but looking at the raw keycode returned is going to result in hardware, os, configuration and platform differences, so you should be looking at the virtual keycode returned by a key event.
EDIT: Maybe wxWidgets just doesn't handle it right
(doubtful).The issue of the numlock key is "forcing" you to work around this (poorly) by using the raw scan code.
If that's the case you don't need to throw away what you've done, but if you add SDL just for the input stuff, you'll find calls which return the SDL_keysym don't just return the hardware scancode (which you can do nothing about "fixing") but also map it to a unicode character and a virtual symbol, which is I think what you're looking for. Hopefully their calls don't have this numlock modifier problem.
如果您不想使用 SDL,我推荐 SFML - 简单快速的多媒体库 。
它是多平台的,并且使用起来非常简单。 例如,来自教程部分:
其中输入是
有一些迹象表明 SFML 比 SDL 更快,但我倾向于使用它来编写快速且可移植的代码,因为我比 SDL 更喜欢它的用法。
If you don't wan't to use SDL, I recommend SFML - Simple and Fast Multimedia Library.
It is multiplatform and really simple to use. For example, from tutorials section:
where Input is
There are some indications that SFML is faster than SDL, however I tend to use it to whip out fast and portable code since I like its usage more than SDL.