MouseY ( )
Parameters
| None. |
Description
|
Returns the vertical position of the mouse pointer. The value is measured inside your display, so 0 is the top edge and GraphicsHeight()-1 is the bottom edge, windowed or full screen. Read it alongside MouseX every frame and you have the pointer position for drawing a custom cursor with DrawImage, for hit-testing menu buttons, or for dragging something around the screen. It is an absolute position, which suits menus and editors. When you want mouse-look for a first-person camera, use MouseYSpeed instead: relative movement carries on working after the pointer reaches the edge of the screen. The position comes from the window's own mouse messages, so it stops updating while the pointer is elsewhere on the desktop and holds the last value it saw. It is a plain screen position and is not shifted by Origin. Gotcha: losing the window focus resets the tracked position to 0, so MouseY reads 0 after an alt-tab until the mouse moves over your window again. MoveMouse updates it at once, so a warped pointer reads back correctly in the same frame. See also: MouseX, MouseZ, MouseYSpeed, MoveMouse, MouseDown, HidePointer. |
Example
; MouseY Example ; -------------- Graphics 640,480,0,2 SetBuffer BackBuffer() ; Hide the Windows pointer - the example draws its own crosshair HidePointer While Not KeyDown(1) Cls ; MouseY returns the pointer's y position on screen, ; from 0 to GraphicsHeight()-1 mx=MouseX() my=MouseY() ; Horizontal range-marker tracks the MouseY position Color 90,90,90 Line 0,my,639,my ; Shooting-range crosshair at the full mouse position Color 255,255,0 Oval mx-10,my-10,20,20,False Line mx-14,my,mx+14,my Line mx,my-14,mx,my+14 Color 255,255,255 Text 0,0,"Move the mouse up and down Esc: exit" Text 0,20,"MouseY() = "+my+" (0 to "+(GraphicsHeight()-1)+")" Flip Wend End
Index