I've seen this when I was first looking into the input stuff recently.I think it was caused by the keyboard getting confused after I wastesting the data and clock lines on the interface.

One fix I came up with (and discarded) was to try to reset the keyboard3 times, and only fail if it failed all 3 times. The other fix (the oneI ended up using) doesn't make sense to i8042 keyboard controllers.