且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在c编程中使用键盘中断

更新时间:2023-11-20 15:43:10

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



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



您可以找到更多解释和代码示例适用于UNIX和Windows: http://***.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://***.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.