Console App Mouse-Click X Y Coordinate Detection/Comparison

Console App Mouse-Click X Y Coordinate Detection/Comparison

What @Frank Krueger said. Do you really want to do this? Windows Forms is designed to make this much easier.

If you do, you'll need to use PInvoke into the low level Windows API. Try this as a starting point - but be aware that this is considerably more complex than the Windows Forms application would be.

How can I get the mouse position in a console program?

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. 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)

You'll have to indicate that you want to retrieve mouse input using SetConsoleMode first though, as illustrated in this MSDN article.

Console App Mouse-Click X Y Coordinate Detection/Comparison

What @Frank Krueger said. Do you really want to do this? Windows Forms is designed to make this much easier.

If you do, you'll need to use PInvoke into the low level Windows API. Try this as a starting point - but be aware that this is considerably more complex than the Windows Forms application would be.

CodedUi:Mouse click with coordinates

Try giving a position relative to the control that is being clicked, instead of an absolute point,
use this property:

 uitestcontrol.BoundingRectangle

like this:

var btnPosition= someBtn.BoundingRectangle

and then select the position you want to click based on the controls current position.

for example:

Point relativePoint = new Point(btnPosition.X + 40, btnPosition.Y - 40);
Mouse.click(someBtn,relativePoint );


Related Topics



Leave a reply



Submit