Shadowrun: Awakened 29 September 2011 - Build 871
Functions | Variables
Kbhit.h File Reference
#include <sys/time.h>
#include <termios.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
Include dependency graph for Kbhit.h:

Go to the source code of this file.

Functions

static void cooked (void)
static int getch (void)
static int kbhit (void)
static void raw (void)

Variables

static struct termios g_old_kbd_mode

Function Documentation

static void cooked ( void  ) [static]

Definition at line 23 of file Kbhit.h.

References g_old_kbd_mode.

Referenced by raw().

{
    tcsetattr(0, TCSANOW, &g_old_kbd_mode);
}
static int getch ( void  ) [static]

Definition at line 72 of file Kbhit.h.

References raw().

{
    unsigned char temp;

    raw();
/* stdin = fd 0 */
    if(read(0, &temp, 1) != 1)
        return 0;
    return temp;
}
static int kbhit ( void  ) [static]

Definition at line 51 of file Kbhit.h.

References raw().

{
    struct timeval timeout;
    fd_set read_handles;
    int status;

    raw();
/* check stdin (fd 0) for activity */
    FD_ZERO(&read_handles);
    FD_SET(0, &read_handles);
    timeout.tv_sec = timeout.tv_usec = 0;
    status = select(0 + 1, &read_handles, NULL, NULL, &timeout);
    if(status < 0)
    {
        printf("select() failed in kbhit()\n");
        exit(1);
    }
    return status;
}
static void raw ( void  ) [static]

Definition at line 29 of file Kbhit.h.

References cooked(), and g_old_kbd_mode.

Referenced by getch(), and kbhit().

{
    static char init;

    struct termios new_kbd_mode;

    if(init)
        return;
/* put keyboard (stdin, actually) in raw, unbuffered mode */
    tcgetattr(0, &g_old_kbd_mode);
    memcpy(&new_kbd_mode, &g_old_kbd_mode, sizeof(struct termios));
    new_kbd_mode.c_lflag &= ~(ICANON | ECHO);
    new_kbd_mode.c_cc[VTIME] = 0;
    new_kbd_mode.c_cc[VMIN] = 1;
    tcsetattr(0, TCSANOW, &new_kbd_mode);
/* when we exit, go back to normal, "cooked" mode */
    atexit(cooked);

    init = 1;
}

Variable Documentation

struct termios g_old_kbd_mode [static]

Definition at line 20 of file Kbhit.h.

Referenced by cooked(), and raw().


Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net