C++ 中箭头键按下的平台独立检测
在 C++ 控制台程序中,我找到了如何在 Windows 上检测和箭头键,并且我发现了很多与问题无关的其他内容(尽管我认为是很好的搜索词),但我想知道是否有一种独立于平台的方法来检测箭头键按下。一个不错的第二名是如何检测 unix 和 mac 中的箭头键按下。代码片段将不胜感激。
In a C++ console program, I've found how to detect and arrow key on Windows, and I've found a lot of other stuff that had nothing to do with the question (despite what I thought were good search terms), but I want to know if there is a platform-independent way to detect an arrow key press. A decent second place for this would be how to detect arrow key press in unix and mac. Code fragments would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 SDL2 来跨平台执行此操作。
示例代码:
You can do this cross-platform by using SDL2.
Example code:
正如比利所说,没有标准的跨平台方法可以做到这一点。
就我个人而言,我将这个(面向游戏的)库用于所有输入,跨平台 win/linux/mac : http: //sourceforge.net/projects/wgois/
As Billy said, there is no standard cross-platform way to do it.
Personally I use this (game-oriented) library for all inputs, cross-platform win/linux/mac : http://sourceforge.net/projects/wgois/
没有跨平台的方法可以做到这一点,因为它不是由 C 或 C++ 标准定义的(尽管可能有一些库可以在不同平台上编译时抽象出差异)。
我相信您在 POSIX 盒子上寻找的库是 curses,但我自己从未使用过它——我可能是错的。
请记住,控制台程序(即
gnome-terminal
或konsole
或xterm
)完全有可能垄断这些键的使用。功能。There's no cross platform way to do it because it's not defined by either C or C++ standards (though there may be libraries which abstract away the differences when compiled on different platforms).
I believe the library you are looking for on POSIX boxes is curses, but I've never used it myself -- I could be wrong.
Keep in mind that it's entirely possible the console program (i.e.
gnome-terminal
orkonsole
orxterm
) has monopolized the use of those keys for other functions.