Skip to content

File evabKeyCatcher.h

File List > src > evabKeyCatcher.h

Go to the documentation of this file

#pragma once

#include <evaHandler.h>

namespace evab
{

  template <class T, Keys... KEYS>
  class KeyCatcher : public T
  {
  public:
    template <typename... Args>
    KeyCatcher(eva::IHandler *aListener, Args &&...args)
        : T(args...), mListener(aListener)
    {
    }

    bool OnKey(Keys aKey) override
    {
      if (T::OnKey(aKey))
        return true;

      if ((... || (aKey == KEYS)))
      {
        if (mListener)
        {
          mListener->invoke(this, {0, (int)aKey});
          return true;
        }
      }
      return false;
    }

  private:
    eva::IHandler *mListener = nullptr; 
  };

}