I don't have a piece of code that will do exactly what you want, but I'm pretty certain you can do it, if by no more elegant means than using ctypes. The Sidekick app is an example of how ctypes can be used (it basically calls some functions in the USER32 DLL to let it provide hotkeys in a way that AC itself can't).