Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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.</p> <p>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.):</p> <pre><code>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); } </code></pre> <p>Then in the handlers have code like this for the mouse move:</p> <pre><code>private void RootVisual_MouseMove(object sender, MouseEventArgs e) { timeOfLastActivity = DateTime.Now; } </code></pre> <p>and a similar one for the <code>KeyDown</code> event handler.</p> <p>You will have to set off a timer:</p> <pre><code>idleTimer = new DispatcherTimer(); idleTimer.Interval = TimeSpan.FromSeconds(1); idleTimer.Tick += new EventHandler(idleTimer_Tick); // Initialise last activity time timeOfLastActivity = DateTime.Now; </code></pre> <p>Then in the tick event handler have something like this:</p> <pre><code>private void idleTimer_Tick(object sender, EventArgs e) { if (DateTime.Now &gt; timeOfLastActivity.AddSeconds(30)) { // Do your stuff } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload