如何检测鼠标滚轮倾斜? [英] How to detect mouse wheel tilt?

查看:255
本文介绍了如何检测鼠标滚轮倾斜?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要检测轮换鼠标滚轮在.NET /的WinForms,我可以重写 OnMouseWheel 点击可以通过覆盖 onmousedown事件被检测(这仅仅是中东按钮)。但我怎么发现的倾斜轮(倾斜的左/右横向滚动)?无论是 OnMouseWheel ,不是 onmousedown事件被调用时,我倾斜的鼠标滚轮。

解决方案

覆盖的此处;总之,你需要手动处理窗口消息(它是直接在.NET中没有处理 - code是链接的文章):

 保护覆盖无效的WndProc(参考消息M)
    {
        base.WndProc(REF米);
        如果(m.HWnd!= this.Handle)
        {
            返回;
        }
        开关(m.Msg)
        {
            案例Win32Messages.WM_MOUSEHWHEEL:
                FireMouseHWheel(m.WParam,m.LParam);
                m.Result =(IntPtr的)1;
                打破;
            默认:
                打破;
        }
    }
    ...
    抽象类Win32Messages
    {
        公共const int的WM_MOUSEHWHEEL = 0x020E;通过间谍//发现++
    }
 

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++
    }

这篇关于如何检测鼠标滚轮倾斜?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