0

In Caliburn.Micro, how can I detect user activity (mouse click/movement) outside of a ViewModel?

For example, if a user has not clicked anything in an application for a certain amount of time it should go back to the start page of the application.

This could be implemented in each View/ViewModel, but this would cause a lot of code duplication as each View/ViewModel would need the same code.

I did find this promising question, but this seems to detect system wide user activity instead of application wide as I need.

Community
  • 1
  • 1
TheHvidsten
  • 4,028
  • 3
  • 29
  • 62
  • You are talking about detecting something in Model. This has nothing to do with ViewModel or Views unless you want to detect something specific to the view, then do it as usual: View -> command/direct method call -> ViewModel -> Model. What exact scenario you want to detect where linked question solutions doesn't fit? – Sinatr Aug 12 '16 at 11:42
  • The linked question detect system wide user activity. This includes user activity not related to my application. I just need to detect activity related to my application so that I can switch to a different view if the user has been idle for too long (while he is still allowed to be active in other applications) – TheHvidsten Aug 12 '16 at 12:19
  • Why you don't switch while he is not using application? Switch always (disregards active application). If user knows what there is a switch while he idling inside certain page of application it will not a surprise to him when this switching also occurs while he is alt-tabbed **and iddling in other application**. I don't see problem here. Or is the problem opposite - to detect idling only in current application? Then simply start timer when application is deactivated (in main/current window view), if timer expired before activation call method of ViewModel to pass to Model. Same activating. – Sinatr Aug 12 '16 at 12:28
  • For the sake of the argument, say that I want to log a user off an application if he is idle. I then want to log off the user regardless if the user is active in another application. So the user logs on, changes to another application and does stuff there, but because he is not active in my application he gets logged off. So a user is still active on the PC, but just not in my application. I want to detect that the user is inactive on my application. I don't care if he is active/inactive in other applications. – TheHvidsten Aug 12 '16 at 12:40
  • You can start timer somewhere and hook mouse/keyboard. On hook event reset timer if application is active. If timer expired - do log off, because user wasn't active in your application. See [this](http://stackoverflow.com/q/3312752/1997232), I only did global hooks, maybe you can do local hook (to UI thread?) somehow, then you don't even need to track if application is active. – Sinatr Aug 12 '16 at 12:59

0 Answers0