如何检测用户正在使用触控板而不是Java swing中的鼠标? [英] How to detect the user is using the Trackpad and not the mouse in Java swing?

查看:135
本文介绍了如何检测用户正在使用触控板而不是Java swing中的鼠标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java swing应用程序,该应用程序使用可缩放" JComponent来显示大数据.当用户移动鼠标滚轮时,我会监听这些事件,并从滚动量中更新JComponent的内容.

I hava a Java swing application that use a 'pan-able' JComponent to display large data. When the user move the mouse wheel, I listen to these events, and update the content of the JComponent from the scrolled amount.

我想根据用户是否有不同的行为

I would like to have a different behavior depending on whether the user is

  • 使用经典鼠标
  • 使用触摸板,就像现代Mac笔记本电脑中可以找到的那样.

我如何检测到用户正在使用鼠标滚轮和触控板来生成滚动事件?我依靠的是Java 1.6 swing,因为我无法使用javaFX.

How could I detect that the user is using the mouse wheel vs the trackpad to generate the scroll event? I am relying in java 1.6 swing, si I cannot go to javaFX.

问题背后的故事: 我只想在用户使用鼠标滚轮时为滚动事件添加一种凉爽的惯性感觉.但是,当然,在MacOSX上,触控板具有内置的惯性功能.所以我想决定是否应该产生惯性运动.

Story behind the question: I just wanted to add a cool inertia feel to the scrolling event when the user use the mouse wheel. But of course, on MacOSX, the trackpad has its own inertia stuff builtin. So I wanted to decide whether I should generate the inertial movement or not.

推荐答案

Java Swing是一项旧技术,它支持传统的鼠标滚轮旋转事件.

Java Swing is an old technology, it supports the traditional mouse wheel rotation events.

使用旧的滚轮鼠标或滚轮触控板时,它将读取硬件滚轮的旋转.

When you use the old wheel mouse, or wheel track-pad, it will read the rotation of the hardware wheel.

使用现代激光鼠标时,鼠标的移动将转换为旋转运动.

When you use a modern laser mouse, the mouse movement will be translated to rotation motion.

当您使用触摸式触控板(如现代Mac笔记本电脑中的触控板)时,滚动手势将转换为旋转运动,即单键&左键和右键单击两次(基于OS鼠标垫配置).

When you use a touch track-pad like the one in modern Mac laptops, the scroll gesture will be translated into rotation motion, single & double touch as left and right click (based on OS mouse-pad configuration).

您可以使用库详细检查输入设备,如果鼠标或触控板通过USB连接到计算机,则可以尝试

You can use libraries to check the input devices in detail, in case your mouse or track-pad is connected to your computer through USB, you can try J-USB library.

对于内部硬件,您首先必须确定操作系统的类型,然后才能基于该信息获取有关系统和硬件的信息.在Java中.

As for internal hardware, you first have to identify the type of OS, and based on that you can get information on system and hardware in Java.

最后,如果您的应用程序与用户交互,建议您询问用户他们正在使用哪种类型的鼠标,并将其存储在配置文件或其他内容中.

Finally, if your application interacts with a user, I suggest asking the user what type of mouse they're using, and store that in configuration file or something.

这篇关于如何检测用户正在使用触控板而不是Java swing中的鼠标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