问题
During development i have observed that certain PDAs with Windows CE and possibly Windows Mobile too are sending the Enter key twice in the key pressed event thus i execute twice the code that lies under the control's key press event for the return button.
I suspect that this is a hardware bug and i would like to ask how you resolved it without changing your application logic.
回答1:
Without changing the logic? You really can't (unless there is a hardware or firmware fix). I'd guess the simplest mechanism (that requires a logic change) is to treat two Enter keys or keypresses in a short period (say < 100ms) then ignore the second.
回答2:
I don’t know if this will help but if you read the keyboard port Enter is seen as two bytes rather than one.
回答3:
This happened to me too and it turned out it was because the "enable character repeat" option was enabled in control panel->keyboard. The default repeat delay was way too fast for the keypad that we used, so I just slowed it down and the problem went away.
来源:https://stackoverflow.com/questions/634230/keypress-event-is-triggered-twice-for-a-single-enter-button-press-in-windows-ce