What would be the expected behavior for a window that hides from a key press

This is a subjective question, but I need opinions.

I have a WinForms C # application whose window is hidden after a certain key press (Enter or Escape) with possible modifiers (like Ctrl-Enter). When hidden on KeyDown or KeyPress, another application that becomes active after my window is hidden receives a KeyUp event for that keypress. Usually this shouldn't affect this other application, but some are responsive to KeyUp. For example, TweetDeck sends a message that is currently being edited on "Enter" KeyUp, even if it hasn't received KeyDown / KeyPress.

So I thought okay, I'll be a good citizen, I'll hide on KeyUp. But this is not the case. If I'm only looking for clues up, I do what I blame others for! If I try to create a KeyDown / KeyUp match history, I overcomplicate my code (modifiers generate their own key).

What should I do? What should a well-implemented application do?

+1


source to share


3 answers


I cannot think of any program that implements keyboard shortcuts in the KeyUp event. This standard was established a long time ago using the Windows TranslateAccelerator () API. It translates WM_KEYDOWN. Windows Forms implements the same behavior with ProcessCmdKey ().



Looks like you found doozy. Does it handle Alt + F4 correctly?

0


source


It's a hack, but you can set your program state to "pending hide" when you get the key down. And then when you get the key for that sequence, reset the "pending state" and then hide.

Alternatively, can you just "eat" the message queue key after you get the down key?

I wouldn't worry too much about apps handling keywords and not down keys - as you point out - the only reason this is a problem is because your app is changing active windows in the middle of the down key sequence. Your responsibility (IMO) also "is" key messages. You can probably just manipulate the key instead of the down key with no side effects.

EDIT



Thinking about it further - when you alt-tab to a new window - the action doesn't happen until the key is closed. Meanwhile, it shows a window of possible applications to change. You can do a similar action and there is a precedent for this behavior.

So: Down to Down: The display window indicating the application will be hidden. on the up key: hide the window

This is the "state" - you can only hide if you got the key and the key up - at least that's what I would do. 99.9999% (guess) not handling a keypress would be fine.

+2


source


Well, I would say, "Don't worry about it until it becomes a problem," but I think this is a problem now.

In this case, I would hide in KeyPress (expected user experience) but grab focus until KeyUp comes out (or short timeout).

-1


source







All Articles