Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Custom MouseMovement Example
#4
Give this version a test run, if you get a chance.   IF you can't see a cursor with _PUTIMAGE, then maybe it's a color -1 issue?  Or something else odd?

Code: (Select All)
DIM SHARED AS LONG MouseMoveX, MouseMoveY, MouseX, MouseY

SCREEN _NEWIMAGE(800, 600, 32)
_SCREENMOVE _MIDDLE


DO
    CLS
    Mouse
    TMMX = TMMX + MouseMoveX: TMMY = TMMY + MouseMoveY
    PRINT "Mouse x:"; MouseX
    PRINT "Mouse y:"; MouseY
    PRINT "MouseMoveX:"; MouseMoveX
    PRINT "MouseMoveY:"; MouseMoveY
    PRINT "Total MouseMoveX:"; TMMX
    PRINT "TOtal MouseMoveY:"; TMMY
    _LIMIT 30
    _PRINTSTRING (MouseX, MouseY), CHR$(24)
    _DISPLAY
LOOP UNTIL _MOUSEBUTTON(2)
SYSTEM



SUB Mouse
    STATIC AS LONG CurrentX, CurrentY
    STATIC AS INTEGER Init
    WHILE _MOUSEINPUT
        Xjunk = _MOUSEX: Yjunk = _MOUSEY
    WEND 'catch up to the current mouse's position so we sync properly
    X = _MOUSEX: Y = _MOUSEY
    MouseMoveX = 0: MouseMoveY = 0

    IF Init = 0 THEN
        Init = -1
        CurrentX = _WIDTH \ 2: CurrentY = _HEIGHT \ 2
        _MOUSEHIDE
        _MOUSEMOVE _WIDTH \ 2, _HEIGHT \ 2
    ELSE
        IF X <> _WIDTH \ 2 OR Y <> _HEIGHT \ 2 THEN
            MouseMoveX = X - _WIDTH \ 2: MouseMoveY = Y - _HEIGHT \ 2
            CurrentX = CurrentX + MouseMoveX
            CurrentY = CurrentY + MouseMoveY
            IF CurrentX < 0 THEN CurrentX = 0
            IF CurrentX >= _WIDTH THEN CurrentX = _WIDTH - 1
            IF CurrentY < 0 THEN CurrentY = 0
            IF CurrentY >= _HEIGHT THEN CurrentY = _HEIGHT - 1
        END IF
    END IF

    _MOUSEMOVE _WIDTH \ 2, _HEIGHT \ 2
    WHILE _MOUSEINPUT
        Xjunk = _MOUSEX: Yjunk = _MOUSEY
    WEND 'clear the manual reset to the center so we don't read it in the next pass
    MouseX = CurrentX: MouseY = CurrentY
END SUB

Even if the values do something odd (which I don't know why they should), you should still be able to see the arrow on the screen and move it around.  In this case, it's only going to be a text sized character of an arrow (CHR$(24)), so you might need to strain your eyes to find it, but it should definitely be there.

Once a cursor is available and moving, then we can sort out what the heck is going on with the return values.  Work on one thing at a time.  Big Grin
Reply


Messages In This Thread
Custom MouseMovement Example - by SMcNeill - 02-25-2024, 05:37 PM
RE: Custom MouseMovement Example - by NakedApe - 02-26-2024, 01:18 AM
RE: Custom MouseMovement Example - by SMcNeill - 02-26-2024, 03:29 AM
RE: Custom MouseMovement Example - by SMcNeill - 02-26-2024, 03:45 AM
RE: Custom MouseMovement Example - by NakedApe - 02-26-2024, 06:00 AM
RE: Custom MouseMovement Example - by NakedApe - 02-26-2024, 05:35 PM
RE: Custom MouseMovement Example - by SMcNeill - 02-27-2024, 07:15 AM
RE: Custom MouseMovement Example - by GareBear - 02-27-2024, 01:06 PM
RE: Custom MouseMovement Example - by SMcNeill - 02-27-2024, 01:28 PM
RE: Custom MouseMovement Example - by SMcNeill - 02-27-2024, 01:47 PM
RE: Custom MouseMovement Example - by NakedApe - 02-27-2024, 04:59 PM
RE: Custom MouseMovement Example - by SMcNeill - 02-27-2024, 05:06 PM
RE: Custom MouseMovement Example - by MasterGy - 02-27-2024, 05:18 PM
RE: Custom MouseMovement Example - by NakedApe - 02-27-2024, 07:17 PM
RE: Custom MouseMovement Example - by MasterGy - 02-27-2024, 08:53 PM
RE: Custom MouseMovement Example - by SMcNeill - 02-27-2024, 08:58 PM
RE: Custom MouseMovement Example - by MasterGy - 02-27-2024, 09:07 PM
RE: Custom MouseMovement Example - by NakedApe - 02-28-2024, 02:40 AM



Users browsing this thread: 2 Guest(s)