Gabi Barrientos
Gabi Barrientos

Reputation: 1886

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.

Upvotes: 3

Views: 3424

Answers (2)

Piotr Stapp
Piotr Stapp

Reputation: 19820

You can do this with "two" parts:

  1. Create global system hook on mouse wheel event (good example here)

  2. Second using PInvoke check if your Console is active (you can find a example here: Determine if current application is activated (has focus))

  3. You can extend function in 2 to get window RECT check here and intersect mouse position with window position

Upvotes: 3

Raymond Chen
Raymond Chen

Reputation: 45173

Call the ReadConsoleInput function. You will receive a MOUSE_WHEELED event when the wheel is rotated on your console.

Upvotes: 7

Related Questions