在c编程中使用键盘中断 [英] using keyboard interrupts in c programming

查看:133
本文介绍了在c编程中使用键盘中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用键盘的左,右,上和下键。所以请告诉我如何在c中使用中断21h。

i want to use left, right, up and down keys of key board. so please tell me that how to use interrupt 21h in c.

推荐答案

中断是汇编程序,而不是C,它们是硬件依赖,i。即必须适应您正在编写程序的特定CPU。该程序可能无法在具有不同CPU的计算机上运行,​​即使它们运行相同的操作系统。你真的不应该这样做,除非有一个很好的理由,而且你很好,程序将在你的个人机器上运行!



如果你想要对于C的答案,主要有两个函数可以使用: getch()将等待下一次按键并返回相应的键码。 kbhit()只会检查一个键是否被击中。



您可以找到更多解释和代码示例适用于UNIX和Windows: http://stackoverflow.com/questions/448944/c-non-阻止键盘输入 [ ^ ]



这里还讨论了一个关键控制游戏的编程:http://www.cplusplus.com/forum/beginner/89434/ [ ^ ]。这里的代码包含C ++元素,但relvant部分是C。
Interrupts are Assembler, not C, and they are hardware dependend, i. e. must be adapted to the specific CPU you are writing the program for. The program will likely not run on machines with different CPUs, even if they run the same OS. You really shouldn't do that unless there is a very good reason, and you're fine that the program will just run on your personal machine!

If you want an answer for C, there are mainly two functions you can use: getch() will wait for the next key press and return the corresponding keycode. kbhit() will merely check whether a key was hit.

You can find some more explanations and code examples for UNIX and Windows here : http://stackoverflow.com/questions/448944/c-non-blocking-keyboard-input[^]

There's also a discussion on programming a key-controlled game here: http://www.cplusplus.com/forum/beginner/89434/[^]. The code here includes C++ elements, but the relvant parts are C.


这篇关于在c编程中使用键盘中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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