getchar: fix infinite loop due to pending events

The `inchar` function could enter an infinite loop if there are events pending
to be processed when an interrupt is received.