473,783 Members | 2,516 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Giving mouse movement lag

I was wondering if there was a way to give mouse movement on an empty form some lag/delay? For instance, user moves mouse, and the cursor is
20ms (possible adjustable from some option) behind the movement. So when user stops moving mouse, 20ms later the cursor itself stops
moving...
I tried using:
Windows.Forms.C ursor.Current.P osition = New System.Drawing. Point(x,y)
and forms of sleep/timer events but cant seem to get it to work correctly....
Well anyway if anyone knows how to do it, some help would be appreciated.
Oct 26 '08 #1
6 3117
I think making the mouse invisible and then displaying a fake mouse pointer
would be your best bet, since you need to know where the "future" mouse will
be.

--
David Streeter
Synchrotech Software
Sydney Australia
"c.k." wrote:
I was wondering if there was a way to give mouse movement on an empty form some lag/delay? For instance, user moves mouse, and the cursor is
20ms (possible adjustable from some option) behind the movement. So when user stops moving mouse, 20ms later the cursor itself stops
moving...
I tried using:
Windows.Forms.C ursor.Current.P osition = New System.Drawing. Point(x,y)
and forms of sleep/timer events but cant seem to get it to work correctly....
Well anyway if anyone knows how to do it, some help would be appreciated.
Oct 27 '08 #2

http://www.devx.com/vb2themax/Tip/18576

however not in miliseconds but 10 times slower or 10 times faster as default
is possible

HTH

Michel


"c.k." <hr*****@heiaow .peoschreef in bericht
news:rb******** *************** *********@4ax.c om...
>I was wondering if there was a way to give mouse movement on an empty form
some lag/delay? For instance, user moves mouse, and the cursor is
20ms (possible adjustable from some option) behind the movement. So when
user stops moving mouse, 20ms later the cursor itself stops
moving...
I tried using:
Windows.Forms.C ursor.Current.P osition = New System.Drawing. Point(x,y)
and forms of sleep/timer events but cant seem to get it to work
correctly....
Well anyway if anyone knows how to do it, some help would be appreciated.

Oct 27 '08 #3

Thanks for the advice, changing the mouse speed isnt quite what i want, i'd like the speed to be same, just happen x milliseconds later.
Anyway, I wrote some code around the idea of just hiding the mouse pointer (altho in the below code it's commented out), but doesn't seem to
want to work correctly. I'll paste the code here..just open up a big form, and add a radio button with no text (acting as a temp 'fake'
mouse cursor):

Public Class Form1

Dim t As New Timer
Dim iX(0) As Integer
Dim iY(0) As Integer
Dim i1 As Integer = 0
Dim i2 As Integer = 0
Dim tmEvent1(0) As DateTime
Dim tmEventNow As DateTime
Dim tmSpan As TimeSpan
Dim tmEventMisc As DateTime

Private Sub Form1_Click(ByV al sender As Object, _
ByVal e As System.EventArg s) Handles Me.Click
Me.Close()
End Sub

Private Sub Form1_Load(ByVa l sender As Object, _
ByVal e As System.EventArg s) Handles Me.Load
t.Interval = 1
AddHandler t.Tick, AddressOf Me.MoveFakeMous e
t.Start()
End Sub

Private Sub Form1_MouseEnte r(ByVal sender As Object, _
ByVal e As System.EventArg s) Handles Me.MouseEnter
'Cursor.Hide()
End Sub

Private Sub Form1_MouseLeav e(ByVal sender As Object, _
ByVal e As System.EventArg s) Handles Me.MouseLeave
'Cursor.Show()
End Sub

Private Sub Form1_MouseMove (ByVal sender As Object, _
ByVal e As System.Windows. Forms.MouseEven tArgs) Handles Me.MouseMove
ReDim iX(i1)
ReDim iY(i1)
ReDim tmEvent1(i1)
iX(i1) = e.X
iY(i1) = e.Y
tmEvent1(i1) = Now
i1 += 1
End Sub

