473,505 Members | 13,925 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

action on mousemove event

84 New Member
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:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
  3. Private Type POINTAPI
  4.   X As Long
  5.   Y As Long
  6. End Type
  7. Dim DeltaX As Integer
  8. Dim DeltaY As Integer
  9. Dim StartPos As POINTAPI
  10. Dim logintime As Variant
  11.  

On form_load

Expand|Select|Wrap|Line Numbers
  1. ' these should be set when the screen saver is in setup mode
  2. DeltaX = 100 ' adjust this for x sensitivity level
  3. DeltaY = 100 ' adjust this for y sensitivity level
  4. Call GetCursorPos(StartPos)
Then in each frame or tab

Expand|Select|Wrap|Line Numbers
  1. Private Sub SSTab1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  2. Dim NewPos As POINTAPI
  3. Call GetCursorPos(NewPos)
  4. Dim CheckX As Integer
  5. Dim CheckY As Integer
  6. CheckX = Abs(NewPos.X - StartPos.X)
  7. CheckY = Abs(NewPos.Y - StartPos.Y)
  8. If CheckX > DeltaX Or CheckY > DeltaY Then
  9.   MouseMove = 1
  10. End If
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?
Oct 13 '07 #1
11 2309
metalheadstorm
84 New Member
anyone out there ? i come in peace :)
Oct 17 '07 #2
Killer42
8,435 Recognized Expert Expert
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?
Oct 17 '07 #3
QVeen72
1,445 Recognized Expert Top Contributor
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
Oct 17 '07 #4
metalheadstorm
84 New Member
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.
Oct 18 '07 #5
cugone
20 New Member
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. :>
Oct 18 '07 #6
metalheadstorm
84 New Member
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 ?
Oct 18 '07 #7
Killer42
8,435 Recognized Expert Expert
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?
Oct 18 '07 #8
metalheadstorm
84 New Member
i dont care what the user is doing :D just that s/hes there, which is generally known when they move their mouse.
Oct 19 '07 #9
Killer42
8,435 Recognized Expert Expert
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.
Oct 19 '07 #10
metalheadstorm
84 New Member
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
Nov 5 '07 #11
Killer42
8,435 Recognized Expert Expert
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.
Nov 6 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

3
7420
by: Tim Mulholland | last post by:
i posted this a while ago and never got a response, but i'm still having problems, so i thought i'd see if anyone had any sudden realizations this time Thanks in advance! Tim I have...
0
1995
by: Sam Sungshik Kong | last post by:
Hello! If I understand correctly, MouseMove event is triggered when the mouse moves (ie when point changes). I, however, found out that it's triggered even if the mouse is not moving. What I...
3
5653
by: Crucifix | last post by:
Hello, I'm writing a small C# app, and part of what I'm trying to do involves the dragging of PictureBox controls on a form. Unfortunately, MouseMove seems to be behaving very oddly, causing...
3
5145
by: TyBreaker | last post by:
I'm writing a screen saver using Visual Studio 2005 (Basic) and I have a Form which contains a PictureBox. I have two events, Click and MouseMove that I'd like to cause the program to end (see...
6
7226
by: Rob | last post by:
This is a curious problem. It seems like it should be quite easy. Of course a timer is used to determine when form should be closed, but how do you consistently reset the timer when the mouse is...
2
4729
by: Jakub Ɓukomski | last post by:
hi. i've got a problem as follows, to which i can't find a solution to: i've got two divs, which are completely independent of each other (neither is a parent of child of another). they're...
4
2007
by: info | last post by:
Hello everybody, I hope you can help me with my problem. I want to add the mousemove event to a class that doesn't have it (specifically it is the nationalinstruments.ui.xycursor from measurement...
4
2195
by: since | last post by:
How do I in IE prevent the onclick action from being fired when I am done dragging? have tried "window.event.cancelBubble = true", for onmouseup , onmousedown, and onmousemove handlers. The onclick...
0
7213
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
406
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.