问题描述
如何在Windows控制台程序中的C ++中获得鼠标单击的位置? (一个变量,该变量在单击时返回鼠标的位置)
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.
推荐答案
您将需要使用 *ConsoleInput
系列方法(窥视,读取等).它们在控制台的输入缓冲区上运行,包括键盘和鼠标事件.总体策略是:
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
和MOUSE_EVENT_RECORD
)
- wait on the console's input buffer handle (
ReadConsoleInput
) - determine the number of waiting events (
lpNumberOfEventsRead
) - handle them as you see fit (i.e.
MOUSE_EVENT
andMOUSE_EVENT_RECORD
)
您必须指出要使用首先,如本MSDN文章中所示.
这篇关于如何在控制台程序中获取鼠标位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!