Project Homepage Sourceforge Page CVS Repository Freshmeat.net Page Download project Author's Homepage

kbhit.c File Reference


Detailed Description

Handle console keyboard functionality.

Definition in file kbhit.c.

#include <stdio.h>
#include <termios.h>
#include <term.h>
#include <curses.h>
#include <unistd.h>
#include "kbhit.h"

Include dependency graph for kbhit.c:

Include dependency graph

Go to the source code of this file.

Functions

int do_kbhit ()
 do a kbhit

void init_keyboard ()
 initialize the keyboard

void close_keyboard ()
 reset the keyboard terminal settings


Variables

termios initial_settings new_settings
 console termio settings (pre and post operation)


Function Documentation

void close_keyboard  ) 
 

reset the keyboard terminal settings

Author:
Karl N. Redman, various

Definition at line 88 of file kbhit.c.

Referenced by do_kbhit().

00089 {
00090         //reset terminal to initial settings
00091         tcsetattr(0, TCSANOW, &initial_settings);
00092 }

int do_kbhit  ) 
 

do a kbhit

Author:
Karl N. Redman, various.

Definition at line 40 of file kbhit.c.

References close_keyboard(), and init_keyboard().

Referenced by main().

00041 {
00042         int ch = 0;
00043 
00044         printf("PRESS ANY KEY TO CONTINUE");
00045         fflush((FILE *)0);
00046 
00047         //set keyboard state - no echo, single char input
00048         init_keyboard();
00049 
00050         //get charecter
00051         read(STDIN_FILENO, &ch, 1); /* getchar() works here too */
00052         printf("%c",ch);
00053 
00054         //set keyboard back to initial state
00055         close_keyboard();
00056 
00057         return(0);
00058 }

Here is the call graph for this function:

void init_keyboard  ) 
 

initialize the keyboard

Author:
Karl N. Redman, various

Definition at line 65 of file kbhit.c.

References new_settings.

Referenced by do_kbhit().

00066 {
00067   //    struct termios new_settings;
00068 
00069         //save attribures for close
00070         tcgetattr(0, &initial_settings);
00071 
00072         //set no echo, one char input,
00073         new_settings = initial_settings;
00074         new_settings.c_lflag &= ~ICANON;
00075         new_settings.c_lflag &= ~ECHO;
00076         new_settings.c_lflag &= ~ISIG;
00077         new_settings.c_cc[VMIN] = 1;
00078         new_settings.c_cc[VTIME] = 0;
00079 
00080         tcsetattr(0, TCSANOW, &new_settings);
00081 }


Variable Documentation

struct termios initial_settings new_settings [static]
 

console termio settings (pre and post operation)

Definition at line 33 of file kbhit.c.

Referenced by init_keyboard().


Generated on Thu Mar 18 07:26:19 2004 for run-free by doxygen 1.3.5