Java:如何获取OS X Lion中的滚动方法?

发布于 2024-11-29 15:25:05 字数 227 浏览 0 评论 0原文

由于 OS X 支持“自然滚动”,因此我的应用程序无法正常工作。自然滚动是为滚动窗格设计的,我真的很喜欢。但是,当我想放大/缩小时,它就出错了。所以,我想做的是检查 OS X 的滚动方法。
如果它是“自然”的,我将从 MouseWheelEvent.getWheelRotation() 中获取相反的滚动值,以使我的放大/缩小行为感觉正确。

简而言之:如何知道 OS X 是否使用自然滚动?

Since OS X supports the "natural scrolling", my applications works wrong. The natural scrolling is made for scroll panes, which I really like. But, when I want to zoom in/out, it works wrong. So, what I want to do is check the scroll method for OS X.
If it is "natural" I'll take the opposite of the scroll values from MouseWheelEvent.getWheelRotation() to make my zoom in/out behavior feel correct.

So, in short: How to know if OS X uses natural scrolling or not?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

飘然心甜 2024-12-06 15:25:05

找到了解决方案。

首先,您需要一个库来读取 .plist 文件。我使用了这个

您可以轻松地在 GlobalPreferneces.plist 中读取(使用 fseventer 检查在更改滚动选项时更改了哪个文件)以找出启用了哪种滚动,如下所示:

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());
}

Found a solution.

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

Than you can easily read in the GlobalPreferneces.plist (checked with fseventer which file is changed when changing the scroll option) to find out which kind of scrolling is enabled 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());
}
不知在何时 2024-12-06 15:25:05

看看 Mike Swingler 关于 java- 的答案开发者邮件列表。有一个完整的线索。

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

酒儿 2024-12-06 15:25:05

由于 Apple 已经放弃了 Java,我认为没有内置方法来检测是否启用了自然滚动。但是,您可以读入用于配置鼠标/触摸板行为的 .plist 文件(这是一个基本的 xml 文件),并查找将启用自然滚动的属性设置为 true 或 false。

您可以在此处找到所需的 .plist 文件:

User/Library/Preferences/ <- 此文件夹隐藏在 Lion 中!

com.apple.driver.AppleBluetoothMultitouch.mouse.plist

com.apple.driver.AppleHIDMouse.plist

编辑:

您无法使用标准 Java 框架读取 plist 文件,因为从 Mac OS 10.4 开始,所有 .plist 都以二进制格式保存。请参阅我的另一个答案以获得正确的解决方案。

As Apple has dropped Java, I don't think that there is built in method to detect if natural scrolling is enabled. However, you could read in in the .plist files for configuring mouse/touchpad behaviour (which is a basic xml file) and look for the property to enable natural scrolling is set to true or false.

You can find the required .plist files here:

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

com.apple.driver.AppleBluetoothMultitouch.mouse.plist

com.apple.driver.AppleHIDMouse.plist

Edit:

You can't read in a plist file with the standard Java Framework, as since Mac OS 10.4 all .plists are saved in binary format. See my other answer for a correct solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文