Incorrect boolean value returned by keyboard input functions?

This is an issue I’ve been facing for a while but I’ve never really been able to figure it out. It happens for every keyboard input handling library I use, even the one built into GameMaker. Basically the problem is that when a certain key is pressed for an extended period of time, even after letting go of the key the keyboard input function continues to return a boolean value of “true” indicating that the key is still being pressed.

This results in the common bug in games when the player holds on to the arrow keys or any key that controls the character’s movement, and after a while even though the player lets go of the key the character continues to move in that direction.

Is this due to a lag in the input handling? Is it a problem that a third-party user of the library can mitigate? I’d really appreciate an answer to this question that’s been bugging me for a while now. Thanks ;D