The wrong way is to poll input devices inside the element that received the focus. We will not even consider it, let's move on to the right one.
The correct one is an external handler that queues the received events. And this queue is available to windows, buttons and other objects.
In Windows, there is no need to specifically do anything, this event handling scheme is already present from the very beginning.
For DOS, the ideal solution would be to work with interruptions (its int 9h handler for the keyboard, int 33h for the mouse, etc.). This is exactly how event handling in Turbo Vision is arranged, so it makes sense not to reinvent the wheel, but to take everything from there. Especially since the source is.
For Linux, things are a bit more complicated (see the example , and this is not the only option), but the general meaning remains the same.
And most importantly, you need to understand. Despite the fact that the general principle is the same, its implementation is very strongly tied to the OS and the platform, and it is this that constitutes the lion’s share of the work ( neither the C language nor the C ++ language have the means to fully work with input devices, so everything is needed do it yourself ). And while spending time on DOS, you need to understand well why this is done, since in most cases it will be wasted time.
int 9handler :) - PinkTux