3

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.

Gabi Barrientos
  • 1,746
  • 3
  • 23
  • 37

2 Answers2

7

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

Kirk Woll
  • 76,112
  • 22
  • 180
  • 195
Raymond Chen
  • 44,448
  • 11
  • 96
  • 135
3

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

Rich Turner
  • 10,800
  • 1
  • 51
  • 68
Piotr Stapp
  • 19,392
  • 11
  • 68
  • 116
  • Thanks, I will try to get this to work. However, maybe I should have provided this information in my post, but I use mono develop on ubuntu. Given the fact that ubuntu does not contain all dll files needed to do this, would this work on linux systems, or is there another way to do this on linux systems? – Gabi Barrientos Apr 06 '13 at 22:11