Take control of mouse using mouse hooks in VC# - c#

is there any way to take control of all the mouse events entirely using mouse hooks? I'm developing an application (VC# exe that is) and I've to fulfill the following requirement: Whenever the application is active, it has to display a virtual cursor instead of the windows cursor and when the user tries to move the mouse, the mouse events have to be transferred to this virtual cursor instead of the windows cursor. So, lets say when the user moves the mouse, the virtual cursor should move instead of the windows cursor.
I've tried to implement this by giving WH_MOUSE as the hook id in SetWindowsHookEx() call, but the problem is that along with the virtual cursor, the windows cursor is moving too.
Is there a way to fulfill my requirement? Any input will be greatly appreciated. Thanks in advance.

Have you tried using BlockInput?
P.S: use it with care :)

Related

C# Prevent mouse over effects in other applications

I'm writing a screen shot app where I need to prevent the mouse over effect in all windows. For example, when hovering over a button or hyperlink they will often change color as a form of feedback. My goal is to take a screen shot where the user clicks without the additional feedback.
I can see two approaches:
Disable / ignore the system cursor and create my own. Allow it to fly around the screen without triggering any hover effects. Send a mouse_event when the user clicks using winuser.h
Use a semi-transparent topmost WPF window that allows clicks pass through to other windows. THis answer feels close, but does trigger hover over effects in other windows.
Option 1 is feasible, but I would need to also account for right clicking and scroll wheel.
Option 2 would be best if I could pass through the click event and not the mouse movement. Is this possible in WPF or should I roll my own cursor controls?
Thanks!

Faking A Keyboard or Mouse Event

I've been trying to figure out how to fake, not simulate, keyboard and mouse input. By this I mean the system goes through the process as if the actual event occurred, such as a mouse click, but does not actually perform the event, such as clicking the mouse.
Or if you wanted to make the system think your mouse had moved even though it did not. Sort of a "virtual" move that doesn't actually happen/effect the mouse.
Is it possible to override the simulated mouse clicks and events to make them not actually click while the system thinks they have?
Here is a nice project that wraps the keyboard and mouse. Here is the mouse input simulator file for reference. To see the lower level work, navigate to the WindowsInput.Native namespace in that project.
Thanks guys for all of your help. I was finally able to achieve what I wanted via lrb's answer.
I used that library to fake input and in the grand scheme of things I was trying to make a mouse jiggler but not actually effecting the user's mouse in case the application was running while the user was using the mouse. Which is why I wanted to "fake" the mouse rather than move the actual mouse. Thanks again for everything this was amazing.
Icemanind I'm still curious about your idea with subscribing an event rather than having an event handler. This would allow me to induce something like a mouse click without actually clicking correct?

record mouse movements on desktop (not form) in windows application form

I have created a windows application form, it can display the opening window that user opens in real time. And I need to record the mouse movement. However, I could only record the mouse movement on windows form by using Cursor. Is there any way in C# can record the movements on desktop NOT form?
I think there may be 2 ways, but have not found the solutions yet:
find a way to record the mouse movement on the whole screen, so that when users open any kind of window, their mouse movements can be recorded
I'm using handle for foregroundwindow to display the info the opening window, is there any way to use handle to record the mouse movements?
Many many thanks!
You need global Windows hooks. There is a really good tutorial: http://web.archive.org/web/20130912133933/http://www.jarloo.com/recording-keystrokes-and-the-mouse-and-play-them-back-in-c/

Hiding the cursor in Windows CE

I have a fullscreen application running on Windows CE 6.0 which will only be manipulated using the finger or a stylus.
So I don't need the mouse cursor, which I'm hiding using Cursor.Hide().
However, when I use the stylus to manipulate something on the screen, the mouse cursor is printed while the stylus touch the screen.
Is there a way to make the cursor not show when touching the screen?
BTW: the application will be the only thing running, so system-wide solution are possible, but I'd rather keep it inside the application.
For a system-wide solution, in case you can create the OS, you can remove the mouse cursor component from the catalog (SYSGEN_CURSOR).
For a local solution here is a suggestion (never tried it):
You can replace the icon with a blank icon so you won't see any cursor while inside your form. Once you leave the borders of your form you can restore the usual icon.
Read How to use custom cursors. I checked that the Cursor class is available with the CF. There are two other functions needed to be P/Invoked that are available under CE:
GetIconInfo
CreateIconIndirect

Mouse coordinates on Screen

How to track the mouse position on the screen regardless of application.i.e. Whenever the user clicks or select something with mouse in any application, i want to display my own menu at that point itself.
Is there any way to get mouse position on the screen using c#?
To do this, you'd need to P/Invoke to user32.dll and use SetWindowsHookEx().
Have a look here:
SetWindowsHookEx (user32)
How to set a Windows hook in Visual C# .NET
That sounds like a bad idea. I'm sure you could force it with a bit of effort, but what about the other applications that may want to show their own menus when the mouse is clicked?
I have solved this issue, I used Low Level Mouse hooks and Low Level Keyboard hooks to implement the solution.
I am yet to add the Menu part of it.

Categories

Resources