Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MouseInApp
#1
As per posts in a few different topics, here's a simple way to determine if a mouse is inside the program window or not.  (This works just for Windows, but you Linux/Mac guys should be able to substitute for whatever the equivalent of the Windows API call of GetCursorPos is.  I just don't know your OS commands good enough to know what to use for it.)


Code: (Select All)
SCREEN _NEWIMAGE(1280, 720, 32)
_MOUSEMOVE 640, 360

DO
    CLS
    IF MouseInApp THEN PRINT "Mouse is in program area!" ELSE PRINT "The mouse has left the building!"
    _LIMIT 30
    _DISPLAY
LOOP UNTIL _KEYDOWN(27)

FUNCTION MouseInApp
    TYPE MIA_point_type: AS LONG x, y: END TYPE
    DECLARE DYNAMIC LIBRARY "user32": FUNCTION GetCursorPos (lpPoint AS MIA_point_type): END DECLARE
    DECLARE LIBRARY: FUNCTION glutGet& (BYVAL what&): END DECLARE
    DIM AS LONG DX, DY
    DIM Dmouse AS MIA_point_type 'Desktop mouse
    result = GetCursorPos(Dmouse)
    DX = Dmouse.x - _SCREENX - glutGet(506): DY = Dmouse.y - _SCREENY - glutGet(506) - glutGet(507)
    IF DX >= 0 AND DX <= _WIDTH AND DY >= 0 AND DY <= _HEIGHT THEN MouseInApp = -1
END FUNCTION
Reply




Users browsing this thread: 1 Guest(s)