"Natural" Scrolling

Anyone know how to detect if the user has turned “Natural” scrolling on or off in OSX?

I have MouseWheel events and I want my program to react “properly” based on the users setting

This shows two ways…

For the first one you need to get the NSEvent as it comes in. To do that in Xojo I think you’d have to create an NSView subclass implementing ScrollWheel with a Shared method and then attach it as a subview of your control. Then when the event comes in you can check isDirectionInvertedFromDevice and pass it on.

For the second you can use MacOSLib. I think it should look like this but it’s not working with my old copy of MacOSLib, or maybe it’s that com.apple.swipescrolldirection is wrong.

dim isNatural As boolean = NSUserDefaults.StandardUserDefaults.BooleanValue("com.apple.swipescrolldirection")

Hmm, no. I think that MacOSLib code is wrong, not sure the proper way.

I don’t know if macoslib exposes wrappers to do this, but here’s how:

[[[NSApplication sharedApplication] currentEvent] isDirectionInvertedFromDevice]

Here is one way to do it… and it works under Maverick (I just tested it)

  Dim retcode As Boolean
  #If TargetMacOS Then 
    Dim sh As New shell
    Dim cmd As String
    cmd="defaults read NSGlobalDomain com.apple.swipescrolldirection"
    sh.Mode = 0
    sh.Execute cmd
    retcode=(trim(sh.Result)="1") ' Natural Scrolling in OSX in ON
  Return retcode

Got the current macoslib and it has currentEvent but not isDirectionInvertedFromDevice, and that call is only valid for wheel event type so you’ll need to add the declare and call it in the MouseWheel event. If the event isn’t wheel type you’ll get an ObjC exception.

[code]Function MouseWheel(X As Integer, Y As Integer, deltaX as Integer, deltaY as Integer) As Boolean

declare function isInverted lib “Cocoa.Framework” selector “isDirectionInvertedFromDevice” (id As Ptr) as boolean

dim isNatural As boolean = isInverted(NSApplication.app.currentEvent.id)

End Function[/code]