Mouse coordinates on Screen - c#

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.

Related

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?

Metro-style Appbar in fullscreen WPF program

I am currently working on a desktop C# WPF application where the goal is to make it look and feel like a "real" Windows Store App.
I want to add an appbar that should be shown when the user swipes up from the bottom. To do this in a normal app you just position your finger outside the screen area, and swipe up.
But if I do that in a fullscreen WPF program I don't receive any TouchDown or TouchMove events - probably because the finger is already down when entering the actual screen area.
I have tried with the Manipulation framework also, but same result here. Even when I hook directly into the message queue using WndProc or other hooks I get no events at all.
The funny thing is that I can see the "touch cursor" move around the screen, so at least something in the underlying framework is notified.
Does anyone have an idea how to do this?
p.s. It is not an option for me just to use a windows store app instead, because of hardware connectivity issues ;-)
You will need to keep track of the cursor location coordinates, and see when the cursor (swipe) starts at the edge of the screen and moves in. When that triggers (with whatever trigger you want, distance covered most likely) you can fire up your Appbar.
There was a similar question asked on MSDN:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/d85dcde7-839a-44d3-9f2a-8b47b947576c/swipe-gesture-and-page-change?forum=wpf

How to get text under mouse in any open window

I'm working on a project which is by C# language. I want to produce a Dictionary which is similar to Narcis or Easylingo that able the user to use the mouse and just move the cursor on the WORD in any application then the program detect the word and will find the meaning for that particular word.
My question is How I can detect the word which is under the Mouse Cursor on the screen in any application such as Microsoft office or Web browsers, etc.
I'm looking for any tips and guide or any Codes which can help me.
Your cooperation is highly appreciated.
You will need to fiddle with Win API capture the GDI calls that output text to the screen.
As suggested in this answer on SO,
Usually for GDI controls you can get the position and size of the control, and you can usually get the font info. For example, with static text controls you'd use WM_GETFONT. Then once you have that you can get the position of the mouse relative to the position of the control and use one of the font functions, perhaps something like GetTextExtentPoint32 to figure out what is under the cursor.
So try finding something in that direction.
You could possibly mimic the same features as Spy++ and capture WM_MOUSEMOVE events, pre-filter them and detect whenever the mouse is over a textbox or similar control.
It certainly won't be easy, and will take a lot of work and research!

C# Change Global Mouse Cursor

I have a form with a Transparency-key color, where I'm doing a global mouse hook for the right click.
Until there everything is okay, but since the form is transparent, the mouse cursor is changing according to what is behind the form.
Is there any way to change the global mouse cursor?
Yup, that's how transparency works. Not just to the eye of the user, also to what the mouse sees from its left eye. Has to work that way, major user confusion if it didn't, no option to change it.
The workaround is to show a fake version of the desktop. A screen shot. Just what the ever popular Windows Snipping Tool does. Sample code is in this thread.

Take control of mouse using mouse hooks in VC#

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 :)

Categories

Resources