0

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.

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. 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. Lime's "onMouseWheel" function doesn't respond to the input either. Do you guys have any suggestions for capturing this kind of input for an app targeted for 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. Vertical scrolling fires an event that returns deltaX = 0 and deltaY = +/- 1, but horizontal scrolling doesn't even trigger an event.

Alexander L. Hayes
  • 3,892
  • 4
  • 13
  • 34
TFSM
  • 53
  • 1
  • 9
  • What platform are you targeting? It looks like flash support doesn't have a horizontal component implemented: https://github.com/openfl/lime/blob/2d3f51d2a4413069b221269da3e084c9b905caa6/lime/_backend/flash/FlashApplication.hx#L218 – MSGhero May 12 '15 at 20:46
  • @MSGhero I see what you mean.That `deltaX` will never be non-zero using Lime, it seems. Crap. We're targeting Windows at the moment, but will be moving to mobile spaces soon. Any suggestions? – TFSM May 13 '15 at 07:58
  • You might get a better response in the openfl forums. Or by complaining about your issue on twitter. – MSGhero May 15 '15 at 20:13

1 Answers1

0

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. 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.

tienery
  • 172
  • 7
  • Thanks for the quick answer. In your method above, what would the user interaction have to be to enable the horizontal scroll? By the looks of it, they would have to hold down a key on the keyboard and then scroll normally (aka vertically). Please correct me if I'm wrong. – TFSM May 12 '15 at 12:30
  • That is correct, the key code 18 is the key for ALT, so holding down the ALT key would enable horizontal scrolling. – tienery May 12 '15 at 12:45
  • Cool. What I'm actually looking for is help with the actual hardware input for a horizontal scroll. See the update above. – TFSM May 12 '15 at 12:51
  • Ah, sorry for misunderstanding your question. I thought you were looking for a code example. In that case (I am not 100% sure on how well OpenFL works for touch events, and Lime I'm completely blind to) OpenFL presents the [TouchEvent](http://docs.openfl.org/openfl/events/TouchEvent.html) class which allows for handling touch events, i.e. how many fingers touch the screen before enabling scrolling. Scroll events are handled by the hardware itself, so it may be a matter of finding information regarding that in Lime docs if Lime is your main focus here. – tienery May 12 '15 at 12:58