检测用户在Windows 8商店应用程序或系统范围内不活动的时间
本文关键字:系统 范围内 不活动 时间 应用程序 用户 Windows 检测 | 更新日期: 2023-09-27 18:17:56
我试图检测用户在应用程序或Windows 8商店应用程序API的系统范围内不活跃的时间。
我查看了系统触发User Away,但是它只告诉你它什么时候空闲。不允许你指定特定的时间。我还研究了《Pointer Pressed》并尝试检测点击或触摸事件;但这不起作用,因为我使用的是webview,无法通过webview捕获PointerPressed事件。
是否有任何方法可以检测用户是否在应用程序或系统范围内闲置了X时间?任何帮助都很感激,谢谢!
我最终用javascript检测按键和鼠标按下事件。在LoadCompleted事件中,我使用AW_WebView注入javascript。调用脚本("eval",新字符串[]{scriptsString});
按键脚本:
window.document.body.onkeydown = function(event){
window.external.notify('key_pressed');
};
Mouse Down Scripts:
document.onmousedown = function documentMouseDown(e){
window.external.notify('mouse_down');
}
您可以为其他用户事件添加额外的脚本。
当检测到鼠标按下或键时,window.external。Notify("按下键盘或鼠标")被执行。此消息在我的WebView_ScriptNotify事件中得到"接收"。当我收到来自WebView的消息时,我设置了一个计时器。如果已经设置了计时器,则取消它并重新启动计时器。当计时器完成时,一些代码被执行。
private void SetTimer(int time)
{
if (!TimerEnabled)
{
return;
}
else
{
if (DelayTimer != null)
{
DelayTimer.Cancel();
DelayTimer = null;
}
//the timeout
TimeSpan delay = TimeSpan.FromSeconds(time);
bool completed = false;
DelayTimer = ThreadPoolTimer.CreateTimer(
(source) =>
{
//
// Update the UI thread by using the UI core dispatcher.
//
Dispatcher.RunAsync(
CoreDispatcherPriority.High,
() =>
{
//
// UI components can be accessed within this scope.
//THIS CODE GETS EXECUTED WHEN TIMER HAS FINISHED
});
completed = true;
},
delay,
(source) =>
{
//
// TODO: Handle work cancellation/completion.
//
//
// Update the UI thread by using the UI core dispatcher.
//
Dispatcher.RunAsync(
CoreDispatcherPriority.High,
() =>
{
//
// UI components can be accessed within this scope.
//
if (completed)
{
// Timer completed.
}
else
{
// Timer cancelled.
}
});
});
}
}
希望这能帮助到一些人!我知道这不是一个完美的方法来完成这项工作,但目前这对我来说是有效的。