Seems like nobody really encounter this problem except me, but here goes the piece of code to clear the keyboard buffer by directly writing the starting and endpoint of the keyboard buffer start and end.
;--------------------------------------------------------------------------
; clears keyboard buffer
;--------------------------------------------------------------------------
clearkeyboardbuffer proc near
push ax
push es
mov ax, 0000h
mov es, ax
mov es:[041ah], 041eh
mov es:[041ch], 041eh ; Clears keyboard buffer
pop es
pop ax
ret
clearkeyboardbuffer endp