8

I'm developing a class library for windows 10 universal apps (mobile and desktop device families only). I need to invoke an event if the user has been idle(no touch, mouse move, key press etc) for x number of seconds. This method can be used to solves this problem on android. But I couldn't find a solution on windows UWP.

Is there an API available in UWP to achieve this?

Kavinda Gayashan
  • 387
  • 4
  • 17

2 Answers2

8

You can detect global input with various events on the app's CoreWindow:

Touch and mouse input with CoreWindow.PointerPressed, PointerMoved, and PointerReleased.

Keyboard input: KeyUp and KeyDown (the soft keys) and CharacterReceived (for characters generated via chords & text suggestions)

Use these to detect the user is active and idle out if it goes too long without any of these events.

Rob Caplan - MSFT
  • 21,714
  • 3
  • 32
  • 54
2

I know this is really old question, but I think you can now get to same result with RegisterBackgroundTask

Just set:

new TimeTrigger(15, false) //For time trigger

Link

new SystemCondition(SystemConditionType.UserNotPresent)) //And so you want to know so user is not present

Link

Example usage in App.xaml.cs:

var builder = new BackgroundTaskBuilder();
builder.Name = "Is user Idle";
builder.SetTrigger(new TimeTrigger(2, false)); //two mins
builder.AddCondition(new SystemCondition(SystemConditionType.UserNotPresent));
// Do not set builder.TaskEntryPoint for in-process background tasks
// Here we register the task and work will start based on the time trigger.
BackgroundTaskRegistration task = builder.Register();
task.Completed += (sender, args) =>
{
    //Handle user not present (Idle) here.
};
Flair
  • 2,609
  • 1
  • 29
  • 41
TekuSP
  • 21
  • 4
  • Please provide additional details in your answer. As it's currently written, it's hard to understand your solution. – Community Sep 05 '21 at 20:18
  • Added solution example. – TekuSP Sep 06 '21 at 09:01
  • The `TimeTrigger` Class has a minimum value which is `15` minutes. You could not set a time interval that less than `15` minutes to the `TimeTrigger`. This is mentioned here: `TimeTrigger.FreshnessTime Property` – NoWar Nov 12 '21 at 07:53