Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Detect when mouse leaves program window
#3
I was waiting for Spriggsy to jump in here first because his API knowledge is heaps more than mine.  There's probably a better API way of doing this, but here's a quick way off the top of my head - using the GetCursorPos API. 

- Dav

Code: (Select All)

TYPE POINTAPI
    x AS LONG
    y AS LONG
END TYPE
DIM apixy AS POINTAPI 'mouse x/y for the GetCursorPos function

DECLARE DYNAMIC LIBRARY "user32"
    'get current mouse x/y position
    'http://allapi.mentalis.org/apilist/GetCursorPos.shtml
    FUNCTION GetCursorPos% (lpPoint AS POINTAPI)
END DECLARE


SCREEN 12

DO

    'poll mouse x/y
    tmp = GetCursorPos(apixy)
    ax = apixy.x: ay = apixy.y

    sx = _SCREENX: sy = _SCREENY

    CLS: PRINT "MOUSE IN"
    IF ax - sx < 0 THEN CLS: PRINT "MOUSE OUT"
    IF ax - sx > _WIDTH THEN CLS: PRINT "MOUSE OUT"
    IF ay - sy < 0 THEN CLS: PRINT "MOUSE OUT"
    IF ay - sy > _HEIGHT THEN CLS: PRINT "MOUSE OUT"
    _DISPLAY

LOOP


Find my programs here in Dav's QB64 Corner
Reply


Messages In This Thread
RE: Detect when mouse leaves program window - by Dav - 08-16-2023, 03:22 PM



Users browsing this thread: 2 Guest(s)