Finding keycode of multimedia key in java

我与影子孤独终老i 提交于 2019-12-08 05:22:49

问题


I want to capture key presses on Windows like Fn+Pause, Fn+VolumeUp in my Java Application but I am unable to detect their KeyCodes.

addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            System.out.println(e.getKeyCode());
        }
    });

Using this snippet it prints 0 for all the Multimedia Key Presses !

Kindly suggest a suitable method for finding the keyCode and thereby utilizing it in Java Application.


回答1:


Use the JIntellitype library.

This API is a Java JNI library that uses a C++ DLL to do all the communication with Windows. That also means the platform on which you are running must be Windows.

If you are in Linux use JXGrabKey

In MacOSX use OSSupport




回答2:


Check the KeyEvent constants for some special keys. Other special keys might indeed not be "recognized".

See this thread as well.



来源:https://stackoverflow.com/questions/16494804/finding-keycode-of-multimedia-key-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!