Linux 中 kbhit 的汇编实现

发布于 2024-09-28 06:07:03 字数 70 浏览 0 评论 0原文

我正在用汇编语言编写游戏,我需要检查是否按下了某个键。 那么,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北城半夏 2024-10-05 06:07:03

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.

染墨丶若流云 2024-10-05 06:07:03

我假设您还需要关键版本。我还假设您在控制台上(对于 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文