Welcome to Developer Fusion! :)
This might be possible for a USB keyboard, but I'm pretty sure there's no way of doing this using a PS/2 keyboard, as that port was never designed to be "hot swappable".
From wikipedia "PS/2 ports are designed to connect the digital I/O lines of the
microcontroller in the external device directly to the digital lines of
the microcontroller on the motherboard. They are not designed to be hot swappable.
Hot swapping PS/2 devices usually does not cause damage due to the fact
that more modern microcontrollers tend to have more robust I/O lines
built into them which are harder to damage; however, hot swapping can
still potentially cause damage on older machines, or machines with less
robust port implementations."
Sorry I can't be of more help!