在检测到过非焦点窗口鼠标滚轮?

在检测到过非焦点窗口鼠标滚轮?

问题描述:

我的目标是做一个浮动工具栏(它自己的C#应用​​程序),当用户使用滚轮过我,我想更改显示的按钮。听起来容易,应该只是这一个班轮的问题:

My goal is to make a floating toolbar (as its own C# application), and when the user uses the scrollwheel over me I want to change the buttons that are visible. Sounds easy enough, should just be a matter of this one-liner:

MouseWheel += new MouseEventHandler(Form1_MouseWheel);



我遇到的问题是,当我的应用程序具有焦点鼠标滚轮处理程序时才会激活。这意味着用户必须先点击,然后鼠标滚轮。这将不是我想要做的事情。

The problem I am having is that the mouse wheel handler is only invoked when my application has focus. That means the user has to first click, and then mousewheel. That won't do for what I'm trying to do.

我能勾MouseHover事件处理程序,并调用form.Activate(),要获得焦点。这是因为当用户将鼠标悬停在我的应用程序(而不是等待一点点)后立即使用滚轮是不理想的,重点还是会放在前面的应用程序,它会得到鼠标滚轮事件。

I can hook the MouseHover event handler and call form.Activate() then, to get focus. That's suboptimal because if the user uses the scrollwheel immediately after mousing over my application (instead of waiting a little), the focus will still be on the previous app and it'll get the mousewheel event.

一个自然的事情将是挂钩MouseEnter事件并调用激活()有,但随后而不是我的应用程序来前,它的图标开始闪烁任务栏上。我使用的Win7,但这个问题可能比这更旧。

A natural thing to do would be to hook the MouseEnter event and call Activate() there, but then instead of my application coming to the front, its icon starts to blink on the task bar. I'm using Win7, but this problem is probably older than this.

在理想情况下,我想这样做将是检测鼠标滚轮事件,而不必担心什么我的应用程序是否具有焦点。它真的会更好的为以前的应用程序,以保持输入焦点,因此,例如,如果用户在记事本中,他们可以输入,鼠标悬停到我的应用程序,使用滚轮,看看他们所看到的,并决定只恢复在记事本中输入。理想我不想让他们不得不在这种情况下甚至有一次点击。

Ideally, what I'd like to do would be to detect the mousewheel events without having to worry about whether my application has focus. It would really be better for the previous application to keep input focus, so for example if the user's in Notepad they can type, mouse over to my app, use the scroll wheel, look at what they see and decide to just resume typing in Notepad. Ideally I don't want them to have to click even once in this scenario.

我会满足于将焦点切换到我的应用的解决方案,不过,如果有没有别的办法。

I'll settle for a solution that switches focus to my application, though, if there's no other way.

我有什么迄今为止使用C#和Windows Forms,但我很开放使用的东西,如果能解决我的问题有所不同。

What I have so far uses C# and Windows Forms, but I'd be open to using something different if that can solve my problems.

所以:我怎么能看到,而用户不必点击首先关注我的应用程序的鼠标滚轮事件

So: how can I see those mousewheel events without the user having to click to focus my application first?

如果你需要抓住你的应用程序之外的鼠标事件,你可以使用一个全球系统挂钩。有一个很好的.NET实现 rel=\"nofollow\">

If you need to catch mouse events outside your application, you can use a global system hook. There's a good .NET implementation here