Help with Mouse Wheel on OSX

Working with my MacBook Air (Sierra 10.12.1)
When I move slowly the mouse wheel on a control, MouseWheel event fires. As it should be.
But deltaX and deltaY (both) are equal to zero.

Is it normal? I am not a regular Mac user and probably I should configure something.
Any hint about what I am doing wrong?

If I move the wheel quickly everything works as expected, although what really happens is this:

  • one call to Function MouseWheel with deltaX = deltaY = 0 and a second call to the same function with deltaY = something

normal
delta X and Y are integers but the track pad actually can report sub pixel movement

Thanks Norman.
And… is there any way to catch these subtle values?

no
a double like “0.5” when shoved in to an integer is “0”

I think I filed a feature request for us to move a fair number of things to doubles
Pixel X and Y would be nice
Mouse X, Y
Deltas (like this)

Here’s some code I found to read the deltas off the mouse wheel NSEvent, which come in as Singles. This is tested only in 32bit, my guess to work in 64bit is all ‘Single’ types should be changed to ‘CGFloat’. In a quick test it runs through the HasPreciseScrollingDeltas code but the logged deltas are still integral values so ymmv. Also, I can’t tell if this is my code because some aspects are not my usual style (deep if nesting, "End If"s, capitalized keywords,…). Also not sure if the pragmas are necessary or what.

[code]Function MouseWheel(X As Integer, Y As Integer, DeltaX as Integer, DeltaY as Integer) As Boolean
#Pragma DisableBackgroundTasks
#Pragma DisableBoundsChecking

Dim CorrectX As Single = DeltaX
Dim CorrectY As Single = DeltaY
Dim UsesPixelDeltas As Boolean

Try
Declare Function objc_getClass Lib “Cocoa.framework” (aClassName As CString) As Ptr
Declare Function sel_registerName Lib “/usr/lib/libobjc.dylib” (Name As CString) As Ptr
Declare Function GetSharedApplication Lib “Cocoa.framework” Selector “sharedApplication” (Target As Ptr) As Ptr
Declare Function GetCurrentEvent Lib “Cocoa.framework” Selector “currentEvent” (Target As Ptr) As Ptr
Declare Function RespondsToSelector Lib “Cocoa.framework” Selector “respondsToSelector:” (Target As Ptr, Sel As Ptr) As Boolean
Declare Function HasPreciseScrollingDeltas Lib “Cocoa.framework” Selector “hasPreciseScrollingDeltas” (Target As Ptr) As Boolean
Declare Function ScrollingDeltaX Lib “Cocoa.framework” Selector “scrollingDeltaX” (Target As Ptr) As Single
Declare Function ScrollingDeltaY Lib “Cocoa.framework” Selector “scrollingDeltaY” (Target As Ptr) As Single

Dim NSApplication As Ptr = objc_getClass("NSApplication")
If NSApplication <> Nil Then
  Dim SharedApplication As Ptr = GetSharedApplication(NSApplication)
  If SharedApplication <> Nil Then
    Dim EventObject As Ptr = GetCurrentEvent(SharedApplication)
    If EventObject <> Nil Then
      If RespondsToSelector(EventObject,sel_registerName("hasPreciseScrollingDeltas")) Then
        UsesPixelDeltas = HasPreciseScrollingDeltas(EventObject)
        CorrectX = ScrollingDeltaX(EventObject) * -1
        CorrectY = ScrollingDeltaY(EventObject) * -1
      End If
    End If
  End If
End If

Catch Err As RuntimeException
UsesPixelDeltas = False
CorrectX = DeltaX * -1
CorrectY = DeltaY * -1
End Try

//…CorrectX and CorrectY now contain the wheel deltas

End Function[/code]

Thank you, Will.
I’ve took the code, changed Single by CGFloat, but unfortunately it didn’t work because “HasPreciseScrollingDeltas” returns False.

However I noticed something strange:
If you create a break in the middle of the code, for example at “CorrectY = ScrollingDeltaY(EventObject) * -1”, in the variables panel you can not see CorrectX, CorrectY, both declared as CGFloat. Is it the expected behaviour?[quote=305141:@Norman Palardy]
I think I filed a feature request for us to move a fair number of things to doubles
Pixel X and Y would be nice, Mouse X, Y, Deltas (like this)[/quote]
I could not find this request. I will create one.

Perhaps ScrollingDeltaX/Y is wrong. I tried with deltaX/Y and get floating point values now. The change is a rename in these lines…

[code]
vvvvvv vvvvvv
Declare Function deltaX Lib “Cocoa.framework” Selector “deltaX” (Target As Ptr) As Single
Declare Function deltaY Lib “Cocoa.framework” Selector “deltaY” (Target As Ptr) As Single

       vvvvvv

CorrectX = deltaX(EventObject) * -1
CorrectY = deltaY(EventObject) * -1[/code]

I get plenty of 0,0 deltas too but I think those are just carrying info about the event ‘phase’ changing.

Also, if HasPreciseScrollingDeltas is false it may mean floating point values just aren’t available. I’m getting True from my trackpad.

Please post the link. I have a few points to spend and think this is a very good place for them.

In that context, did you consider a new or enhanced Color datatype using (probably optionally to not break old code) doubles instead of integers too? Especially with 10 bits per pixel and even more HDR screens we are losing a lot of dynamics with fixed 8 bit colors.

I always read this as the quality of the pointing device. As far as I know, floating point deltas are always available, just that they might be less precise when scrolling.

Hi Will,

Some improvements! :slight_smile: However I had to change Function deltaX and deltaY by deltaXX and deltaYY, since these words are parameters of the Function MouseWheel and can not be used.

Now CorrectY has a value 0.1 or -0.1 which is perfect to know if I must zoom in or out.
Curiously, the first wheel rotation in any direction doesn’t rise MouseWheel event, but the following do. When you change rotation direction, you must rotate once for nothing and then it works.

Thanks again,

[quote=305240:@Ulrich Bogun]Please post the link. I have a few points to spend and think this is a very good place for them.
[/quote]
feedback://showreport?report_id=46419

[quote=305240:@Ulrich Bogun]In that context, did you consider a new or enhanced Color datatype using (probably optionally to not break old code) doubles instead of integers too? Especially with 10 bits per pixel and even more HDR screens we are losing a lot of dynamics with fixed 8 bit colors.
[/quote]
I think there is one for that too feedback://showreport?report_id=25846
Not sure if its public or not