简体   繁体   English

Haxe:处理水平滚动事件

[英]Haxe: Handling horizontal scroll events

I recently started using Haxe, so pardon me if my question has an obvious answer or if my description of the problem is a little sloppy, but I'm going to try my best to explain it. 我最近开始使用Haxe,请原谅我的问题是否有明显的答案,或者我对问题的描述有些草率,但是我将尽力解释。

I'm working on a laptop that has a multitouch-supported track pad, and a normal optical mouse with only a vertical scroll wheel (no horizontal clicking available on there). 我正在使用一台笔记本电脑,该笔记本电脑具有支持多点触控的触控板,以及一台普通的光学鼠标,只有一个垂直的滚轮(那里没有水平单击按钮)。 I'm looking for a way to handle horizontal scroll input / events. 我正在寻找一种处理水平滚动输入/事件的方法。 OpenFL's mouse events support vertical scrolling well enough. OpenFL的鼠标事件足够好地支持垂直滚动。 Both the mouse scrolling and the two-finger track pad scrolling work fine for the vertical axis. 对于垂直轴,鼠标滚动和两指触控板滚动都可以正常工作。 It looks like the same event is generated when either of those input methods are used, which is understandable. 可以理解,当使用这些输入方法中的任何一个时,似乎都会生成相同的事件。 But I can't seem to find an event that would be generated when a horizontal scroll is performed. 但是我似乎找不到执行水平滚动时会生成的事件。 The track pad allows for horizontal scrolling, since web browsers respond to the command, but I can't find any way to make my program respond to this input. 触控板允许水平滚动,因为Web浏览器会响应该命令,但是我找不到任何使程序响应此输入的方法。 Lime's "onMouseWheel" function doesn't respond to the input either. Lime的“ onMouseWheel”功能也不响应输入。 Do you guys have any suggestions for capturing this kind of input for an app targeted for Windows? 你们对于针对Windows应用程序捕获此类输入有什么建议吗?

Thanks in advance 提前致谢

UPDATE: What I'm looking for here is not a question of how to scroll the screen horizontally, but how to recognize the horizontal scroll event coming from hardware, for example two fingers on the track pad or a sideways click of the middle mouse wheel. 更新:我在这里寻找的不是关于如何水平滚动屏幕的问题,而是如何识别来自硬件的水平滚动事件,例如,在触控板上的两根手指或鼠标中键的侧向单击。 Lime's onMouseWheel has two params, deltaX and deltaY , but no events are triggered that give back a non-zero deltaX value. Lime的onMouseWheel具有两个参数deltaXdeltaY ,但是没有触发任何返回非零deltaX值的事件。 Vertical scrolling fires an event that returns deltaX = 0 and deltaY = +/- 1, but horizontal scrolling doesn't even trigger an event. 垂直滚动会触发返回deltaX = 0和deltaY = +/- 1的事件,但水平滚动甚至不会触发事件。

This can be done in several ways. 这可以通过几种方式来完成。 The first is to add an event handler to mouse wheel for the object instance that you want to attach the event handler to, so MouseEvent.MOUSE_WHEEL and use the delta variable to determine the scroll direction. 第一种是将鼠标事件添加到要附加事件处理程序的对象实例的事件处理程序,因此, MouseEvent.MOUSE_WHEEL并使用delta变量确定滚动方向。 What you may also need to do is handle a key down event which enables horizontal scrolling instead of vertical. 您可能还需要做的是处理一个按下键事件,该事件使水平滚动而不是垂直滚动成为可能。

Some example code: 一些示例代码:

mySprite.addEventHandler(MouseEvent.MOUSE_WHEEL, onScroll);
mySprite.addEventHandler(KeyboardEvent.KEY_DOWN, onKeyDown);
mySprite.addEventHandler(KeyboardEvent.KEY_UP, onKeyUp);

...
private var horizontal:Bool;
private function onScroll(e:MouseEvent):Void
{
    if (e.delta > 0 && horizontal)
        mySprite.scrollRect.x++;
    else if (e.delta < 0 && horizontal)
        mySprite.scrollRect.x--;
}

private function onKeyDown(e:KeyboardEvent):Void
{
    if (e.keyCode == 18)
         horizontal = true;
}

private function onKeyUp(e:KeyboardEvent):Void
{
    if (e.keyCode == 18)
         horizontal = false;
}

You will need to define the scrollRect in your constructor somewhere to specify the scrolling bounds of the sprite. 您将需要在构造函数中的某个地方定义scrollRect,以指定子画面的滚动范围。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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