Post Reply 
Social Buttons
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Finding the Coordinates in a Console
Author Message
Scorch Offline
Intermediate C++
********

Trade Count: (0)
Posts: 83
Joined: Jan 2011
Reputation: 15
Post: #1
Finding the Coordinates in a Console
Here's a way to get the x and y values of your mouse in a console. It's neat to try, so compile it!

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;
}
01-29-2011 07:29 PM
Find all posts by this user Quote this message in a reply
Hidden Dragon Offline
Amazing
*******

Trade Count: (0)
Posts: 63
Joined: Jan 2011
Reputation: 4
Post: #2
RE: Finding the Coordinates in a Console
Is there any reason you use for(;;) instead of while(true)?
(This post was last modified: 01-29-2011 10:04 PM by Hidden Dragon.)
01-29-2011 10:03 PM
Find all posts by this user Quote this message in a reply
Scorch Offline
Intermediate C++
********

Trade Count: (0)
Posts: 83
Joined: Jan 2011
Reputation: 15
Post: #3
RE: Finding the Coordinates in a Console
It's personal preference. They both should loop forever, so it doesn't matter what you choose.
01-30-2011 06:25 AM
Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: