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:
- 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
)
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
"Not In" Clause in Linq to Entities
Error: Must Create Dependencysource on Same Thread as the Dependencyobject Even by Using Dispatcher
Using a List as a Data Source for Datagridview
When Is It Ok to Catch an Outofmemoryexception and How to Handle It
Iequalitycomparer for Sequenceequal
Dtd Prohibited in Xml Document Exception
Unlock Windows Programmatically
C# - Making All Derived Classes Call the Base Class Constructor
Testing Equality of Arrays in C#
Edit Specific Element in Xdocument
Why Use Generic Constraints in C#
Impersonate User in Windows Service