How can I alter the Input/Action map so when I bind an action to a specific key it also binds an action to Some Modifier + specific key?
i.e. SHIFT_DOWN_MASK + specific key
So all of my key bindings work without modifiers. I am assigning a sound file to a certain letter on the key board and when I press that key, the sounds file plays. I also have code to loop the sound file, toggle whether or not it loops, and check if it loops. I want to have it so that, in addition to binding the play()
action to the key, it will bind the toggleLoop()
action to the action SHIFT_DOWN_MASK + specific key
.
Where I bind actions:
@SuppressWarnings("serial")
public void bindKey(JPanel base)
{
base.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(key),"play"+key);
base.getActionMap().put("play"+key, new AbstractAction(){
public void actionPerformed(ActionEvent e)
{
System.out.println(key + " Pressed");
play();
}
});
//assigning action just the key pressed
base.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke((char)(key-32), InputEvent.SHIFT_DOWN_MASK),"loop"+(char)(key-32));
base.getActionMap().put("loop"+(char)(key-32), new AbstractAction(){
public void actionPerformed(ActionEvent e)
{
System.out.println(key + " toggled loop");
toggleLoop();
//fix toggle
}
});
//^ where I try to assign action to modifier
}