I built up a control system for our amateur radio clubhouse which allows members to make reservations on a schedule for the use of a radio & an antenna from a web-based scheduling system. I have an RPi that reads that database & uses the reservation information to selectively control the power on any one of three radios, & to connect any one of three antennas to the selected radio. A couple of the radios have PCs associated with them whose power must also be controlled. All of the power control is done by RPi I/O pins controlling digital relays.
Now, here's where my description of this system actually has something to do with the OPs post: after the reservation period ends, we needed a way to cleanly power-off the associated PCs. I programmed a Teensy for each PC which runs as a keyboard & accepts a trigger from the RPi via an I/O pin, then generates the keystrokes to run a command shell (WINDOWS-R, followed by "cmd.exe"), then generates the keystrokes to cause the command shell to shutdown the PC (" /c shutdown /s /t0" & RETURN). There are conditions where the PC needs to be restarted instead of shutdown, so a similar method is used from the same Teensy, triggered by a different I/O pin, which again generates the keystrokes to run a command shell (WINDOWS-R, followed by "cmd.exe"), then generates the keystrokes to cause the command shell to reboot the PC after a 30-second delay (" /c shutdown /r /t30" & RETURN).
Using this method is very effective at insulating the keyboard commands originating from the Teensy from anything else that may be going on with the PCs desktop applications (which might potentially interfere with initiating activities by way of a shortcut). In our radio clubhouse implementation, these PCs are not used by any operators, so we don't have to worry about any other windows stealing focus while the keyboard commands are being executed.
Hope that helps . . .
Mark J Culross
KD5RXT