Page principale | Liste alphabétique | Liste des classes | Liste des fichiers | Membres de classe | Membres de fichier | Pages associées

SurcoucheTouche.cpp

Aller à la documentation de ce fichier.
00001 /*! \file SurcoucheTouche.cpp
00002     \brief Surcouche pour touche.
00003 
00004     Redéfinie tout un tas de fonctions système pour les rendre portables unix et windows.
00005 
00006     \author     aerith (www.aerith.fr)
00007     \version    1.0
00008     \date       01/11/2007
00009 */
00010 
00011 #include    "SurcoucheTouche.h"
00012 
00013 
00014 void mode_raw(int activer)
00015 {
00016 #ifndef WIN32
00017    static struct    termios cooked;
00018    static int       raw_actif = 0;
00019 
00020    if(raw_actif == activer)
00021       return;
00022 
00023    if(activer)
00024    {
00025       struct termios raw;
00026 
00027       tcgetattr(STDIN_FILENO, &cooked);
00028 
00029       raw = cooked;
00030       cfmakeraw(&raw);
00031       tcsetattr(STDIN_FILENO, TCSANOW, &raw);
00032 
00033    }
00034    else
00035       tcsetattr(STDIN_FILENO, TCSANOW, &cooked);
00036 
00037    raw_actif = activer;
00038 #endif
00039 }
00040 
00041 int     KeyGet()
00042 {
00043     fflush(stdin);
00044 #ifdef WIN32
00045     return _getch();
00046 #else
00047     return getchar();
00048 #endif
00049 }
00050 
00051 int     KeyPressed()
00052 {
00053 #ifdef WIN32
00054     return _kbhit();
00055 #else
00056     struct timeval  tv = {0, 0};
00057     fd_set          readfds;
00058 
00059     FD_ZERO(&readfds);
00060     FD_SET(STDIN_FILENO, &readfds);
00061 
00062     return select(STDIN_FILENO + 1, &readfds, NULL, NULL, &tv) == 1; 
00063 #endif
00064 }
00065 
00066 int     KeyWait()
00067 {
00068     int     c;
00069 
00070     mode_raw(1);
00071 
00072     while(!KeyPressed());
00073     c = KeyGet();
00074 
00075     mode_raw(0);
00076 
00077     return c;
00078 }
00079 

Généré le Thu Jun 12 09:12:30 2008 pour A.I.F. par  doxygen 1.3.9.1