Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15079

Mouse move API problem.

$
0
0
A long time ago, I created a small program to move the mouse pointer at fixed intervals of time. The goal was to move the pointer just slightly to prevent a screen saver from loading or an auto-monitor power-off. It would move the pointer from its current position to one pixel to the left, and then back again regardless of the pointers position on the screen. My problem, I lost the code when I accidentally initiated a format of an external hard drive I used for storage. Close to 600MB of anything and everything, gone. I felt really bad.

So, below is my attempt to recreate the program. The public declarations are in a module, and the rest in a form. The only purpose of a small form is to unload the program. What I have does not work. It puts the pointer in the far upper-left corner of the screen on each iteration no matter how far I move it away. The timer interval is one second for testing. Once working, I planned to set the interval much longer. If anyone could take a look and tell me what I am doing wrong, I would appreciate it.

Code:

Option Explicit

Public Const MOUSEEVENTF_MOVE = &H1

Public Declare Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy _
    As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Declare Function SetCursorPos Lib "user32.dll" (ByVal x As Long, ByVal y As Long) As Long

===============================

Option Explicit

Dim C As Integer
Dim A As Long
Dim B As Long

Sub MoveMouse(x As Single, y As Single)

Dim RetVal As Long

mouse_event MOUSEEVENTF_MOVE, 0, 0, x, y
RetVal = SetCursorPos(x, y)
   
End Sub

Private Sub Form_Load()

Me.Top = 100
Me.Left = 100

End Sub

Private Sub tmrMov_Timer()

C = C + 1
If C Mod 2 = 0 Then
    MoveMouse 1, 0
Else
    MoveMouse -1, 0
End If

If C >= 2 Then C = 0

End Sub


Viewing all articles
Browse latest Browse all 15079

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>