Linux 中 kbhit 的汇编实现
我正在用汇编语言编写游戏,我需要检查是否按下了某个键。 那么,kbhit在Linux中是如何实现的呢?
谢谢。
I'm writing a game in assembly, and I need to check if a key was pressed.
So, how is kbhit implemented in Linux?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Google 在 C 语言中找到了 Linux 的 kbhit 实现:http://cboard。 cprogramming.com/c-programming/63166-kbhit-linux.html
您可以按原样编译此代码并从汇编代码中调用它,或者如果您确实愿意,可以将其转换为将其组装。
Google turned up a kbhit implementation for Linux in C: http://cboard.cprogramming.com/c-programming/63166-kbhit-linux.html
You could either compile this as is and call it from your assembly code, or if you really want to you could convert it to assembly.
我假设您还需要关键版本。我还假设您在控制台上(对于 X,XKeyEvent 有足够的信息)。
首先,您必须将终端(即:控制台)置于非规范或原始模式。如果不这样做,您将看不到任何输入,直到输入出现行分隔符或 EOF。请参阅我对您之前的问题的回答。
然后,要获得密钥版本,您需要将键盘设置为 RAW 或 MEDIUMRAW 模式(这与终端原始模式无关,这是 Linux 和控制台特定的,请参阅 console_ioctl(4))。退出之前不要忘记将键盘设置回原始模式。
此处有一篇关于此的好文章。
I assume that you want also key releases. I also assume you are on the console (for X, XKeyEvent has enough info).
First, you have to put your terminal (i.e: console) in non-canonical or in raw mode. If you don't do this, you won't see any input until there is a line delimiter or EOF on input. See my answer to your previous question.
Then, to get key releases, you want to set the keyboard to RAW or MEDIUMRAW mode (this has nothing to do with terminal raw mode, this is very Linux and console specific, see console_ioctl(4)). Don't forget to set the keyboard back to its original mode before exiting.
There's a nice article about this here.