如何对WPF中的触摸板滚动做出反应? [英] How to react to touchpad scrolling in WPF?

查看:120
本文介绍了如何对WPF中的触摸板滚动做出反应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

WPF中的MouseWheel事件有点问题。



我有以下代码:

一个自定义控制器

Hello everybody,
I have a little issue with MouseWheel events in WPF.

I have the following code:
One Custom Controller

<UserControl x:Name="customTileController"

             ...

             MouseDown="MainCanvas_Distribute_MouseDown"

             MouseMove="MainCanvas_Distribute_MouseMove"

             MouseUp="MainCanvas_Distribute_MouseUp"

             MouseWheel="customTileController_MouseWheel">



在代码中使用此事件处理程序behin d:


with this event handler in the code behind:

private void customTileController_MouseWheel(object sender, MouseWheelEventArgs e)
       {
           //for upwards scrolling we zoom in
           if (e.Delta > 0)
           {
               IncreaseZoomLevel();
           }
           //for downwards scrolling we zoom out
           else if (e.Delta < 0)
           {
               DecreaseZoomLevel();
           }
       }





此代码运行良好,当我滚动一个传统的鼠标(通过USB连接,但也许没关系)。问题是,当我尝试在我的笔记本触摸板上使用滚动条时,鼠标指针变为滚动指针,但我的应用程序中没有任何反应。触摸板是一个相当旧的笔记本,运行Windows 8.1,它应该通过PS / 2连接。



这个问题是由我的代码引起的,WPF(我(不要想)或者是在Win8.1下运行的旧Synaptics驱动程序吗?



感谢您提前和抱歉因这个小问题打扰您,但我是好奇它是由什么导致的:)。



This code works well, when I'm scrolling with one "traditional" mouse (connected via USB, but perhaps it doesn't matter). The problem is, when I try to use the scrollbar thingy on my notebook touchpad, the mouse pointer changes to the scrolling one, but nothing happens in my application. The touchpad is in one fairly old notebook, running Windows 8.1 and it should be connected via PS/2.

Is this issue caused by my code, by WPF (I don't think) or by the old Synaptics driver running under Win8.1?

Thanks for advance and sorry for disturbing you by this tiny issue, but I'm curious what's it caused by :).

推荐答案

基本上,我的建议是在对问题的评论中讨论。



Basically, my advice is in the discussion in comments to the question.

macika123写道:
macika123 wrote:



最后,它正在工作:D。我很开心。

经过一番研究后,似乎我并不孤单。 Synaptics的虚拟滚动功能在某些应用程序中不起作用,但在我的情况下,水平滚动在Visual Studio中工作(感谢提示深入挖掘触摸板属性,我发现,我实际上可以打开水平滚动)。

当我正在使用Interop监听发送到我的WPF应用程序窗口的消息时,奇怪的是我收到WM_MOUSEWHEEL消息,即使我正在使用虚拟滚动。但是,MouseWheel事件仍然不会触发。幸运的是,wParam的HIWORD部分设置正确(至少在我的目的),所以我可以根据车轮旋转方向逐步放大和缩小。



现在我'我只是想知道,这是由什么引起的?基本上,应用程序获取消息,但不知何故它在.NET中丢失。



感谢您的帮助和安慰,我的代码和错误在其他地方。


Finally, it's working :D . I'm so happy.
After a bit research it seems, that I'm not alone with this problem. Synaptics' virtual scrolling feature is not working in some applications, but in my case the horizontal scrolling is working in Visual Studio (thanks for the tip to dig deeper in touchpad properties, where I found, that I can actually turn horizontal scrolling on).
When I'm listening for messages sent to my WPF application window using Interop, weirdly I receive WM_MOUSEWHEEL messages, even if I'm using virtual scrolling. However, the MouseWheel event still doesn't fire. Fortunately the HIWORD part of wParam is set correctly (at least for my purposes), so I can step zooming in and out based on wheel spin direction.

Now I'm just wondering, that what's this caused by? Basically, the application gets the message, but somehow it's lost in .NET.

Thanks for help and for reassuring, that my code and the error is somewhere else.

不客气。



让我在这里提出一些推测。我希望我们即将解决这个问题,因为我们无法实现进一步的步骤。



