Pengecekan Keyboard Stroke di C UNIX (2)

Posted: November 7, 2008 in C/C++, Open Source Tutorial, Programming
Tags: , , , ,

Wew…sebelumnya pengecekan keyboard stroke yang pake kbhit itu ada kelemahannya, yaitu……resposinya jelek, kbhit cuman ngecek keyboard tersebut tidak idle klo kita ketikkan suatu string ke terminal dan kita tekan ENTER. Nah, kalau kita cuman mencet2 kibor dan gak tekan enter…ya kbhit tadi menganggap kita idle…
Nah, disini ternyata, lagi-lagi ada cara yang lebih seru dan lebih keren, kita cek TTY-nya :

static int long_idle_time;  // ini variabel global

void check_idle()
{
    struct stat stbuf;
    stat(tty, &stbuf);
    char out[100];;
    char time_now[100];
    time_t now,*mod_time;
    memset( out, '', sizeof( time_now) );
    now = time( NULL );
    mod_time = &stbuf.st_mtime;
    if(last_mod_time!=*mod_time)
    {
        last_mod_time=*mod_time;
        long_idle_time=0;
    }
    else long_idle_time++;
    char output[100];
    sprintf(output,"%s has been idle for %d second",tty,long_idle_time);
    syslog(LOG_INFO, output);
}

nah,kita bisa dapat berapa lama user sedang idle lewat variabel long_idle_time

Comments
  1. stroke says:

    bagaimana cara megobati orang yang terkena stroke???

  2. azer89 says:

    waduh..saya gak kuliah di FK neh…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s