In Linux Kbhit is not included Using signals in Linux how ca

In Linux Kbhit() is not included. Using signals in Linux, how can you make a random key into a signal. So that when the key is pressed a certain function is called.

Ex. When Ctrl+C is pressed the SIGINT is called.

How can you press like spacebar and myfunction gets called?

Solution

Since getch(), kbhit() functions in c are not available in case of linux, we prefer signals to be made for recognization of key press in linux... But here we can use keypress(0) function available under stdio.h ,termios.h and unistd.h header files...

printf(\"enter spcae bar to call a function\");

while(keypress(0) !=\' \');

function();

The above given code will wait for the user input to check for key pressed and then if he press spacebar then calls an function();

In Linux Kbhit() is not included. Using signals in Linux, how can you make a random key into a signal. So that when the key is pressed a certain function is cal

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site