Instead of having a python script that runs in the background to trigger events, you could use udev, which is part of the Linux kernel. Here's an example of using udev to trigger events when a bluetooth keyboard connects to a system: http://unix.stackexchange.com/questions/144417/making-udev-rule-for-bluetooth-keyboard