How can I get the mouse click position in C++ in a Windows console program? (A variable that returns the position of the mouse when clicked)
I want to draw a menu with simple text commands, so when someone clicks, the game will register it and know the position. I know how to do everything I need to do except get the mouse position when clicked.
GetConsoleScreenBufferInfo retrieves information about the specified console screen buffer in a
CONSOLE_SCREEN_BUFFER_INFO
structure. ThedwCursorPosition
member gives you theX
andY
positions.Use the consoles own event handler for keyboard and mouse -
ReadConsoleInput( )
.ead more here https://msdn.microsoft.com/en-us/library/windows/desktop/ms685035(v=vs.85).aspx
You'll need to use the
*ConsoleInput
family of methods (peek, read, etc). These operate on the console's input buffer, which includes keyboard and mouse events. The general strategy is:ReadConsoleInput
)lpNumberOfEventsRead
)MOUSE_EVENT
andMOUSE_EVENT_RECORD
)You'll have to indicate that you want to retrieve mouse input using
SetConsoleMode
first though, as illustrated in this MSDN article.