Java: How to get the scroll method in OS X Lion?

Since OS X supports natural scrolling, my applications do not work properly. Natural scrolling is made for scroll windows, which I really like. But, when I want to zoom in / out, it doesn’t work correctly. So, I want to check the scroll method for OS X.
If this is “natural,” I will stick with the opposite of the scroll values ​​from MouseWheelEvent.getWheelRotation() to change the behavior of the image.

So, in short: how do I know if OS X uses natural scrolling or not?

+6
source share
3 answers

Found a solution.

First you need a library to read .plist files. I used this one .

Than you can easily read in GlobalPreferneces.plist (checked with fseventer which file changes when the scroll parameter is changed) to find out which scroll is turned on like this:

 try { File globalPref = new File(System.getProperty("user.home") + "/Library/Preferences/.GlobalPreferences.plist"); NSDictionary dict = (NSDictionary)PropertyListParser.parse(globalPref); NSNumber pref = (NSNumber)dict.objectForKey("com.apple.swipescrolldirection"); if(pref.boolValue()) { //natural scrolling is enabled } } catch (Exception ex) { System.out.println("Faild to parse plist: " + ex.getMessage()); } 
+3
source

Since Apple abandoned Java, I don't think the built-in method detects whether natural scrolling is enabled. However, you can read in the .plist files to customize the behavior of the mouse / touchpad (which is the base xml file) and look for a property to enable natural scrolling, set to true or false.

Here you can find the necessary .plist files:

User / Library / Preferences / <- This folder is hidden in Lion!

com.apple.driver.AppleBluetoothMultitouch.mouse.plist

com.apple.driver.AppleHIDMouse.plist

Edit:

You cannot read in the plist file with the standard Java Framework, since Mac OS 10.4 all .plists are saved in binary format. See My other answer for the correct solution.

+1
source

Take a look at Mike Swinger's answer on the java-dev mailing list. There is a whole stream about it.

+1
source

Source: https://habr.com/ru/post/895122/


All Articles