KeyEvent的特殊键(如静音) [英] KeyEvent special Keys (like mute)

查看:338
本文介绍了KeyEvent的特殊键(如静音)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在试图建立一个小的远程应用程序为Android到我的电脑上控制MediaPlayer的(如Rythmbox)。

I'm currently trying to create a little remote-app for Android to control a MediaPlayer (like Rythmbox) on my PC.

大多数媒体播放器明白我的键盘(如播放/暂停或下一个/ previous)上的特殊键。我的想法是,Android应用程序发送一个命令(如暂停)到PC中。在PC上运行正常的Java应用程序,它接收到该命令,并模拟了这种特殊的按钮的键盘preSS。

Most media-players understand the special keys on my keyboard (like "play/pause" or "next/previous"). My idea is that the Android App sends a command (like "pause") to the PC. On the PC runs a normal Java-Application which receives this commands and simulates a key-press of this special button.

的好处是,你可以使用这个应用程序在所有平台上的支持这个特殊的键每一个​​球员(以及他们在几乎每一个新的USB键盘)。

The advantage would be that you can use this App on all platforms for every player which supports this special keys (and they are on almost every new USB-Keyboard).

我搜索的JavaDocs在的KeyEvent 级,但我找不到任何一个常数。有谁知道如何模拟这些按钮之一的preSS如果这甚至有可能与Java?

I searched the JavaDocs for a constant in the KeyEvent-class, but I can't find any. Does anyone know how to simulate a press of one of those buttons and if this is even possible with Java?

附加库的是跟我没关系,也一样,只要没有其他的解决方案。

Additional library's are okay with me, too, as long as there is no other solution.

另外,我知道我应该使用机器人模拟键盘preSS,这适用于我的键盘就一切正常键。我根本找不到任何方法来模拟这些特殊键一键preSS。

Also, I know i should use a Robot to simulate the key-press and this works for all normal keys on my keyboard. I simply can't find any way to simulate a key press on those special keys.

推荐答案

所以,我认为这是不可能做到这一点与Java。我想另一件事,找出哪些键盘code中的特殊键有,但这个小程序只返回0,这些键(它为正常键):

So, I think it's not possible to do that with Java. I tried another thing to find out which key-code the special keys have, but this small program only returns 0 for those keys (it works for "normal" keys):

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JFrame;
import javax.swing.JLabel;


public class GetKeycode implements KeyListener{

    private JFrame f;
    private JLabel feld;

    public GetKeycode(){
        f = new JFrame("GetKeycode");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.addKeyListener(this);
        feld = new JLabel();
        f.add(feld);
        f.pack();
        f.setVisible(true);
    }

    @Override
    public void keyReleased(KeyEvent e) {
        feld.setText(e.getKeyCode()+"");        
    }

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

    // Unused:
    @Override public void keyPressed(KeyEvent e) {}

    @Override public void keyTyped(KeyEvent arg0) {}

}

我希望这将在JRE的功能的版本中实现。但在这一刻,似乎有没有办法解决这个。

I hope this will be implemented in feature versions of the JRE. But at this moment, there seems to be no solution to this.

感谢所有的答案,反正。

Thanks for all the answers anyways.

这篇关于KeyEvent的特殊键(如静音)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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