For Windows:
Have you tried Input Director?
After you install it on the two computers and set it up, you can control both machines and there is an option to Mirror input.
There is also the Microsoft Microsoft Garage Mouse without Borders Where you hit Ctrl 3 times to run the commands across all machines.
As a note, anything that you create software wise will be exactly the same as how these programs work. You hit the keyboard, the kb hook intercepts it and sends it over TCP/IP to computer 2 in 1ms (you do have good network...), where the second service implements the command.
If you are having troubles with software implementations (if there is something to do with the timing and video), then you need to have a hardware based solution like a special KVM because it would be almost impossible to synch things with software.
---EDIT - From comments
For Mac:
There really are not many options.
Software wise there is Synergy which works cross platform on Windows, Mac and Linux. It doesn't have a native option to mirror inputs like the others, but you can create hotkeys that implement certain actions on all/or some computers (for ex. hit F1 and it will send a spacebar keystroke to all machines). I believe that you could probably use this to achieve what you need.
Hardware wise, one method that I have heard of people using is buy 2 cheap identical sets of wireless keyboards/mice combos that have the little red connect button on them. I think the cheaper the better because you don't want it to be bluetooth, or have AES Encryption, or anything with enough smarts in it to stop you (nano receivers typically don't have sync buttons on them). Plug one wireless receiver into the computer click the sync button on the receiver and then also on the keyboard. Plug the next receiver in, and do the same.
http://www.tomshardware.co.uk/forum/274681-31-control-computers-time-keyboard-mouse maybe keyclone can help? http://solidice.com/downloads/windows/keyclone another post there mentions input director – barlop – 2015-07-30T00:08:03.133
and apparently taking a usb hub won't work.. i.e. plugging 2 computers and a keyboard into the sockets. . Or a keyboard onto the dangly bit and the computers into the USB sockets apparently won't work. – barlop – 2015-07-30T00:12:42.053