Added missing null-termination checks.
Changed Get(Async)KeyState return type to short.