Scroll Wheel Detection

I would like my GestureDetection WebSDK control to also detect scroll events in a target WebControl.

Scroll wheel action may not always be for scrolling, and therefore scroll details should be passed to an event handler when scrolling is disabled.

I have successfully added a mouse wheel event listener, but the challenge starts when I want to pass the data back to the ExecuteEvent. see my attempt bellow.

strGestures.Append("function MouseWheelHandler(e)") strGestures.Append("{") strGestures.Append(" // cross-browser wheel delta") strGestures.Append(" var e = window.event || e; // old IE support") strGestures.Append(" var delta = Math.max(-1, Math.min(1, (e.wheelDelta || -e.detail)));") 'strGestures.Append("debugger;") strGestures.Append("Xojo.triggerServerEvent('" + me.ControlID + "', 'mouseWheel', [e])") strGestures.Append(" return false;") strGestures.Append("}")

Parameter(0) of the ExecuteEvent returns and object with type [object MouseEvent]. I examined REALbasic.MouseEvent and found most of it’s variables matched the JavaScript(JS) variable e.

[code] Select Case name…

	...Case "mouseWheel"
			Dim Details as REALBasic.MouseEvent = Parameters(0)
	End Select[/code]

The code above failed with an illegal cast exception. “_VarientString cannot be cast to REALBasic.MouseEvent”

I could pass each detail back in a JS array but that’s not a very elegant solution. Other Xojo mouse events make use of the REALBasic.MouseEvent quite well. Is there anyway I can do the same?

I also noticed the Framework.js uses mouse wheel event listeners. Am I likely to break the framework if I add addition listeners to WebControls?

Any help would be much appreciated!

I think it would be simpler to pass the values as it is done in Xojo Desktop [quote]RectControl.MouseWheel ( X as Integer,Y as Integer, DeltaX as Integer, DeltaY as Integer ) As Boolean[/quote]

It would still be helpful to know if adding the event listers could cause trouble with the JS framework.

It shouldn’t, unless you’re relying on them in your control.

Keep in mind that passing every mouse event back to the server may not work well over the internet. They work locally because latency is 1ms, but once you get out there and latency >= 50ms, you can get behind really fast. Make sure you throttle them.

Thanks Greg, Appreciate your help. The traffic would be quite low with a mouse wheel but would probably increase dramatically with something like a track-pad scroll. I’ll add some threshold options to the JS.

Something to keep in mind… WebContainers do respond to MouseWheel events. You may want to test your control inside a container for conflicts.

Anyone wonder about apple mice?

I do.
No right button, no middle button… I wonder why anyone buys one… :slight_smile:

I don’t have one to test with… I would be interested if it works though.

[quote=363037:@Jeff Tullin]I do.
No right button, no middle button… I wonder why anyone buys one… :)[/quote]
No right button?

System preferences -> Mouse -> enable right-click … oopsie!

No middle button?

True of most mice.

And if you had ever seen my father with a two-button mouse, then you’d know why Apple has it set to one button by default :wink:

And NO SCROLL WHEEL! How can it possibly scroll! :stuck_out_tongue_winking_eye:

Btw: From a statistic I read a few years ago (numbers could be slightly different):

97% of Apple users have experience with Windows and chose the Mac deliberately. But less than 5% of Windows users have experience with Macs. Still doesn’t stop Windows users belittling the Mac as a “toy computer” and telling nonsense like “it has no right button” … now considering that all here are Xojo users and know the belittling attitude of “real programmers” maybe some time spent contemplating the irony might be helpful …

Apple mice do work with web scrolling. I have one here… and there is a scroll wheel. Just drag your finger on the surface of the mouse where you’d expect it to be.

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.