Capturing mouse wheel events in console application - c#

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

Related

How can I listen to mouse events of other processes

Is it possible in C# to listen to mouse related windows messages sent to other windows in other processes?
There is a open source project in codeplex for that
Application and Global Mouse and Keyboard Hooks .Net Libary in C#
If you want to do this yourself do some extra search on Windows Hooks
This article shows how
You can take a look at the Codeplex Application and Global Mouse and Keyboard Hooks library
This library attaches to windows global hooks, tracks keyboard and mouse clicks and movement and raises common .NET events with KeyEventArgs and MouseEventArgs, so you can easily retrieve any information you need:
Mouse coordinates
Mouse buttons clicked
Mouse wheel scrolls
Key presses and releases
Special key states
From above links Documentation:
Before beginning it is important to know that hooking terms can and will be used interchangeably. Global hooks are also known as System, or System-Wide hooks, and will encompass the entire operating system. Application hooks are often called Local, because as the name implies, will only correspond to the single application which placed the hook (or a specific thread).
There is no managed way to do this.
However, with Windows Api this is possible:
This should help you.
C# - Capturing Windows Messages from a specific application
It would be a good start to capture WM_MOUSEMOVE
http://msdn.microsoft.com/en-us/library/windows/desktop/ms645616(v=vs.85).aspx
But there are other mouse related window messages, too.

Control OS Mouse Event using Windows Form - C#

The program I am trying to do is to simulate the mouse event of a operating system using keyboard with Windows Form. Right now I am able to change the cursor and do different actions like mouse clicking inside the Form (when the Form is on the Top).
The problem is I would like to extend it to the whole Operating System, which means even if my Windows Form is not at the top, I am still able to control my cursor and do all sorts of mouse event on other applications while the Form is running. How should I do to implement this ?
You might want to look at this library Global System Hooks in .NET which uses global system hooks to detect all mouse and keyboard events include those outside of your application.
You can synthesize OS-wide keystrokes, mouse motions, and button clicks using the Win32 SendInput() API. You can call it from C# using P/Invoke. Sample code can be found here: SendInput on PInvoke.net.
I remember back in the day I used the SendInput (and a screenshot API) to create a Minesweeper bot in C# (2.0 I think). It could solve an Expert puzzle in about one second. I wish I still had the source code to sample here, but I don't.
EDIT: It appears someone has already created a nice .NET warpper for the SendInput(): Windows Input Simulator on CodePlex.

How to create multiple Mouse controls which work separately in 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.

Emulate keyboard

How can I emulate keyboard in application running in background (hidden in tray).
I want to press, hold, and relase keys on keyboard programatically.
Also, I would like to move mouse around and be able to click.
You can use SendInput API function
You can also try the Windows.Forms.SendKeys API
Here is a How-To: How to: Simulate Mouse and Keyboard Events in Code

Disable Mouse moves and clicks using c# windows application

I want to Enable the Mouse moves and clicks Using c# windows application.
How to do this ?
I don't want to unplug my mouse from my PC. :)
You can use this library to make a mouse hook that can suppress the mouse input.
You can then check GetForegroundWindow() and set e.Handled to true.
Find the GUID of mouse and disable the mouse using c#

Categories