根据您的描述,您的代码无需处理鼠标滚轮event(下次,更好地显示将事件处理程序添加到某个事件实例的调用树的位置,即对应的+ =运算符,因为方法名称 customTileController_MouseWheel ,严格说来,并没有告诉它任何事情;另外,从不使用这样的自动生成的名称,它们违反了良好的Microsoft命名约定,出于某些明显的原因)。这不可能是错的。



首先,.NET中可用的所有输入事件都有不同的级别。一些是主要的并且由硬件生成并且通过硬件中断到一个IRQ线并且由硬件驱动器处理,并且一些是次要的。例如,硬件事件产生 KeyDown KeyUp 事件(也是间接),但不是 KeyPress 事件,这是前两个事件的次要事件;它在考虑输入语言的长链之后发挥作用,产生一个在较低级别上不存在的角色。



这不是物理鼠标会发生什么轮。当您滚动它时,硬件会生成与鼠标移动相同级别的事件,即使在鼠标移动光学鼠标时也会发生光学图像识别。无论如何,从计算机的角度来看,这些都是同一级别的事件。滚动的鼠标不能被误解为鼠标移动。



触摸板滚动区域会发生什么?没有那样的事。相反,一些代码只是尝试来模仿与真实鼠标相同的效果。在物理上,主要事件仍然与常规触摸相同。请注意,即使鼠标按钮按下事件也可以是真实(触摸板通常具有物理按钮)或模拟,通过快速触摸并移动。我真的不知道这种模拟发生在哪里,在一些固件或驱动程序中,但我宁愿猜测它发生在驱动程序中,就是它,它是以计算机的CPU为代价的。涉及IA的一些元素:识别触摸。



我们都知道识别可以给你误报和漏报。如果硬件(包括固件)和驱动程序的组合质量有问题,或者某些部分质量不合适,则识别结果可能不充分。不幸的是,我没有解释不同软件的不同结果;但它可能是时间,目前的CPU负载水平,任何容易混淆低质量固件或软件的东西... :-)我真的不知道一致的实验结果可以更明确地说出来。



-SA

You are welcome.

Let me put some speculations here. I hope we are about to close this issue, because further steps can be out of our reach.

According to your description, your code does nothing by handling the mouse wheel event (next time, better show where you add the event handler to the invocation tree of some event instance, that is, corresponding += operator, because the method name customTileController_MouseWheel, strictly speaking, does not tell anything about it; also, never use such auto-generated names, they violate good Microsoft naming conventions, for some apparent reasons). It cannot be wrong.

First of all, all input events available in .NET are of different levels. Some are primary and are generated by the hardware and are pushed to the system through the hardware interrupts one some IRQ line and handled by the hardware driver, and some are secondary. For example, hardware events produce KeyDown and KeyUp events (also indirectly), but not KeyPress event, which is secondary to the first two; it comes into play after a long chain taking into account input language, to produce a character which does not exist on lower level.

This is not what happens to physical mouse wheel. When you roll it, hardware generates the event of the same level as, say, mouse move, even though in mouse move of an optical mouse, optical image recognition takes place. Anyway, from the computer standpoint, these are the events of the same level. The roll of the mouse cannot be misinterpreted as mouse move.

What happens in the touchpad "scroll" area? Nothing like that. Instead, some code is just "trying" to emulate the same effect as the "real mouse" does. Physically, the primary events are still the same as you have with the regular touch. Note that even the mouse button down event can be "real" (touchpad has physical buttons, usually) or emulated, through the quick touch and them move. I don't really know where this simulation happens, in some piece of firmware or the driver, but I would rather guess it happens in the driver, that's it, at the expense of the computer's CPU. Some elements of "IA" are involved: recognition of the touch.

And we all know that the recognition can give you false positives and false negatives. And if the quality of the combination of the hardware (including firmware) and the driver is questionable, or some part of it is out of tune, the recognition results can be inadequate. Unfortunately, I failed to explain different results for different software; but it could be timing, the level of CPU load at the moment, anything which tends to confuse low-quality firmware or software… :-) I don't really know consistent experimental results to tell anything more certainly.

—SA


这篇关于如何对WPF中的触摸板滚动做出反应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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