I have a Raspberry Pi Pico running CircuitPython. Is it possible for the python code on this board to detect if a modifier key is pressed on the host computer's keyboard when the board is connected to the host over USB?
My knowledge of USB protocols is limited but it feels like the Pico would need to be listening to data explicitly sent over USB. I don't think that key presses would be sent that way.
I'd be happy to be proven wrong.
I don't think you can do this without installing something on the host computer side to detect when the Pico was connected, check what keys were pressed and communicate with the Pico accordingly.
If the host computer is Windows then a quick search finds this which uses Windows Management Instrumentation to run Python code when a USB device changes.
Alternatively, you could attach a hardware button to the Pico and check that button when the Pico detects that it has been connected to a USB host - you appear to have already figured this out.