Capturing mouse wheel events in console application

泄露秘密 提交于 2019-12-02 00:18:16

问题


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:

  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




回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!