Show panel while a modifier key is pressed (like swaybar)

Okay, the code shared in the article shared in this discuss post works for showing/hiding the panel:

let panel = panelById(401);

panel.hiding === "autohide" ? panel.hiding = "windowsgobelow" : panel.hiding = "autohide";

Now I just need to find out how to do something on global keydown/keyup events (as the regular shortcut facility only allows KeyUp).