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 1065623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T19:50:03+00:00 2026-05-16T19:50:03+00:00

I am writing a C# Project that is relatively simple. Think Public Web Terminal.

  • 0

I am writing a C# Project that is relatively simple. Think “Public Web Terminal”. Essentially there is a maximized form with a fill-docked web browser on it. The web browser control I am using is the WebKit Control found here:

WebKit Download Page

I am trying to detect system idle time by keeping a DateTime which represents the last time a mouse movement or key press was made.

I have instituted event handlers (see code below), and have come across a stumbling block. The mouse (and key) events seem to not fire when my mouse moves over the web document. It DOES work fine when my mouse touches the vertical scroll bar portion of the web browser control, so I know the code is OK – it seems to be some sort of “oversight” (for lack of a better word) on the control’s part.

I guess my question is – to all of you coders out there, how would you go about handling this?

this.webKitBrowser1.KeyPress += new KeyPressEventHandler(handleKeyPress);
this.webKitBrowser1.MouseMove += new MouseEventHandler(handleAction);
this.webKitBrowser1.MouseClick += new MouseEventHandler(handleAction);
this.webKitBrowser1.MouseDown += new MouseEventHandler(handleAction);
this.webKitBrowser1.MouseUp += new MouseEventHandler(handleAction);
this.webKitBrowser1.MouseDoubleClick += new MouseEventHandler(handleAction);

void handleKeyPress(object sender, KeyPressEventArgs e)
{
    this.handleAction(sender, null);
}

void handleAction(object sender, MouseEventArgs e)
{
    this.lastAction = DateTime.Now;
    this.label4.Text = this.lastAction.ToLongTimeString();
}

UPDATE

Using Joe’s accepted solution, I put together the following class. Thanks to all who participated.

class classIdleTime
{
    [DllImport("user32.dll")]
    static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);

    internal struct LASTINPUTINFO
    {
        public Int32 cbSize;
        public Int32 dwTime;
    }

    public int getIdleTime()
    {
        int systemUptime = Environment.TickCount;
        int LastInputTicks = 0;
        int IdleTicks = 0;

        LASTINPUTINFO LastInputInfo = new LASTINPUTINFO();
        LastInputInfo.cbSize = (Int32)Marshal.SizeOf(LastInputInfo);
        LastInputInfo.dwTime = 0;

        if (GetLastInputInfo(ref LastInputInfo))
        {
            LastInputTicks = (int)LastInputInfo.dwTime;
            IdleTicks = systemUptime - LastInputTicks;
        }
        Int32 seconds = IdleTicks / 1000;
        return seconds;
    }

USAGE

idleTimeObject = new classIdleTime();
Int32 seconds = idleTimeObject.getIdleTime();
this.isIdle = (seconds > secondsBeforeIdle);
  • 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-16T19:50:06+00:00Added an answer on May 16, 2026 at 7:50 pm

    You could just ask Windows if the user is idle. You’ll have to use P/Invoke, but it would be the easiest. Check out the GetLastInputInfo function.

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

Sidebar

Related Questions

I am writing a query to fetch results for all the values in a
I am learning on my own about writing an interpreter for a programming language,

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.