You can create a ParserListener to listen for any musical event that any parser is parsing. I have adjusted one of the examples to print out the note position in an octave. You can modify this to find out exactly which note is pressed:
public class ParserDemo {
public static void main(String[] args) throws InvalidMidiDataException, IOException {
MidiParser parser = new MidiParser(); // Remember, you can use any Parser!
MyParserListener listener = new MyParserListener();
parser.addParserListener(listener);
parser.parse(MidiSystem.getSequence(new File(PUT A MIDI FILE HERE)));
}
}
//Extend the ParserListenerAdapter and override the onNoteParsed event to find the current note
class MyParserListener extends ParserListenerAdapter {
@Override
public void onNoteParsed(Note note) {
//A "C" note is in the 0th position of an octave
System.out.println("Note pushed at position " + note.getPositionInOctave());
}
}
Source: http://www.jfugue.org/examples.html