How to implement mouse click event in a C# project


I am writing my first bot in C# project. (Not a scrip to be used by Scrip Engine). I am stuck at sending mouse click event to Eve Online client. Can you please help here with code examples for mouse and keyboard events? Thanks

I looked into source code of Sanderling and A-bot project and did not find a solution that works. I tried the following, function calls which did not work.


Sanderling.Motor.MotionParamExtension.MouseClick(RouteElementMarkerNext, BotEngine.Motor.MouseButtonIdEnum.Right);

ToScriptExtension.MouseClickRight(null, RouteElementMarkerNext); (Here I could not figure out the HostToScrip object to use)


1 Like

The Sanderling code contains some helper methods to make this very simple.

This should work for the mouse click:

static public MotionResult MouseClick(
	IUIElement uiElementToClick,
	IMemoryMeasurement memoryMeasurement,
	IntPtr eveClientWindowHandle,
	BotEngine.Motor.MouseButtonIdEnum mouseButtonId)
		new WindowMotor(eveClientWindowHandle)

In case you do not have the eve clients WindowHandle yet, you can obtain it with the following code:

var eveClientWindowHandle = System.Diagnostics.Process.GetProcessById(measurement.ProcessId).MainWindowHandle;

Thanks Viir! I will try it out.

Got a question for Viir, in your example it looks like eve window is begin set to receive the click, but in Sanderling, when bot uses the mouse, it is moved/clicked no matter in which window is user currently focused (you can be in desktop and sanderling will make right click, showing desktop right click menu).

Isn’t possible to make clicks on a certain window, without affecting the user mouse?
autohotkey has ControlClick for example. Where you can set which window will receive that click event

And DotNet has UI Automation framework:

You can make clicks without affecting the user mouse. The recommended approach to do this is outlined at Multi instances Support - #2 by Viir

Can you use any of those to send a click to the eve online client without affecting the user mouse? If this was possible it would be interesting to take a closer look.

1 Like

I’ve tested the ControlClick with the following script:

   title = EVE - (Your character name)
   ControlClick, x1680 y232, %title%,, RIGHT, NA
   ControlClick, x1744 y283, %title%,,,, NA

If you have the Overview on the common position, once you press CTRL+M it should attempt to click on the first item and dock.
However it only looks to work when eve window is focused. meh, useless :frowning:

1 Like