I finally adapted the great windows app "PuppetMaster" to run under wine and temporary give up with anyremote.
You really should take a look at "PuppetMaster" for some ideas, because this app gives a strong impression of "This is how it should be done". The only bad news is that their site http://www.lim.com.au/ no longer exists.
had to modify:
* direct bluetooth
* X server input emulation (used bits of your code actually)