Examples Delphi

Note that you only can empty your own application's message queue, not from that of another process.

program Dummy;
procedure EmptyKeyQueue;
var
msg: TMsg;
begin
while PeekMessage(msg, 0, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE or PM_NOYIELD) do;
end;
begin
EmptyKeyQueue;
end.