I imagine you are using windows API to recover cursor position, but this function should stop working when you disconnect, end there is a "monitor" so it is possible to say the current position.
Not knowing the technology used in the macro, it’s also complicated to make affirmations, but I imagine that it uses the windows Apis to click buttons, type text, etc.
Well, this macro must have a mechanism, at each event, to determine whether or not it can continue with the actions.
Finally, a solution in this case, is to make that each time the macro is waiting for the next step of the loop, it counts the time and, in case of failure, run the program that sends the email.
Another approach, if you are monitoring a specific program, would be to monitor an element other than the mouse. If the macro goes through multiple screens, you could check the title of the current window with the windows API. Another possibility would be to capture the window image at regular intervals and check if anything has changed.
Ultimately, you can replicate the same logic that the macro uses to wait for the system to check whether or not it is waiting indefinitely.
However, if the macro is "dumb" in the sense that it has no checks, just goes acting in defined time intervals, you can think of another solution.
There is a tool called Sikuli which allows automation using images. For example, you capture the image from a button and then build a script to click that button through the image. Sikuli will look for the image of the button on the screen and can wait a while until that button appears. If the expected button does not appear, then you can capture the error. Sikuli implementations can be made in java or Python.
Updating
I did a search on the Apis related to the mouse cursor position. The mouse position is usually given relative to the current monitor, as Windows supports multiple screens. So when you disconnect all monitors the cursor can be disabled.
I assume you’re currently using the GetCursorPos
. If so, try to check the GetCursorInfo
, because it returns useful information about the cursor state and also about its position.
However, it seems that this information is not accessible by project decision. See this link, that says something like that:
You cannot get this information with the desktop locked. While it is locked, the security subsystem between takes over and your desktop is out of bounds.
Have you ever thought of, instead of capturing the mouse position, leaving a signal somewhere? Or incrementing a counter with each iteration of your loop... If you do this with a service, you can access the service remotely to see if your application is active.
– Oralista de Sistemas
The problem is that each loop of the macro can have an indefinite time, a loop can have time from 5 minutes to 20, everything depends on the particular case.
– MDomingues
You can increment a counter in the service and in a client program make a request every five minutes (or other arbitrary interval). Think outside the box ;)
– Oralista de Sistemas
Why don’t you open a
thread
in the same macro program and checks the state of the mouse (or itself) through thatthread
?– Felipe Avelar
@Felipe.Velar is not possible to modify the macro, is a system called Automate, I believe that make the system capture the position and send to my system is valid, vlw.
– MDomingues
If user leaves the pc for 5 minutes as this detection?
– Bacco
@Bacco I am not connected to vm, so I would like to develop a system that identifies when the macro is stopped, but it has to be something that does not directly involve the operation of the macro, so an external program that captures the mouse, but from what I saw the system does not consider that the macro is moving the mouse.
– MDomingues
What do you mean by "connected to the VM"? What virtualization program and guest operating system do you use? I say which version of Windows is virtualized?
– Alexandre Marcondes