|
fdhwlib
2.0.25
|
#include <keyboard.h>
Emulates the kbhit() function known from.
the windows world
Definition at line 49 of file keyboard.h.
| keyboard::keyboard | ( | ) | [inline] |
| keyboard::~keyboard | ( | ) | [inline] |
Definition at line 151 of file keyboard.h.
References orig.
{
#ifdef __GNUC__
tcsetattr(0,TCSANOW, &orig);
#endif
}
| char keyboard::getchar | ( | ) | [inline] |
Definition at line 232 of file keyboard.h.
Referenced by getpasswd(), and hit().
| char * keyboard::getpasswd | ( | ) | [inline] |
Read a password from the terminal.
Definition at line 268 of file keyboard.h.
References getchar(), hit(), and passwd.
{
char ch;
int i;
// Clear password
fflush(stdout);
ch = 0;
i = 0;
while ((ch != '\n') && (ch != '\r') && (i<20)){
if (hit()){
ch = getchar();
switch (ch){
case '\n':
case '\r':
break;
default:
passwd[i] = ch;
printf("*"); fflush(stdout);
i++;
break;
}
}
}
passwd[i] = 0;
printf("\n");
return(passwd);
}
| bool keyboard::hit | ( | ) | [inline] |
Definition at line 165 of file keyboard.h.
References key, newt, and peek.
Referenced by getpasswd(), and hit().
{
#ifdef __GNUC__
char ch;
int nread;
if(peek != -1) return 1;
newt.c_cc[VMIN]=0;
tcsetattr(0, TCSANOW, &newt);
nread = read(0,&ch,1);
newt.c_cc[VMIN]=1;
tcsetattr(0, TCSANOW, &newt);
if(nread == 1) {
peek = ch;
return 1;
}
#else
//_kbhit(); // ??? Where is the difference
if ( _kbhit() ) {
key = _getch();
return 1;
}
#endif
return 0;
}
| bool keyboard::hit | ( | char | key | ) | [inline] |
char keyboard::key [private] |
Definition at line 103 of file keyboard.h.
struct termios keyboard::newt [private] |
Definition at line 95 of file keyboard.h.
Referenced by hit(), and keyboard().
struct termios keyboard::orig [private] |
Definition at line 89 of file keyboard.h.
Referenced by keyboard(), and ~keyboard().
| char keyboard::passwd[20] |
Character string that contains the last password entered.
Definition at line 79 of file keyboard.h.
Referenced by getpasswd().
int keyboard::peek [private] |
Definition at line 99 of file keyboard.h.
Referenced by getchar(), hit(), and keyboard().