Support Forums
Console Coordinates - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Programming with C++ (https://www.supportforums.net/forumdisplay.php?fid=20)
+---- Thread: Console Coordinates (/showthread.php?tid=14751)



Console Coordinates - Scorch - 12-19-2010

Here's a way to get the coordinates in a console window with your mouse.

Code:
#include <windows.h>
#include <iostream>

int main()
{
    HANDLE in;
    HANDLE out;
    COORD Mouse;

    Mouse.X = 30;
    Mouse.Y = 20;

    DWORD EventCount;
    int LoopCount = 0;
    int KeyEvents = 0;
    INPUT_RECORD rec;
    DWORD NumRead;

    in = GetStdHandle(STD_INPUT_HANDLE);
    out = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),13);
    std::cout <<"\nMouse is at  : " << "\n";

    for(;;)
    {
  Sleep(10);

  GetNumberOfConsoleInputEvents(in,&EventCount);
  while (EventCount > 0)
  {
  ReadConsoleInput(in,&rec,1,&NumRead);

    if (rec.EventType == MOUSE_EVENT)
    {

  if (rec.Event.MouseEvent.dwEventFlags == MOUSE_MOVED)
    {
    SetConsoleCursorPosition(out,Mouse);
    std::cout << rec.Event.MouseEvent.dwMousePosition.X << "," <<
    rec.Event.MouseEvent.dwMousePosition.Y << "  " << std::flush;
    }    
  }

    GetNumberOfConsoleInputEvents(in,&EventCount);
  }
    }

    return 0;
}



RE: Console Coordinates - Digital-Punk - 12-21-2010

Allright that is awesome code Im going to play around with this.