-3

For example, I want to simulate a mouse click at a specific position in a window, but I don't want my real cursor to move or do anything. Is there a possible solution ?

More specifically, I want to do some mouse operations on a specific window, but without my cursor really doing it, which allows me to do other things normally with my mouse. Only the target window knows itself is being clicked, even when the window is minimized.

I know it's really easy use some code to move my cursor, with SetCursorPos(), pyautogui.moveTo() or something. But I can't do anything then!

The only way I can think of is to use a virtual machine.

Meteonis
  • 9
  • 1
  • Just wondering what I should learn or what documentation I should read. – Meteonis Apr 24 '22 at 06:23
  • It's unclear what you're trying to accomplish here. If you genuinely wish to inject input then [`SendInput`](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendinput) will do. This neither allows you specify the target, nor does it prevent your mouse cursor from moving. If, on the other hand, you wish to automate a UI, then [UI Automation](https://learn.microsoft.com/en-us/windows/win32/winauto/entry-uiauto-win32) is the solution. – IInspectable Apr 24 '22 at 09:28
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Apr 25 '22 at 02:14
  • The update didn't clarify things. Please take the [tour] and read [ask]. – IInspectable Apr 25 '22 at 13:25

1 Answers1

-2

If you want to send inputs to the active window you can do it by following this article.

It uses InputSimulator to send inputs to active windows. It is available as a Nuget package too.

Edit: If you want to send mouse events without moving your own cursor, what you could try is running your target program and the C# automation program inside a virtual machine, that way you can have 2 mouse cursors (one in your main OS, and the other in the automated OS)

Gaspar
  • 17
  • 4
  • If the link goes down, your answer must still be useful – Zach Jensz Apr 25 '22 at 04:10
  • Yes I also thought of ways to use a virtual machine. Just try to find out if there is any other solution. – Meteonis Apr 25 '22 at 11:37
  • @ZachJensz there are more than thousands answers from Gold stack overflow users, which don't get downvoted, that also have hyperlinks. Looking at your answers, it's no different. Also, I'm providing the source package that the article uses, in case the article gets taken down. – Gaspar Apr 25 '22 at 21:26
  • @Gaspar I haven't downvoted you for that reason, only commented. "Always quote the most relevant part of an important link, in case the external resource is unreachable or goes permanently offline." is the guideline I went off here. If any of my answers are of low quality can you please leave a comment under them – Zach Jensz Apr 25 '22 at 22:50
  • InputSimulator uses [`SendInput`](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendinput) internally. That clearly means that *"I don't want my real cursor to move"* cannot be met. – IInspectable Apr 26 '22 at 09:23