我正在尝试使用Windows 8应用商店应用程序API检测用户在应用程序或系统范围内处于不活动状态的时间。
我查看了系统触发用户离开的情况,但它只会告诉您它何时空闲。不允许您指定特定的时间。我还查看了按下的指针,并尝试检测点击或触摸事件;但这不起作用,因为我正在使用web视图,无法通过web视图捕获PointerPressed事件。
有没有办法检测用户是否在应用程序或系统范围内空闲了X个时间?感谢您的帮助,谢谢!
发布于 2013-07-10 05:19:58
我最终用javascript检测到了按键和鼠标按下事件。在LoadCompleted事件内部,我使用AW_WebView.InvokeScript("eval",new string[] { scriptsString })注入javascripts;
按键脚本:
window.document.body.onkeydown = function(event){
window.external.notify('key_pressed');
};
鼠标按下脚本:
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.
}
});
});
}
}
希望这对某些人有帮助!我知道这不是一个完美的完成这件事的方法,但就目前而言,这对我来说是有效的。
https://stackoverflow.com/questions/17027352
复制相似问题