473,657 Members | 2,453 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 2318
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

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

Similar topics

3
7431
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 written some code that causes mouseover effects on a picture box. The code works fine most of the time and creates some really nice effects.
0
2009
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 did was: In an empty form, I set the Form1.Text to "0" and added the following code for Form1.MouseMove event.
3
5661
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 spurious MouseMove events when the cursor doesn't actually move. I've looked for a solution in the groups, and although I've come close, I haven't found a proper explanation or fix. Here is a rundown, followed by a very simple test app that...
3
5154
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 below) as one would expect from a screen saver. Well my Click event fires but for some reason my MouseMove event does not. Both the Form and the PictureBox are enabled. In my Form_Load routine, I tried placing "Me.Capture = true" which...
6
7259
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 moved over the form. Normally I would use the MouseMove event to know when the mouse moves over the form and use that to reset the timer. However, this fails on a form that has a large number of controls of the form. The Form.MouseMove event...
2
4764
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 positioned (either absolutely or relatively) in a way that they overlap each other. when i assign an onmousemove event to them, only one of them catches it. any capturing and/or bubbling is beeing performed by parents of the div that caught the...
4
2016
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 studio but I can't find nothing about the possibility to do it. Can anybody help me? I'm using VB.net 2003 Thank you very very much Maurizio
4
2198
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 sort action always seems to get fired. Any help would be greatly appeciated. The following demo is sortable and resizable. I basically don't want the onclick action to be fired if I am resizing a column. Steve <HTML> <HEAD> <style>
0
8420
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8324
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8842
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8740
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8617
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7353
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 projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
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 presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.