简体   繁体   中英

Detect if user Idle on windows universal app

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?

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.

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.
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM