How to Determine When User is Inactive?

I have an extension that needs to do some processing that interferes with drawing and moving tools around. So i want to make sure I only do the processing when the user is not doing anything. I need to search for a moment when the user isn’t sending any input to the computer. How can I determine this in my extension since you can’t get the mouse position without your tool being active?

So far I have:

ToolsObserver: detect any tool state change.

SelectionObserver: detect any selection change

View Observer: Detect any camera movements.

But its not enough. I need to know if the user is moving their mouse. Is there any way to get mouse position, or even if not mouse position just get informed that the mouse moved? Is there any kind of log file I can check that would record a last user activity time? Anything at all to let me know how long its been since there was user input in sketchup?

In my opinion the best approach, that you inform the user that you are doing something in a background. So, he will know it and “won’t move”. Users are smart enough - you can assume, they can understand it.

By the way, the Sketchup::Overlay class may be suitable for mouse tracking if you are using version 2023 or later.

Unfortunately I’m using the old version. And I cannot inform the user because this happens continuously every time the user stops moving their mouse.

Just because the user doesn’t move the mouse doesn’t necessarily mean the system isn’t busy.
Perhaps the best example would be that another developer with the same attitude as you also runs similar code in the background that monitors whether the mouse is moving and starts something in the background that the user has no idea about because he wasn’t notified.
Maybe he just started a process that is not related to Tool, e.g. purge…

Furthermore, the user chose the Tool he is using because he expect it to work as they usually do. “Knock it out of his hand” is not an expected behaviour. This is a wrong approach.

When he stop the mouse, you take control, but you have no idea what is going on in the user’s mind, and you can’t be sure when he will move it again. Are you sure that you will finish your calculations in that undefined time? If not, you will definitely annoy the user.
You think it is just a little disturbance. Well that is always relative.

Constantly monitoring the user, setting observers, reading log files, or whatever… also requires resources that take processor time away from “useful” calculations.

4 Likes

The only good time to do such things is in the pre-Save observer callback of a ModelObserver.

Otherwise, the API does not have any means to determine “inactivity”, which might be considered subjective. (Ie, the user may stop moving the mouse, but because some other process or extension may be doing some heavy work.)
For example, there is no exposure to when the user shifts focus to another application or brings the focus back to SketchUp.* (We can cause it with the API with 21.1+, but not in SU2017.)

* Mentioned in: Tracking major events in the lifetime of a Sketchup session · Issue #682 · SketchUp/api-issue-tracker · GitHub