Archived

This topic is now archived and is closed to further replies.

Mouse wrapping

This topic is 5403 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve been looking for a while for some simple mouse-wrapping code, but I haven''t been able to find any. If you don''t know what mouse wrapping is, it was a feature in earlier windows system that allowed the mouse to wrap to the other side of the screen if it met one of the edges. Does anyone know how to do this? -------------------------------------------- Yunalesca: MEGA DEATH! Anima: *shrugs off Mega Death* PAIN! Yunalesca: Gahh! You killed me with your EYE! ------------------------------ No matter how wonderful, no matter how intelligent, no matter how beautiful a woman is, somewhere out there, is a man thats tired of her s***.

Share this post


Link to post
Share on other sites
Here''s some half code/half pseudo-code to get you started:



POINT pt;

GetCursorPos(&pt);

if ((pt.x == SCREEN_WIDTH) && [the mouse is moving to the right])
{
pt.x = 0;
}
else if ((pt.x == 0) && [the mouse is moving to the left])
{
pt.x = SCREEN_WIDTH;
}

if ((pt.y == SCREEN_HEIGHT) && [the mouse is moving to down])
{
pt.y = 0;
}
else if ((pt.y == 0) && [the mouse is moving to up])
{
pt.y = SCREEN_HEIGHT;
}

SetCursorPos(pt.x, pt.y);

Share this post


Link to post
Share on other sites
TOoo much code.

Try ... (Pseudo c code)

const int Screen_Width = 640;
const int Screen_Height = 480;

// If its too far right/down, wrap it around.
Cursor.x %= Screen_Width;
Cursor.y %= Screen_Height;

// If its too far left/up, wrap it around
while (Cursor.x < 0)
Cursor.x += Screen_Width;

while (Cursor.y < 0)
Cursor.y += Screen_Height;

Done and done.


[edited by - Kevlar-X on March 1, 2003 10:47:49 PM]

Share this post


Link to post
Share on other sites
With that code, if the user, for example, leaves the cursor on the right side of the screen (x = 639), then each frame the cursor will move back and forth (639 to 0 to 639) etc.

Share this post


Link to post
Share on other sites
I decided to steal your idea and i wrote a quick version in VB

Here''s the code:


Option Explicit

Private Type POINTAPI
x As Long
y As Long
End Type

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long

Dim bRunning As Long

Public Sub MouseLoop()

Dim pMouse As POINTAPI

Do

If Not bRunning Then Exit Do

GetCursorPos pMouse

If pMouse.x >= (Screen.Width / Screen.TwipsPerPixelX) - 1 Then
SetCursorPos 1, pMouse.y
End If

If pMouse.y >= (Screen.Height / Screen.TwipsPerPixelY) - 1 Then
SetCursorPos pMouse.x, 1
End If

If pMouse.x <= 0 Then
SetCursorPos (Screen.Width / Screen.TwipsPerPixelX) - 2, pMouse.y
End If

If pMouse.y <= 0 Then
SetCursorPos pMouse.x, (Screen.Height / Screen.TwipsPerPixelY) - 2
End If

DoEvents
Sleep 1
Loop

End Sub

Private Sub Form_Load()

Me.Show
Me.Refresh
bRunning = True
MouseLoop

End Sub

Private Sub Form_Unload(Cancel As Integer)

bRunning = False

End Sub

Share this post


Link to post
Share on other sites