我了解如何将修饰符与键绑定一起使用,CTRL_DOWN_MASK + some key
但我希望能够将特定操作绑定到当控件、某些字母(即“W”)和向上箭头都被按下时。类似的东西CTRL_DOWN_MASK + some key + Up Arrow
。
我会用它来改变某个声音片段的音量。因此,当我CTRL_DOWN_MASK + W + Up Arrow
全部按下时,分配给 W JButton 的声音剪辑的音量会增加,如果我有CTRL_DOWN_MASK + W + Down Arrow
,所述声音剪辑的音量会降低。
public void bindKey(JPanel base)
{
base.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(key, InputEvent.CTRL_DOWN_MASK),"Volume"+key);
base.getActionMap().put("Volume"+key, new AbstractAction(){
public void actionPerformed(ActionEvent e)
{
//if(Up Arrow is being pressed.)
setGain(currentGain() + 1.0f);
//if(Down Arrow is being pressed.)
setGain(currentGain() - 1.0f);
}
});
}