def _key_callback(self, key, duration):
     str_key = lib.UserControlCodeToString(key).title()
     if duration == 0 and self._last_key != key:
         self._last_key = key
         self._key_event = eg.TriggerEnduringEvent(prefix=self._name,
                                                   suffix='KeyPressed.' +
                                                   str_key)
     elif duration > 0 and self._last_key == key:
         self._last_key = 255
         self._key_event.SetShouldEnd()
         self._key_event = None
     elif self._last_key != key:
         self._last_key = 255
         eg.TriggerEvent(prefix=self._name, suffix='KeyPressed.' + str_key)
     return 0
Example #2
0
    def TriggerEnduringEvent(self, suffix, payload=None):
        """
        Trigger an enduring event.

        Does nearly the same as :meth:`!TriggerEvent` but the event will not be
        ended immediately. This is used for devices that can have longer
        enduring events, like a remote, where you can press and hold a button.

        The plugin has to call :meth:`!EndLastEvent` to end the event. The last
        event will also be ended, if another event will be generated through
        :meth:`!TriggerEvent` or :meth:`!TriggerEnduringEvent`. This will
        ensure, that only one event per plugin can be active at the same time.
        """
        with gTriggerEventLock:
            info = self.info
            info.lastEvent.SetShouldEnd()
            event = eg.TriggerEnduringEvent(suffix, payload, info.eventPrefix,
                                            self)
            info.lastEvent = event
            return event