Click here to Skip to main content
15,886,725 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
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.
Posted
Comments
Sergey Alexandrovich Kryukov 2-Jun-14 2:35am    
21H interrupt? Is it DOS or something?
—SA

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900