I like it! Thank you for sharing the code!
By the way, I have that same USB switch. I have tried a number of them, and that is the fastest I've found. The only major flaw is the status lights -- they are too hard to see from far away.
To fix that issue, I drilled a hole in the top of the case, over the lights, about the same size as the adjacent power button. I put a small piece of foam inside to separate the two lights, and covered it with tape. It works perfectly now and it's so much easier to see the status from a typical usage angle.
The whole modification took maybe 15 minutes, and I didn't even bother disassembling it first.