Key press/Key release
Define a bit vector that will hold the current state of all buttons. When you detect an edge caused by a press, you update the appropriate bit (set to 1) in the vector. When you detect the other edge caused by a release you update the bit again (back to 0 for example). When you detect a new key press all you need to do is check that the vector is

keypad_state = (others =&gt; '0')


to find out if this is the only button currently being pressed. If the vector is not all 0's you can decide to do nothing and when the '3' is released you simply update its state in the vector and this does nothing as your code probably does not react to key releases. This way you simply add a single if statement and eliminate the problem. If you had posted some code I might be able to edit it to reflect this mechanism.