Just out of my own Curiosity, There is a program already (Smartcopilot) that takes care of this. And there are a few people in the community very proficient in writing the code to do a shared cockpit. Have you thought about reaching out to them for help and saving yourself the trouble?