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

  • Home
  • SEARCH
  • 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 8465819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:09:32+00:00 2026-06-10T15:09:32+00:00

I’m programming a WPF application, and I’d like to raise an event if the

  • 0

I’m programming a WPF application, and I’d like to raise an event if the user has not interacted with the program for 30 seconds. That is to say, no keyboard or/and mouse events.

The reason I want do do this is because I want to bring attention to the screen if a variable alertstate has been set to true.

I’m thinking of using something along the lines of BackgroundWorker but I really don’t know how I can get the time a user has not interacted with the program. Can someone point me in the right direction?

I guess this question basically comes down to checking if a user has interacted with the screen. How do I do this?

  • 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-06-10T15:09:33+00:00Added an answer on June 10, 2026 at 3:09 pm

    You need to record the last time the user moved the mouse or pressed a key and then check if that time is greater than your threshold.

    So you need to add mouse move, mouse click and keyboard handlers to your application (this is Silverlight code so you might have to change namespaces etc.):

    private void AttachEvents()
    {
        Application.Current.RootVisual.MouseMove += new MouseEventHandler(RootVisual_MouseMove);
        Application.Current.RootVisual.KeyDown += new KeyEventHandler(RootVisual_KeyDown);
    
        Application.Current.RootVisual.AddHandler(UIElement.MouseLeftButtonDownEvent, (MouseButtonEventHandler)RootVisual_MouseButtonDown, true);
        Application.Current.RootVisual.AddHandler(UIElement.MouseRightButtonDownEvent, (MouseButtonEventHandler)RootVisual_MouseButtonDown, true);
    }
    

    Then in the handlers have code like this for the mouse move:

    private void RootVisual_MouseMove(object sender, MouseEventArgs e)
    {
        timeOfLastActivity = DateTime.Now;
    }
    

    and a similar one for the KeyDown event handler.

    You will have to set off a timer:

    idleTimer = new DispatcherTimer();
    idleTimer.Interval = TimeSpan.FromSeconds(1);
    idleTimer.Tick += new EventHandler(idleTimer_Tick);
    
    // Initialise last activity time
    timeOfLastActivity = DateTime.Now;
    

    Then in the tick event handler have something like this:

    private void idleTimer_Tick(object sender, EventArgs e)
    {
        if (DateTime.Now > timeOfLastActivity.AddSeconds(30))
        {
            // Do your stuff
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has

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.