Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 833467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:31:21+00:00 2026-05-15T04:31:21+00:00

I am building an application for which I need to periodically get information about

  • 0

I am building an application for which I need to periodically get information about users keyboard. It is going to be user idle detection application. I have a fairly simple solution to periodically check if the mouse has been moved. But I can’t figure any reasonable non root way to detect if the keyboard has been pressed.

I was thinking about registering a hook every timer timeout and on any key press to unregister it. So if there is no key press for a long time then my program will know if the user is idle.

Anyway, I couldn’t find any global hooks for any key, including modifiers. Is there an easy way to do this? Or would someone have a better way to detect keyboard idleness?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T04:31:22+00:00Added an answer on May 15, 2026 at 4:31 am

    After a lot of searching I found this:

    bool kbdActivity(Display* display)  // checks for key presses
    {
        XQueryKeymap(display, keymap);  // asks x server for current keymap
        for (int i=0; i<32; i++)        // for 0 to 32 (keymap size)
        {
            if (prevKeymap[i] != keymap[i])   // if previous keymap does not
            {                               // equal current keymap 
                XQueryKeymap(display, prevKeymap);  // ask for new keymap
                return true;                // exit with true
            }
        }
        return false;                   // no change == no activity
    }
    

    When I call it every 100-300ms it detects any pressed key anywhere in X.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a WPF application in which I have a need to get the
I'm building a web application in which I need to scan the user-uploaded files
I'm looking at building a Rails application which will have some pretty large tables
I'm building an application which will have dynamic allocated objects of type A each
I am going to be building a application which will be used by people
I am building an application which will send status requests to users (via email
I'm building an application which I'd like to have it connect to a website
I have a SharePoint server. I am building an rails application which can interact
I am building a application that services users via a web front end, which
I am building a WPF application in which I need to open one of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.