Detect if user Idle on windows universal app
Asked Answered
P

2

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?

Package answered 29/6, 2015 at 11:3 Comment(1)
Hi, Check this answer. https://mcmap.net/q/1328014/-how-to-check-if-user-is-idle-on-uwp-duplicateElamitic
M
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.

Melodramatize answered 1/7, 2015 at 5:23 Comment(0)
O
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.
};
Overrate answered 5/9, 2021 at 19:44 Comment(3)
Please provide additional details in your answer. As it's currently written, it's hard to understand your solution.Alliteration
Added solution example.Overrate
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 PropertyCyprian

© 2022 - 2024 — McMap. All rights reserved.