如何在控制台程序中获取鼠标位置? [英] How can I get the mouse position in a console program?

查看:481
本文介绍了如何在控制台程序中获取鼠标位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在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:

  1. 等待控制台的输入缓冲区句柄( ReadConsoleInput )
  2. 确定等待事件的数量(lpNumberOfEventsRead)
  3. 按您认为合适的方式处理它们(即MOUSE_EVENT MOUSE_EVENT_RECORD )
  1. wait on the console's input buffer handle (ReadConsoleInput)
  2. determine the number of waiting events (lpNumberOfEventsRead)
  3. handle them as you see fit (i.e. MOUSE_EVENT and MOUSE_EVENT_RECORD)

您必须指出要使用首先,如本MSDN文章中所示.

这篇关于如何在控制台程序中获取鼠标位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