I think you should check for release event like this:
[pascal]
flags := GetKeyEventFlags(K);
if (flags and kbReleased) <> 0 then
writeln('Released key event'):
[/pascal]

I suspect that since flags is a byte it can hold many flags joined together by binary or.