java中的media / fn键 [英] Media/fn keys in java

查看:122
本文介绍了java中的media / fn键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用java的gstreamer绑定在java中开发媒体应用程序。一切顺利,除了关于键盘的一个小问题,特别是媒体键(例如播放/暂停,后退,下一个)。

I am currently developing a media application in java using the gstreamer bindings for java. All is going well except for one small issue regarding the keyboard, specifically the media keys (e.g. play/pause, back, next).

我有可以正常工作的动作这些功能的按钮/菜单项,并希望允许使用某些键盘上的键(通常在笔记本电脑上)。但是,我找不到java.awt.event.KeyEvent中的东西来表示这些键。我尝试运行下面的代码片段,它适用于大多数键,包括f1-12,但在'fn'被保持时没有响应'fn'或媒体键。

I have Actions that work fine as buttons/menu items for these functions, and was hoping to allow the use of the keys that are on some keyboards (often on laptops). However, I could not find andthing in java.awt.event.KeyEvent to represent these keys. I tried running the snippet of code below, and it worked fine for most keys, including f1-12, but did not respond to 'fn' nor to the media keys while 'fn' was held.

有谁知道如何使这些密钥工作?

Does anyone know how to get these keys working?

代码:

import javax.swing.*;
import java.awt.event.*;

public class Key extends JFrame{

    public Key(){

        JTextField f = new JTextField(50);
        f.addKeyListener(new KeyAdapter(){
            public void keyPressed(KeyEvent e){
                System.out.printf("%s : %d \n", e.getKeyChar(), e.getKeyCode());
            }
        });
        setContentPane(f);
        pack();
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        setVisible(true);

    }

    public static void main(String[] args){
        new Key();  
    }

}


推荐答案

如果 e.getKeyChar() e.getKeyCode()键,当你没有返回任何内容时按下这些键,除了使用JNI 获取较低级别的代码。

If the e.getKeyChar() and e.getKeyCode() keys don't return anything when you press those keys, I'm not aware of any other way to get those events via the standard Java library, other than using JNI to get the codes at a lower level.

您似乎走在正确的轨道上,尝试获取密钥时的密钥代码按下,当你不知道Java中适当的常量是什么时,你会发现关键代码。

You seem to be on the right track, trying to get the key codes when a key is pressed, which is how you would discover key codes when you don't know what the proper constant is in Java.

除此之外,这个问题似乎提供了一些可能性(虽然我不确定这是否只适用于Microsoft IntelliType设备,或者是否它将跨平台工作)。例如,当我在Mac上使用Microsoft IntelliType键盘时,媒体键似乎工作正常。

Other than that, this question seems to offer some possibilities (though I'm not sure if this only works with Microsoft IntelliType devices, or if it will work cross-platform). When I use a Microsoft IntelliType keyboard on my Mac, for example, the media keys seem to work just fine.

这篇关于java中的media / fn键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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