简体   繁体   中英

How to detect mouse wheel tilt?

To detect rotation of the mouse wheel in .NET/WinForms, I can override OnMouseWheel . Clicking can be detected by overriding OnMouseDown (it's just the Middle button). But how do I detect tilting of the wheel (tilt to the left/right for horizontal scrolling)? Neither OnMouseWheel , not OnMouseDown is being called when I tilt the mouse wheel.

Covered here ; in short, you need to handle the windows message manually (at it isn't handled directly in .NET - code is from the linked article):

  protected override void WndProc(ref Message m) { base.WndProc(ref m); if (m.HWnd != this.Handle) { return; } switch (m.Msg) { case Win32Messages.WM_MOUSEHWHEEL: FireMouseHWheel(m.WParam, m.LParam); m.Result = (IntPtr)1; break; default: break; } } ... abstract class Win32Messages { public const int WM_MOUSEHWHEEL = 0x020E;//discovered via Spy++ } 

根据这篇文章 ,如果您有IntelliPoint驱动程序,您将获得WM_MOUSEHWHEEL消息。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM