action on mousemove event

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • metalheadstorm
    New Member
    • Sep 2007
    • 84

    action on mousemove event

    Ok thanks to venna I now have a timer working on my login form which when I go to another form the counter still ticks over.


    Now I've been working on a way of detecting when the mouse has been moved so that I can set a value, say to 1 when it is moved and then the timer gets to 60x5 (5 mins) it sets a value to 1 and then if they're both one then log off / unload / close db etc.

    Here's what I got:

    [CODE=vb]
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Type POINTAPI
    X As Long
    Y As Long
    End Type
    Dim DeltaX As Integer
    Dim DeltaY As Integer
    Dim StartPos As POINTAPI
    Dim logintime As Variant
    [/CODE]


    On form_load

    [CODE=vb]' these should be set when the screen saver is in setup mode
    DeltaX = 100 ' adjust this for x sensitivity level
    DeltaY = 100 ' adjust this for y sensitivity level
    Call GetCursorPos(St artPos)[/CODE]

    Then in each frame or tab

    [CODE=vb]Private Sub SSTab1_MouseMov e(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim NewPos As POINTAPI
    Call GetCursorPos(Ne wPos)
    Dim CheckX As Integer
    Dim CheckY As Integer
    CheckX = Abs(NewPos.X - StartPos.X)
    CheckY = Abs(NewPos.Y - StartPos.Y)
    If CheckX > DeltaX Or CheckY > DeltaY Then
    MouseMove = 1
    End If[/CODE]

    This is really annoying having to put it in each frame and form etc

    Is there a way of just dragging a frame all over your form ... making it see-though and then putting that code in for just that frame?
    Last edited by Killer42; Oct 14 '07, 08:40 AM.
  • metalheadstorm
    New Member
    • Sep 2007
    • 84

    #2
    anyone out there ? i come in peace :)

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Originally posted by metalheadstorm
      anyone out there ? i come in peace :)
      Is there another approach you could take? For instance, since you're doing an API call to check the cursor position, I guess it really isn't dependent on any particular control, or even your form. So what if you had a timer which checks it... oh, say ten times a second, and just sets a flag when it changes or something?

      Comment

      • QVeen72
        Recognized Expert Top Contributor
        • Oct 2006
        • 1445

        #4
        Hi,

        If this is what you want to do : If your Application is running but Idle for few mins, then you want to come out..

        Then do this :
        Keep a project-level variable (add a .Bas module ) and declare this

        Public MyCount As Integer

        And in MouseMove event and KeyPress event of all the Forms give :

        MyCount = 0

        In Main form's Timer1_Timer Event:
        MyCount = MyCount + 1
        If MyCount >= 300 Then
        End
        End If


        Sorry if I have not understood properly.

        Regards
        Veena
        Last edited by Killer42; Oct 17 '07, 09:28 PM.

        Comment

        • metalheadstorm
          New Member
          • Sep 2007
          • 84

          #5
          the problem with what i have atm is that i have to have that code in every frame.

          I have a form with a sstab on it consisisting of 8 tabs ( 8th isnt used atm but will) in each tab ther is a number of frames generally 2-4

          so would i have to put that code in each tab and each frame on each tab or can i just put it under the whole forms mouse event ?

          ------------------------------------------

          I see what u meen veena

          if that works then it would be much much simpler, ill give it a go now :D

          thx both for your replies.

          Comment

          • cugone
            New Member
            • Sep 2007
            • 20

            #6
            Instead of using a mouseMove event, it would be easier to check if the user is actually using the form. You will already have the code in place for what each control is supposed to do, just reset the timer inside each of those subroutines.

            Better yet, write one function/subroutine that resets anything to do with the timer and re-use it that way. That's one aspect of programming: code reuse. :>

            Comment

            • metalheadstorm
              New Member
              • Sep 2007
              • 84

              #7
              Originally posted by cugone
              Instead of using a mouseMove event, it would be easier to check if the user is actually using the form. You will already have the code in place for what each control is supposed to do, just reset the timer inside each of those subroutines.

              Better yet, write one function/subroutine that resets anything to do with the timer and re-use it that way. That's one aspect of programming: code reuse. :>
              so in every text box, command button, etc i would have to do something like

              call mousemoved

              Private Sub mousemoved()
              mousetimer = 0

              or just "mousetimer = 0"
              ------------------------

              I tried out

              MouseMove event and KeyPress event of all the Forms give :

              mousetimer = 0
              this didnt work for the sstabs so i put it in the sstabs mousemove event but if the mouse is over a frame or picture etc it doesnt work.
              So ill have to put it in every frame, picture, etc? ( like i said above? )

              ther must be a simpler way than this long winded putting code in every frame, picture and that cant it be done in a module or something ?

              Comment

              • Killer42
                Recognized Expert Expert
                • Oct 2006
                • 8429

                #8
                Perhaps there's some way you could intercept the mouse-move messages that Windows sends to your application? I know Windows works by sending a constant stream of message around, and you can send them with the SendMessage API function. Maybe you can detect them as well.

                Otherwise, have you considered the timer/API solution I mentioned? Do you just need to know whether the user is doing anything? Or does it need to be specific to your application?

                Comment

                • metalheadstorm
                  New Member
                  • Sep 2007
                  • 84

                  #9
                  i dont care what the user is doing :D just that s/hes there, which is generally known when they move their mouse.

                  Comment

                  • Killer42
                    Recognized Expert Expert
                    • Oct 2006
                    • 8429

                    #10
                    Well, there you go then. Just check the actual mousepointer position every however-often, and if it changes, the user is active. Don't know how you'll tell when they use the keyboard, though, unless they are definitely using your application. In that case, turn on KeyPreview property of each form, so it gets to see the keys first.

                    Comment

                    • metalheadstorm
                      New Member
                      • Sep 2007
                      • 84

                      #11
                      Originally posted by Killer42
                      Well, there you go then. Just check the actual mousepointer position every however-often, and if it changes,
                      Yes as i said above then i have to put that code in evey frame / tab / form / picture ... ther must be a simpler way :S

                      Comment

                      • Killer42
                        Recognized Expert Expert
                        • Oct 2006
                        • 8429

                        #12
                        Originally posted by metalheadstorm
                        Yes as i said above then i have to put that code in evey frame / tab / form / picture ...
                        No, I don't mean to receive MouseMove events. I mean just have a timer somewhere which uses the API call periodically to ask Windows for the absolute position of the mousepointer. Then it won't matter which form has the focus, or even whether your application is visible, or anything.

                        Comment

                        Working...