Fred Kleinschmidt wrote:You also need to be aware that, on many platforms, holding down a key may cause repeated KeyPressed events after a short delay, with no intervening KeyReleased event.
Are you sure it's the KeyPressed event that is repeated, and not the KeyTyped event?
Another way is to use a collection that only allows one entry for a particular key, such as a Hashmap or TreeMap.
Why a Map and not a Set, like I've already shown? I'd go for HashMap, since TreeMap is mostly useful if you need ordering or a custom equality determination (using a comparator, e.g. case insensitive).