I know that I can get the ctl/alt key states from the keypress event when another key is pressed. But I can't find any way to detect the key state when, say, a mouse button is clicked. Yes, I get events when the ctl/alt keys are pressed and released, and I could keep track of whether they are up or down AS LONG AS the window stays in focus. But if the user, say, clicks on the desktop to take my window out of focus, then presses and holds the ctl or alt key down, and then clicks on my window, my code won't have seen the ctl key down event, and won't know it's down.
Is there a way to check the state of such modifier keys when a mouse click, or some other non-keyboard event, occurs?
Instead of trying to keep a state around permanently, check for modifiers every time you handle an event.
Examples: