How to create multiple Mouse controls which work separately in C#? - c#

I am implementing a program in C# which can "Play" multiple instance of a game at the same time. The actions of the spawned instance is based on my actions. For example, when i click at position X, Y of the main instance, there will be mouse click at the same position in all other spawned instance.
I can do the mouse click, mouse down, mouse up by hooking the mouse event, and simulate the same mouse click on position based on the position of the each game window. However, this approach does not help if it comes to mouse dragging. And it has some setback in performance when i have to loop all my game instances to do a virtual mouse click.
I have found out that it is possible to create multiple mouse using the MultiPoint SDK from Microsoft. However, I could not find any documentation about if it is possible to simulate the multiple mouse click events (other than mine) in C#? If it is then how can i do it?
Thanks

Unless you are manipulating a program you didn't write, I think you might be using the wrong API for the job.
If you need to script multiple actions on multiple windows, you are probably better off running them sequentially. It will be easier to code and debug and you won't have to do anything special. Just script each action sequentially and then execute them.

Related

Handling all windows mouse click events in C#

My Mouse has started to double click on single clicks, and I know this is a somewhat common issue. I am wanting to handle all mouse click events to fix this issue in software. I know "LowLevelMouseProc" has some decent control, but through many Google searches, I just can't seem to find what I need. There are two main functions I need is.
My application to be the first in the "CallNextHookEx" chain (The Main issue).
To be able to deny or force button state changes for on mouse press, and on mouse release.
and I do know about the "Left Mouse Button Fix" program, but it does not handle drags after a phantom click(after Mouse Release it does not allow for Mouse Press)
I would imagine that to filter everything the mouse puts through would take a colossal amount of time to fix a problem that will only get worse.
I know that this isn't a programmer's fix to the problem, but I had a similar trouble. I took an afternoon and fixed my mouse using some instructions I found on the web. I couldn't find the ones I used, but these are great. I would suggest that you have plenty of light and a magnifying glass.
Door number 3 is just buy a new mouse...

Capturing mouse wheel events in console application

Is there a way to capture mouse wheel events in a console application using c#, like you would capture mouse wheel events in GUI / Window applications?
I would like to do this to scroll only a part of the text in the console.
I've searched google for this, but all I can find is mouse wheel events in Window applications.
Call the ReadConsoleInput function. You will receive a MOUSE_WHEELED event when the wheel is rotated on your console.
You can do this with "two" parts:
Create global system hook on mouse wheel event (good example
here)
Second using PInvoke check if your Console is active (you
can find a example here:
Determine if current application is activated (has focus))
You can extend function in 2 to get window RECT check here and
intersect mouse position with window position

to use or not to use ReleaseMouseCapture()?

Using methods that work in code might be fine but not knowing exactly what is going behind the scene is not such a good feeling. Fees like a gap or incomplete job.
I happened to find ReleaseMouseCapture() and have used in a method (OnMouseUp event) since seemed necessary but I noticed using or not using this method doesn't affect the visual part of my application at least
Can you give me some idea when we should be using it?
Thanks.
MSDN says:
When an object captures the mouse, all mouse related events are treated as if the object with mouse capture perform the event, even if the mouse pointer is over another object.
Depending on exactly what you're doing it may or may not makes sense. We would need some more information. But what it boils down to is, the object that captures it will listen and receive for all events from the mouse. This way you can better organize your mouse logic. For example, Dragging an object around a screen would be perfect for this since the object itself would be getting all the mouse events.
But, if you're only using ReleaseCaptureMouse so not sure why you're using it. Are you using CaptureMouse anywhere?
I use it whenever I write code to capture the mouse, and need to release the mouse capture when I'm finished.
A typical example would be dragging/dropping controls. When I begin a drag operation, I sometimes wish to have the application or a control capture the mouse so any movements made with the mouse are sent to the specific application or control, regardless of the mouse's actual position. When the user releases the mouse button, I need to release the mouse capture so the application/control stops receiving mouse events that its not interested in.
You only need to call ReleaseMouseCapture if you have called CaptureMouse, so in your case it doesn't sound like you need it.
Capturing the mouse means that the control receives mouse messages even when the mouse moves outside of the control's bounds. It is used for things like drag & drop where the drop will occur outside of the control.

how to call onmousedown method on windows using c#

i need to perform the action done by using left mouse click when i press W for example:
i want to move the cruse to a folder and then press w so the folder open
i want to move the cruse to a file and press w and drag it and drop when i release w
i tried to use windowsFrom and performing the onKeyPress() and it calls onMouseDown() but of course it means that the onMouseDown() function will be called inside the form and what i need is a system behavior,,,, i am using windows 7 64 on VS2010 but i would like if it is some thing global for all windows
thanks a lot for helping,,,
The first step you'll need to capture Key Down events in an external application is define a global hotkey:
I recommend checking out some of the answers for this question for a global hot-key: Best way to tackle global hotkey processing in c#? or this CodeProject article: A Simple C# Global Low Level Keyboard Hook
Then, as M. Babcock said you'll need to send the mouse-down events. The link he provided in the comment is a good one. I'm repeating it here for completeness.
How to simulate Mouse Click in C#?
If you actually need to send keyboard inputs, you can use InputSimulator which is something I have advocated (and used in the past) and it provides a very flexible (and reliable) wrapper that is capable of simulating keyboard events.
It wraps SendInput under the hood but abstracts away all the PInvoke calls and other complexity.
InputSimulator.SimulateKeyDown(VirtualKeyCode.CTRL);
InputSimulator.SimulateKeyPress(VirtualKeyCode.KEYS_V);
InputSimulator.SimulateKeyUp(VirtualKeyCode.CTRL);
or
InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_C);
Use a boolean flag for the clicking, and set it on both by clicking or pressing your hotkey. For instance, this flag should be declared inside the form, and the events KeyDown and MouseDown set it true, while KeyUp and MouseUp set it false. For all your actions now you use this flag for verifying the click. (Not sure if it would works in Windows app, in XNA it works fine). For using outside the class, just set this flag as a public property.

Using System.Windows.DragDrop.DoDragDrop() with touch events?

I currently develop an application providing the possibility to drag&drop items from one ListBox to an other. This is working perfectly while using a mouse.
However, when trying to do the same with a touch screen (producing genuine touch events) this will not work.
In my logs I see that the TouchDown and Move is actually detected. But the call to System.Windows.DragDrop.DoDragDrop() does not block as it is the case during mouse usage. It immediately returns, so the drag gesture ends right after it started.
I assume that DragDrop.DoDragDrop() is geared for mouse usage only and depends on a MouseButtonDown during the complete process of dragging?!
So, is there an equivalent for using drag&drop with touch events?
Thanks for any hints
OK, sorry.
This is one of these questions which you are able to answer yourself... after some time.
And it even was not related to drag&drop itself.
Just this much:
Drag&Drop was working fine with touch. However, WPF swallowed an exception which occurred while determining a visual for dragging within an adorner. This logic had to be adjusted for touch events...

Categories