Fix sending wrong keys when using multiple keyboard layouts

This patch fixes following bugs.
https://code.google.com/p/semicomplete/issues/detail?id=13
https://code.google.com/p/semicomplete/issues/detail?id=21
https://code.google.com/p/semicomplete/issues/detail?id=41#c1
https://code.google.com/p/semicomplete/issues/detail?id=76
Merge pull request #39 from kealthou/fix_multiple_layout_issue

Fix sending wrong keys when using multiple keyboard layouts