Jump to content
  • Advertisement


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


Mouse wrapping

This topic is 5621 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:



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])

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])

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


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

Sleep 1

End Sub

Private Sub Form_Load()

bRunning = True

End Sub

Private Sub Form_Unload(Cancel As Integer)

bRunning = False

End Sub

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!