Private Sub MoveFakeMouse()
Me.Text = CStr(i1) & " " & CStr(i2) & " - X:" & CStr(iX(i2)) & _
" Y:" & CStr(iY(i2))
If i2 >= (tmEvent1.Count - 1) Then Exit Sub
tmEventNow = Now
tmEventMisc = tmEvent1(i2)
tmSpan = tmEventNow.Subt ract(tmEventMis c)

If tmSpan.TotalMil liseconds 20 Then
RadioButton1.To p = iY(i2)
RadioButton1.Le ft = iX(i2)
i2 += 1
End If
End Sub

End Class

The idea is, Form1_MouseMove adds the current mouse coords to an array (iX, iY), and also the current time to a secondary array (tmEvent).
And the timer, every milisecond, triggers MoveFakeMouse() . This sub then checks the time on the tmEvent array with current time and if its
20ms difference, moves the radiobutton using the coords from the associated iX & iY arrays. Then moves on to next array and just keeps doing
that...
But the radiobutton doesn't seem to move, or if it does, it will only move after the mouse has stopped moving and the MoveFakeMouse has
'caught up'. I have a me.text line in there to show it catching up and how the x/y coords dont show up til then.... Anyway, any ideas on why
it's not working, or if i'm completely doing it wrong, another way of doing it... Just looking for a way to delay mouse movement, or have a
fake cursor do exact same movements, just a few moments later....
On Mon, 27 Oct 2008 00:11:00 -0700, SurturZ <su*****@newsgr oup.nospamwrote :
>I think making the mouse invisible and then displaying a fake mouse pointer
would be your best bet, since you need to know where the "future" mouse will
be.
Oct 28 '08 #4
Your REDIM is wiping out the values in the tables before they get processed.
use ReDim Preserve instead.

