问题
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.
回答1:
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
回答2:
Call the ReadConsoleInput function. You will receive a MOUSE_WHEELED
event when the wheel is rotated on your console.
来源:https://stackoverflow.com/questions/15856386/capturing-mouse-wheel-events-in-console-application