Open-Close Widget

How to make when I press key to open/close widget? Now o can only to open.

If you want to use the same key for opening and close, use the FlipFlop node.