To control OBS via shortcuts a WebSocket-based plugin is used.
The SimpleOBSWS Python library gives the possibility of controlling OBS externally by sending direct commands via WebSocket.