17.3.10 Mouse Events

Mouse events are placed in the input buffer when the console is in mouse mode. This is the default mode when a console is created, but it may be switched on or off by using SetConsoleMode . Changing the mouse mode only affects input that occurs after the mode is set, and pending mouse events in the input buffer are not flushed. The mouse pointer is displayed regardless of the mouse mode.

Mouse events are generated whenever the user moves the mouse or presses or releases one of the mouse buttons. Mouse events are placed in a console's input buffer only when the console group has the keyboard focus. If the mouse pointer is not within the borders of the window, mouse events are not reported.

For mouse events, the Event field of the input record will be a mouse event record with the following fields:

dwMousePosition The coordinates of the mouse relative to the screen buffer. The coordinates are in terms of the row and column character cells of the screen buffer. Note that because the screen buffer may have been scrolled with respect to the window, the upper left corner of the window is not necessarily the 0,0 coordinate of the screen buffer. To determine the coordinates of the mouse relative to the coordinate system of the window, subtract the window origin coordinates from the mouse position coordinates. The window origin coordinates are the Left, Top fields of the srWindow rectangle returned by calling GetConsoleScreenBufferInfo. Refer also to the section below on window size and screen buffer size.
dwButtonState A flag indicating status of mouse buttons. The least significant bit corresponds to the leftmost mouse button. The next least significant bit corresponds to the rightmost mouse button. The next bit indicates the next-to-leftmost mouse button. The bits then correspond left-to-right to the mouse buttons. The number of buttons on the mouse can be determined by calling GetNumberOfConsoleMouseButtons.
dwControlKeyState A flag indicating the state of the control keys (Alt, Ctrl, Shift, Num Lock, Scroll Lock, Caps Lock). Constants defined in WINCON.H can be ANDed with this flag to determine if any of these keys were pressed.
dwEventFlags Constants defined in WINCON.H can be compared with this flag to determine the type of mouse event. MOUSE_MOVED indicates a change in the mouse position. DOUBLE_CLICK indicates a double-click. For button press or release events that are not double-click events, this flag is set to 0.