How to detect mouse wheel tilt?
Asked Answered
A

2

9

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.

Asserted answered 5/7, 2009 at 8:39 Comment(0)
E
11

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++
    }
Elissa answered 5/7, 2009 at 8:43 Comment(3)
This works fine when your window has a horizontal scrollbar, but not otherwise. Just a note for people (like me 8-) who might want to abuse the tilt buttons for something other than horizontal scrolling.Chery
I'm not getting any messages to my app from tilting the mouse wheel, but other apps are. Any suggestions?Ordain
I've posted this as a new question here - #1093000Ordain
W
3

Based on this article, if you have the IntelliPoint drivers, you will get WM_MOUSEHWHEEL messages.

Wortman answered 5/7, 2009 at 8:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.