@motorollin
I don't know how WHDLoad does it, but as mentioned earlier, it's a specific hack for each specific game, not a catch-all solution. Someone must have spent some time figuring it out for each of the games it works on.
There is already code that polls the keyboard registers, that's what the keyboard interrupt does. This code is called when someone presses or releases a key. That's what I'm talking about doing, patching this interrupt (which is part of the OS, not the game) with extra code. But there is nowhere to put code that checks the joystick, other than in that interrupt, or other than actually rewriting the game itself. But if you put it in that interrupt, of course it will only look at the joystick when someone presses a key on the keyboard!