Results 1 to 10 of 10

Thread: Mouse Pointer

  1. #1
    Join Date
    Oct 2011
    Posts
    45

    Unanswered: Mouse Pointer

    Is it possible that the mouse pointer will automatically be in a certain place in a database whenever it becomes idle for about 5 seconds? Like, i would always want it to be in a certain button (like the NEXT button) so all i have to do is to click knowing that its always there?? Am i making sense? (=

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Here's a solution:

    a) In the Form Module:
    Code:
    Option Compare Database
    Option Explicit
    
    Private Const c_MaxIddle As Long = 10 ' For 10 seconds iddle time.
    
    Private m_lngIddle As Long
    
    Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
        m_lngIddle = 0
        
    End Sub
    
    Private Sub Form_Activate()
    
        Me.TimerInterval = 1000
        
    End Sub
    
    Private Sub Form_Deactivate()
    
        Me.TimerInterval = 0
        
    End Sub
    
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
        m_lngIddle = 0
        
    End Sub
    
    Private Sub Form_Timer()
    
        m_lngIddle = m_lngIddle + 1
        If m_lngIddle >= c_MaxIddle Then
            SetMousePointer Me.hwnd, 400, 200    ' Not in twips !!!
            m_lngIddle = 0
        End If
        
    End Sub
    b) In an independant module:
    Code:
    Option Compare Database
    Option Explicit
    
    ' Win32 API Declarations.
    '
    Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type
    
    Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
    Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    
    Public Sub SetMousePointer(FHwnd As Long, PosX As Long, PosY As Long)
    
        ' Note: Coordinates (PosX, PosY) are relative
        ' ----  to the upper-left corner of the form.
        '
        Dim Rec As RECT
        
        'Get Left, Right, Top and Bottom of the form.
        '
        GetWindowRect FHwnd, Rec
    
        'Set Cursor position on X-Y (relative to the form area).
        '
        SetCursorPos Rec.Left + PosX, Rec.Top + PosY
        
    End Sub
    Notice however that there are several issues with this technique:

    1. This is against all good practices concerning Windows ergonomy.

    2. The solution is global: it's not limited to Access, which means that if another application gains the focus, this won't prevent the timer from going on running, then from the cursor returning to it's assigned position after the given interval. This is because the Deactivate event will not occur if the focus moves from Access to another application.

    Note: It's possible to determine when the active application moves from Access to another application but this means using API calls to interfere with Windows Messages mechanism, which is complex and can cause all or some parts of Windows crashing if you don't know precisely what you're doing.

    3. You should reset the counter (m_lngIddle = 0) on the MouseMove event and/or stop the timer (Me.TimerInterval = 0) on the GotFocus
    event of every control on the form: beginning to type something in a textbox and suddendly seeing the mouse pointer moving elsewhere can be really annoying.

    4. PosX and PosY are not in inches, centimeters or even twips. You'll have to experiment for translating the coordinates and determine the exact location where the mouse pointer must go. There are API functions to translate the coordinates but I did not bother to use them here.
    Have a nice day!

  3. #3
    Join Date
    Oct 2011
    Posts
    45
    Hi Sinddho. my apology if it took me a while to reply to your post. Thank you so much. Am trying it now. Update you of the outcome. Thank you so much again. (=

  4. #4
    Join Date
    Oct 2011
    Posts
    45
    omg Sinddho, u did it again. I was really amazed..Its so fun learning access especially if you can make it work. I would never get tired of exploring what more could i do with access. Hope ull never get tired of helping us newbies here.Thank you so much.

  5. #5
    Join Date
    Oct 2011
    Posts
    45
    hi Sinddho, i made the mouse pointer automatically be on the Next button but the thing is the action will only be activated everytime i click the Next Button then it will never move again after a few seconds. The thing is, am thinking, if ever the pointer be unintentionally moved out of the Next button, it will never be on the place where it is intended to be. How about if i click anywhere in the database then the pointer will go the next button, would that be possible?
    Last edited by dennis_ian; 11-02-11 at 00:42.

  6. #6
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Normally the mouse pointer returning back where you decided it must go never cease except if you execute:
    Code:
        Me.TimerInterval = 0
    or the form is closed.

    If this is the case, you can reactivate the mechanism by executing:
    Code:
        Me.TimerInterval = 1000
    You have to manually activate/deactivate the system for every control and in every situation, this is one of the reason why it's almost never used. As I wrote:
    Quote Originally Posted by Sinndho View Post
    3. You should reset the counter (m_lngIddle = 0) on the MouseMove event and/or stop the timer (Me.TimerInterval = 0) on the GotFocus
    event of every control on the form...
    Have a nice day!

  7. #7
    Join Date
    Oct 2011
    Posts
    45
    oh i see..i got it Sinddho.Am trying it now.

  8. #8
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    If you have to set the timer on and off in several circumstances (on many control events such as GotFocus, LostFocus, etc.) you can simplify your life by creating a "centralized" procedure in the form module:
    Code:
    Private Function TimerActivate(ByVal Duration As Long)
    
        Duration = Abs(Duration)    
        Me.TimerInterval = Duration
            
    End Function
    In Design view you can now select several controls, open the Event tab of the Properties window and, for activating the timer (e.g. On Lost Focus) type:
    Code:
    =TimerActivate(1000)
    To deactivate the timer (e.g. On Got Focus), type:
    Code:
    =TimerActivate(0)
    That way, you don't need a Sub for every event of every control that must interfere with the mouse cursor mechanism.
    Attached Thumbnails Attached Thumbnails ScreenShot001.jpg  
    Have a nice day!

  9. #9
    Join Date
    Oct 2011
    Posts
    45
    hi Sinddho. Its been a while. sorry for the sooo late reply. Finally got it. Thank u so much for you usual support.(=

  10. #10
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •