How to detect the user is using the Trackpad and not the mouse in Java swing?

后端 未结 3 925
清歌不尽
清歌不尽 2021-01-04 00:37

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 conten

3条回答
  •  攒了一身酷
    2021-01-04 01:12

    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.

    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).

    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.

    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.

提交回复
热议问题