Find the answer to your Linux question:
Results 1 to 5 of 5
Hi. Im trying to execute some actions when there's no keyboard action in "x" seconds or minutes (after "x" seconds or minutes of keyboard inactivity), but is hard to find ...
  1. #1
    Just Joined!
    Join Date
    Apr 2010
    Posts
    2

    [C++] how to execute some action after "x" seconds of keyboard inactivity?

    Hi.

    Im trying to execute some actions when there's no keyboard action in "x" seconds or minutes (after "x" seconds or minutes of keyboard inactivity), but is hard to find something about this...

    and i dont know if this will make a lot of cpu usage

  2. #2
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    This is what the powermanager/screensaver from Gnome/KDE/etc. basically does. So I would look how they do it.
    Debian GNU/Linux -- You know you want it.

  3. #3
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    GNU-Fan's suggestion is reasonable is you are talking about a system where the USER is running an X-Windows desktop (KDE, Gnome, XFCE, etc). It really depends a lot on the environment. As for CPU utilization, it should not be an issue, unless you use a polling construct to detect the keypress. Normally this would be an event-driven handler. It sounds like you need to do some studying of how to deal with hardware asyncronous events in user-space programs.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  4. #4
    Just Joined!
    Join Date
    Apr 2010
    Posts
    2
    im using fluxbox, no kde/gnome. and no user, just root (its an embeeded linux)

  5. #5
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Well, in that case I would download the fluxbox source and see what they do to trigger the screen saver. Since it is an X-Windows application, they undoubtedly trap keypress events anywhere on the screen to reset the timer. It's not that hard to do with low-level Xlib functions, but then it isn't trivial either. Basically, you need a timer that will start your program when it expires, and a kepress XEvent handler that will reset the timer when it detects a keypress anywhere on the screen.

    The source for fluxbox is available here: fluxbox.org - download
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...