Key binding - listening for 2 keys
How do I develop my code to listen for F5 and F10, so if F5 is pressed run 'runSQL(conn, sqlStatement.getText().trim());' otherwise if F10 is pressed run 'runUpdateQuery(conn, sqlStatement.getText().trim());'
Thanks
Code:
AbstractAction action = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
runSQL(conn, sqlStatement.getText().trim());
}
};
// F5 key bind to run the SQL
String keyStrokeAndKey = "F5";
KeyStroke keyStroke = KeyStroke.getKeyStroke(keyStrokeAndKey);
InputMap im = pnlMain
.getInputMap(JPanel.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
im.put(keyStroke, keyStrokeAndKey);
pnlMain.getActionMap().put(keyStrokeAndKey, action);
Re: Key binding - listening for 2 keys
Re: Key binding - listening for 2 keys
Thank you - that's perfect!