Click to See Complete Forum and Search --> : Mouse Moves in Other Windows
m.friday
Jul 28th, 2000, 09:44 AM
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.
Sam Finch
Jul 28th, 2000, 11:23 AM
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.
kedaman
Jul 28th, 2000, 11:57 PM
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
V(ery) Basic
Jul 30th, 2000, 06:32 AM
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++.
V(ery) Basic
Jul 30th, 2000, 06:43 AM
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.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.