Results 1 to 5 of 5

Thread: Mouse Moves in Other Windows

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    1
    Hello,

    I'm very much a newcomer to visual basic. I would imagine that this request is API related, but apologise if it isn't.

    I'm attempting to write an application which includes a time out feature if mouse moves or key presses are not made.

    I'm intending to have an opening screen, which gives the option to open one of three separate applications.

    If there is no activity within the chosen application, for a set period of time, I want it to be closed down and the opening screen shown again. Also, if the user chooses to return to the opening screen to open another application, the current application will close down.

    Thanks,

    Marcus.

  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    This is Really Really Hard, you can't actually do it in VB alone, you have to write Some .dlls in C++ to do the detecting for you. I've never actually done it but if you're saying you're a newbie you might want to try some simpler things first. Unless someone's got some easy to use Hooking dlls you can use.

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    You mean that the mouse movement is the only thing you need to monitor? Then you could use Getcursorpos API to get the mouse position and WindowFromPoint API to detect if the mouse is over one of your foreign applications, you could monitor the movement by using a static variable to compare the last value with current
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516

    Wink For Keyboard and MouseDown:

    Code:
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    
    Private Const ELAPSE = 5 ' Number of minutes before elapsation
    
    Private Sub Form_Load()
    Timer1.Interval = 100
    End Sub
    
    Private Sub Timer1_Timer()
    Static Keyless As Long
    Dim Ctr As Integer
    For i = 0 To 255
         If GetAsyncKeyState(i) And &H8000 Then
              'A key has been pressed
              Ctr = 0
         Else: Ctr = Ctr + 1
         End If
    Next:
    If Ctr = 256 Then
         'No Keys Have been pressed
         Keyless = Keyless + 1
         If Keyless = (10 * 60 * ELAPSE) Then
             'No keys have been pressed for 5 minutes
         End If
    Else:
         Keyless = 0
    End If
    End Sub
    Phew! I've been doing VB for a couple of years and that was quite hard. I would aim for something a little, well, actually a lot less ambitious. Unless, of course, you are a genius who learnt Portugese in under two hours and can predict lightening, in which case feel free to learn C++.
    Courgettes.

  5. #5
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516

    Talking For MouseMove:

    Code:
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    
    Private Type POINTAPI
            x As Long
            y As Long
    End Type
    
    Private Const ELAPSE = 5 ' Number of minutes before elapsation
    
    Private Sub Form_Load()
    Timer1.Interval = 100
    End Sub
    
    Private Sub Timer1_Timer()
    Static ctr As Long, NoMove As Long
    Static PrevPoint As POINTAPI
    Dim NewPoint As POINTAPI
    If ctr = 1 Then
        Call GetCursorPos(NewPoint)
        If NewPoint.x = PrevPoint.x And NewPoint.y = PrevPoint.y Then
            NoMove = NoMove + 1
            If NoMove = (10 * 60 * ELAPSE) Then
                'Mouse hasn't moved for 5 minutes
            End If
        Else:
            NoMove = 0
        End If
        ctr = 0
    End If
    
    Call GetCursorPos(PrevPoint)
    ctr = ctr + 1
    End Sub
    This is the other half of the code, whihc I've just finished. But, how about a Hello World app? I little easier on the poor fingers.
    Courgettes.

Posting Permissions

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



Click Here to Expand Forum to Full Width