I have done similar work in JavaScript to read magnet card swipes. You will need to measure the time between key press events. If the time is under a THRESHOLD (you might need to determine this experimentally), then its the wedge reader, so append the pressed key to your input string. Otherwise, its a human, so reset the state.
This is a rough example of how you might accomplish this:
private String input = "";
private long lastPress = 0;
public void onKeyPress(Event event) {
if(lastPress - System.currentTimeInMillis() < THRESHOLD) {
lastPress = System.currentTimeInMillis();
input += event.getKey();
} else {
lastPress = 0;
input = "";
}
}
This is just a starting point. Your particular application may require additional conditions like checking for sentinels and what not to help determine if you are in a wedge read or not.