How to know if the mouse is in idle state
Hi Specialist:
In the app below, when the app is triggered, the figure is imported. But then the mouse is placed in any place of this window. How to set an idle event to know if it's in idle state. Thank you.
In the app below, when the app is triggered, the figure is imported. But then the mouse is placed in any place of this window. How to set an idle event to know if it's in idle state. Thank you.
Tagged:
0
Answers
It's not clear what are you trying to achieve, can you please provide more details what you are going to do?
The application is in an idle state as soon the function you invoked is completed, e.g. the app is loaded.
Yuri
Thanks for your answer, please let me clarify further. I would like to monitor the mouse event after the processing finished. Within the red frame, the mouse event can be found involving Mycontrol like the figure. However, when the mouse move outside of this red frame, the mouse event can not be monitored.
I would like to monitor the mouse (especially idle state) not only within red frame but also outside red frame. Could you please give some advice? Thank you.
So, you want to detect when the mouse is not moving anywhere on the screen, right? If yes, you can use a timer and periodically check the cursor position and detect when the position is not changing during some period. Similar problem is addresses in this post: https://stackoverflow.com/questions/609965/detecting-when-the-mouse-is-not-moving
Here is how you get cursor position in Image-Pro:
Public Sub PrintMouseCoordinates Dim p As System.Drawing.Point=System.Windows.Forms.Cursor.Position Debug.Print( CStr(p.X) & ", " & CStr(p.Y)) End Sub
YuriThanks for your direction. I tried to combine timer and cursor position. When the timer is triggered, the position can be exhibited, like below, but the effect is not good.
I tried to apply thread as well, but the easiest example program exists issue in AddressOf.
Public Module Module1 Public Sub CountSheep() Dim i As Integer = 1 ' Sheep do not count from 0. Do While (True) ' Endless loop. Debug.Print("Sheep " & i & " Baah") i = i + 1 System.Threading.Thread.Sleep(1000) 'Wait 1 second. Loop End Sub Sub UseThread() Dim t As New System.Threading.Thread(AddressOf CountSheep) t.Start() End Sub End Module
Please give some advice, thank you.The idea is to start timer and monitor the displacement of the cursor between the ticks. I've attached the demo project that contains this code:
When the mouse stops or start moving again, the Output is updated.
Mouse started moving on 14:31:05.9750000
Load the attached project and run StartMouseMonitoring macro.
Let me know if it works for you.
Yuri
Hi YuriG:
I try to make a interactive window like below to prompt user click OK or Cancel. And I hope to add your timer program to continue the program. It means after an idle time, the system will move ahead like the user click the OK. But I found the program seems to wait within the "With" block. Could you please give some advice? Thank you.
Try With Measure.Measurements.ToolsCommands.Select(NewMarco) .Prompt = "Press <Enter> or <OK> for live video camera!" '.Tool = emmtool.Circle .Interactive = True .Run(Nothing) End With Catch 'ACTION FOR CANCEL PRESSED End Try
The interactive prompt can be stopped by assigning IsInteracting property of the command to False. The attached project shows how to do that and provides 3 ways of handling workflow: Ok, Cancel, Time Expired:
Public Module Module1 Private WithEvents _timer As System.Windows.Forms.Timer Private _InteractionCommand As McCommandExtended = Nothing Private _InteractionStopped As Boolean = False Public Sub ShowTimedInteractionPrompt _timer = New System.Windows.Forms.Timer _timer.Interval=5000'wait 5 seconds Dim cm As Object cm=Measure.Measurements.ToolsCommands.Select(Nothing) _InteractionCommand=cm _InteractionStopped=False _timer.Start Try With cm .Prompt = "Press <Enter> or <OK> for live video camera!" '.Tool = emmtool.Circle .Interactive = True .Run(Nothing) End With If _InteractionStopped Then MsgBox("Wait time expired.") Else MsgBox("Ok was hit.") End If Catch MsgBox("Cancel was hit.") Finally End Try End Sub Private Sub _timer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles _timer.Tick _InteractionCommand.IsInteracting=False'stop interaction _InteractionCommand=Nothing _InteractionStopped=True _timer.Stop _timer=Nothing End Sub End Module
Yuri
Just an enquiry if it is possible to change the name of "OK" to "live preview"? Thank you.
You can hide Ok button in Automate.ScriptingCommands.Interaction using InteractionButtons=0. Also, this command has own Timeout property, so no need for own timer:
Using own buttons in interactive prompt is supported, but you have to create own command class and overwrite "ShowInteraction" function, which is not supported on macro level.
It might be easier to create a button in your app with text you want.
Yuri
Thanks for your kind answer. I have considered build an app to do interactive job but the effect is not good as I met some issues, it is better to use the one you recommended before. I will just write some more explanations in the interactive window. Thank you so much for solving this issue.