Event for moving cursor on screen (1 Viewer)

JohnPapa

Registered User.
Local time
Today, 05:54
Joined
Aug 15, 2010
Messages
954
I have a form with a timer and I would like to disable the timer when the user moves the cursor on the screen.

I tried form.mousemove. Does not trigger the event on any mouse move.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 10:54
Joined
May 7, 2009
Messages
19,247
well, you will need to put it on all the controls mousemove event.
but how will you re-Enable the timer when there is no mouse movement?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 10:54
Joined
May 7, 2009
Messages
19,247
see this demo.
what you need to do is when there is "mouse movement", quickly Exit your timer event
instead of "doing any processing inside it".
 

Attachments

  • detectMouseMovement.accdb
    588 KB · Views: 86

JohnPapa

Registered User.
Local time
Today, 05:54
Joined
Aug 15, 2010
Messages
954
Many thanks arnelgp. Let me repeat the problem and suggest a solution based on your suggestion.

The problem is created when a user enters an appointment in his appointment form and this appointment is not visible in the appointment form of the other users. The simple solution is to refresh the appointment form every few minutes (can be user definable), but it would not be a good idea to refresh the form when the user is doing work on the form.

Let's say that I want to refresh every 5 minutes, assuming the user is not doing any work on the form. One solution which I thought of is to use arnelgp code above to check for movement every say 5 seconds and have a counter for every 5 seconds that has elapsed without movement. If this counter reaches 100 (the number of 5 second intervals in 5 minutes) than I do the form refresh and set the counter to 0.

I would modify arnelgp's code so that once the movement is detected the TimerInterval is set to something very small such as 100 so that the Stationary code is executed immediately and at this point the TimerInterval is set again to 5 seconds. In other words, no need to wait for 5 seconds when movement has been detected. I include below what I mean,

Code:
If (cur_point.x <> last_point.x) Or (cur_point.y <> last_point.y) Then
            With lblMoving
                .Caption = "Moving"
                .ForeColor = 1643706
                Me.TimerInterval = 101  '*** Added code
            End With
        Else
        
            With lblMoving
            If Me.TimerInterval = 101 Then   '*** Added code
                Me.TimerInterval = 5000         '*** Added code
            End If                                           '*** Added code
                .Caption = "Stationary"
                .ForeColor = 2316088
            End With
            
        End If

Also, you are correct about resetting the Timer on exit of specific form and enabling it when the user returns.
 

JohnPapa

Registered User.
Local time
Today, 05:54
Joined
Aug 15, 2010
Messages
954
Many thanks arnelgp. Let me repeat the problem and suggest a solution based on your suggestion.

The problem is created when a user enters an appointment in his appointment form and this appointment is not visible in the appointment form of the other users. The simple solution is to refresh the appointment form every few minutes (can be user definable), but it would not be a good idea to refresh the form when the user is doing work on the form.

Let's say that I want to refresh every 5 minutes, assuming the user is not doing any work on the form. One solution which I thought of is to use arnelgp code above to check for movement every say 5 seconds and have a counter for every 5 seconds that has elapsed without movement. If this counter reaches 100 (the number of 5 second intervals in 5 minutes) than I do the form refresh and set the counter to 0.

I would modify arnelgp's code so that once the movement is detected the TimerInterval is set to something very small such as 100 so that the Stationary code is executed immediately and at this point the TimerInterval is set again to 5 seconds. In other words, no need to wait for 5 seconds when movement has been detected. I include below what I mean,

Code:
If (cur_point.x <> last_point.x) Or (cur_point.y <> last_point.y) Then
            With lblMoving
                .Caption = "Moving"
                .ForeColor = 1643706
                Me.TimerInterval = 101  '*** Added code
            End With
        Else
       
            With lblMoving
            If Me.TimerInterval = 101 Then   '*** Added code
                Me.TimerInterval = 5000         '*** Added code
            End If                                           '*** Added code
                .Caption = "Stationary"
                .ForeColor = 2316088
            End With
           
        End If

Also, you are correct about resetting the Timer on exit of specific form and enabling it when the user returns.
Also, the refresh should be disabled when there is a dirty record.
 

Users who are viewing this thread

Top Bottom