"c.k." <hr*****@heiaow .peowrote in message
news:nq******** *************** *********@4ax.c om...
>
Thanks for the advice, changing the mouse speed isnt quite what i want,
i'd like the speed to be same, just happen x milliseconds later.
Anyway, I wrote some code around the idea of just hiding the mouse pointer
(altho in the below code it's commented out), but doesn't seem to
want to work correctly. I'll paste the code here..just open up a big form,
and add a radio button with no text (acting as a temp 'fake'
mouse cursor):

Public Class Form1

Dim t As New Timer
Dim iX(0) As Integer
Dim iY(0) As Integer
Dim i1 As Integer = 0
Dim i2 As Integer = 0
Dim tmEvent1(0) As DateTime
Dim tmEventNow As DateTime
Dim tmSpan As TimeSpan
Dim tmEventMisc As DateTime

Private Sub Form1_Click(ByV al sender As Object, _
ByVal e As System.EventArg s) Handles Me.Click
Me.Close()
End Sub

Private Sub Form1_Load(ByVa l sender As Object, _
ByVal e As System.EventArg s) Handles Me.Load
t.Interval = 1
AddHandler t.Tick, AddressOf Me.MoveFakeMous e
t.Start()
End Sub

Private Sub Form1_MouseEnte r(ByVal sender As Object, _
ByVal e As System.EventArg s) Handles Me.MouseEnter
'Cursor.Hide()
End Sub

Private Sub Form1_MouseLeav e(ByVal sender As Object, _
ByVal e As System.EventArg s) Handles Me.MouseLeave
'Cursor.Show()
End Sub

Private Sub Form1_MouseMove (ByVal sender As Object, _
ByVal e As System.Windows. Forms.MouseEven tArgs) Handles Me.MouseMove
ReDim iX(i1)
ReDim iY(i1)
ReDim tmEvent1(i1)
iX(i1) = e.X
iY(i1) = e.Y
tmEvent1(i1) = Now
i1 += 1
End Sub

Private Sub MoveFakeMouse()
Me.Text = CStr(i1) & " " & CStr(i2) & " - X:" & CStr(iX(i2)) & _
" Y:" & CStr(iY(i2))
If i2 >= (tmEvent1.Count - 1) Then Exit Sub
tmEventNow = Now
tmEventMisc = tmEvent1(i2)
tmSpan = tmEventNow.Subt ract(tmEventMis c)

If tmSpan.TotalMil liseconds 20 Then
RadioButton1.To p = iY(i2)
RadioButton1.Le ft = iX(i2)
i2 += 1
End If
End Sub

End Class

The idea is, Form1_MouseMove adds the current mouse coords to an array
(iX, iY), and also the current time to a secondary array (tmEvent).
And the timer, every milisecond, triggers MoveFakeMouse() . This sub then
checks the time on the tmEvent array with current time and if its
20ms difference, moves the radiobutton using the coords from the
associated iX & iY arrays. Then moves on to next array and just keeps
doing
that...
But the radiobutton doesn't seem to move, or if it does, it will only move
after the mouse has stopped moving and the MoveFakeMouse has
'caught up'. I have a me.text line in there to show it catching up and how
the x/y coords dont show up til then.... Anyway, any ideas on why
it's not working, or if i'm completely doing it wrong, another way of
doing it... Just looking for a way to delay mouse movement, or have a
fake cursor do exact same movements, just a few moments later....
On Mon, 27 Oct 2008 00:11:00 -0700, SurturZ <su*****@newsgr oup.nospam>
wrote:
>>I think making the mouse invisible and then displaying a fake mouse
pointer
would be your best bet, since you need to know where the "future" mouse
will
be.
Oct 28 '08 #5

Oh wow...not sure how I missed that. Thanks!
On Tue, 28 Oct 2008 15:35:42 +1100, "James Hahn" <jh***@yahoo.co mwrote:
>Your REDIM is wiping out the values in the tables before they get processed.
use ReDim Preserve instead.

"c.k." <hr*****@heiaow .peowrote in message
news:nq******* *************** **********@4ax. com...
>>
Thanks for the advice, changing the mouse speed isnt quite what i want,
i'd like the speed to be same, just happen x milliseconds later.
Anyway, I wrote some code around the idea of just hiding the mouse pointer
(altho in the below code it's commented out), but doesn't seem to
want to work correctly. I'll paste the code here..just open up a big form,
and add a radio button with no text (acting as a temp 'fake'
mouse cursor):

Public Class Form1

Dim t As New Timer
Dim iX(0) As Integer
Dim iY(0) As Integer
Dim i1 As Integer = 0
Dim i2 As Integer = 0
Dim tmEvent1(0) As DateTime
Dim tmEventNow As DateTime
Dim tmSpan As TimeSpan
Dim tmEventMisc As DateTime

Private Sub Form1_Click(ByV al sender As Object, _
ByVal e As System.EventArg s) Handles Me.Click
Me.Close()
End Sub

Private Sub Form1_Load(ByVa l sender As Object, _
ByVal e As System.EventArg s) Handles Me.Load
t.Interval = 1
AddHandler t.Tick, AddressOf Me.MoveFakeMous e
t.Start()
End Sub

Private Sub Form1_MouseEnte r(ByVal sender As Object, _
ByVal e As System.EventArg s) Handles Me.MouseEnter
'Cursor.Hide()
End Sub

Private Sub Form1_MouseLeav e(ByVal sender As Object, _
ByVal e As System.EventArg s) Handles Me.MouseLeave
'Cursor.Show()
End Sub

Private Sub Form1_MouseMove (ByVal sender As Object, _
ByVal e As System.Windows. Forms.MouseEven tArgs) Handles Me.MouseMove
ReDim iX(i1)
ReDim iY(i1)
ReDim tmEvent1(i1)
iX(i1) = e.X
iY(i1) = e.Y
tmEvent1(i1) = Now
i1 += 1
End Sub

Private Sub MoveFakeMouse()
Me.Text = CStr(i1) & " " & CStr(i2) & " - X:" & CStr(iX(i2)) & _
" Y:" & CStr(iY(i2))
If i2 >= (tmEvent1.Count - 1) Then Exit Sub
tmEventNow = Now
tmEventMisc = tmEvent1(i2)
tmSpan = tmEventNow.Subt ract(tmEventMis c)

If tmSpan.TotalMil liseconds 20 Then
RadioButton1.To p = iY(i2)
RadioButton1.Le ft = iX(i2)
i2 += 1
End If
End Sub

End Class

The idea is, Form1_MouseMove adds the current mouse coords to an array
(iX, iY), and also the current time to a secondary array (tmEvent).
And the timer, every milisecond, triggers MoveFakeMouse() . This sub then
checks the time on the tmEvent array with current time and if its
20ms difference, moves the radiobutton using the coords from the
associated iX & iY arrays. Then moves on to next array and just keeps
doing
that...
But the radiobutton doesn't seem to move, or if it does, it will only move
after the mouse has stopped moving and the MoveFakeMouse has
'caught up'. I have a me.text line in there to show it catching up and how
the x/y coords dont show up til then.... Anyway, any ideas on why
it's not working, or if i'm completely doing it wrong, another way of
doing it... Just looking for a way to delay mouse movement, or have a
fake cursor do exact same movements, just a few moments later....
On Mon, 27 Oct 2008 00:11:00 -0700, SurturZ <su*****@newsgr oup.nospam>
wrote:
>>>I think making the mouse invisible and then displaying a fake mouse
pointer
would be your best bet, since you need to know where the "future" mouse
will
be.
Oct 28 '08 #6
Thanks for letting us know the information was useful.

You are aware, I presume, that your real code will need to use a
System.Collecti ons.Queue instead of an array (which will make the redim
unnecessary).

"c.k." <hr*****@heiaow .peowrote in message
news:id******** *************** *********@4ax.c om...
>
Oh wow...not sure how I missed that. Thanks!

Oct 30 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
32655
by: BadOmen | last post by:
I want my program to send a mouse click to the window at the current mouse position, how do I do that? Example: I have my mouse over a button in Word and then my program is sending the left mouse click and the button under the mouse is clicked. Yours, Jonas
10
18084
by: Danny | last post by:
How can I get the coordinates of the mouse cursor in Mozilla browsers as well as Opera and IE6? I'm struggling to understand how to capture mouse movement events with Mozilla/Netscape/Firefox and I've Googled so much my brain hurts. http://www.ghpkendal.co.uk/TestPages/Test.htm Move your cursor over the yellow area and you should see the mouse coordinates echoed above.
3
2241
by: Wapr | last post by:
Hi, How can I limit to movement of the cursor on my form to a specified rectangle? thanks
6
10817
by: Carlos García-Carazo | last post by:
Hello, I am working on a C# application for an industrial machine, using Windows Forms, where the user could look at the screen from a 90 degree rotated position, like he could turn the monitor to leave it standing on its left (or right) side. There are many ways to show a "turned" interface in this case, but the problem is that when he moves the mouse right, in a turned screen the mouse cursor goes down (or up), when he moves it up...
1
19229
by: Benny Raymond | last post by:
In my attempt to make a macro recording program where i can then playback mouse movements i'm running into a big problem: I'm trying to simulate the movement of the mouse to a point on the screen. With my current code the mouse is only moving in the X direction and not in the Y direction (however my debug line is telling me that it's trying to move in the Y as well). I've read everything I could find online, tried some hacky ways of...
4
6977
by: mike | last post by:
I have the opportunity to rescue a project that uses a mouse to sense the relative position of a machine. The hardware is built...just needs to be programmed. Stop snickering!!! I didn't do it...I just gotta fix it. I need to make some calculations on the measurements and VB6 is my language. Yes, the system mouse will corrupt the measurement, but it's an auditing function and that's acceptable.
5
2331
by: hurricane_number_one | last post by:
I am creating a simple server application, that will listen for incoming mouse coordinates and then move the mouse accordingly. So basically it's like a very simple VNC server without and screen display. I have this basic part working. The problem is that response time is really bad. It seems like the server is not receiving the data fast enough to be able to move the mouse so that it appears to be in sync with the movement on the client...
0
2311
by: Studlyami | last post by:
I am trying to find how windows translate the input from a HID device to an actual windows message; specifically, the mouse. I am trying to figure out how when the mouse moves the process windows takes in order to ensure all windows receive the notification that the mouse moved and how windows moves the mouse cursor. What process handles the movement of the mouse cursor and at what point does windows move the mouse cursor vs posting the...
0
9643
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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,...
1
10083
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7494
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
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5379
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
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
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.