20 #include <vstgui4/vstgui/lib/cframe.h> 21 #include <vstgui4/vstgui/lib/events.h> 66 fOnKeyboardEventCallback = std::move(iOnKeyboardEventCallback);
67 return std::dynamic_pointer_cast<GlobalKeyboardHook>(shared_from_this());
77 static std::shared_ptr<GlobalKeyboardHook>
create(CView *iView)
79 return SelfContainedViewListener::create<GlobalKeyboardHook>(iView);
87 std::shared_ptr<SelfContainedViewListener>
registerView(CView *iView)
override 90 maybeRegisterKeyboardHook();
100 DCHECK_F(iView == fView);
101 maybeRegisterKeyboardHook();
109 DCHECK_F(iView == fView);
110 maybeUnregisterKeyboardHook();
120 maybeUnregisterKeyboardHook();
134 fFrame = fView->getFrame();
137 fFrame->registerKeyboardHook(
this);
147 fFrame->unregisterKeyboardHook(
this);
157 if(fOnKeyboardEventCallback)
158 fOnKeyboardEventCallback(event);
void viewRemoved(CView *iView) override
Overridden to handle detaching the keyboard hook from the frame.
Definition: GlobalKeyboardHook.h:107
void maybeRegisterKeyboardHook()
Definition: GlobalKeyboardHook.h:130
std::shared_ptr< SelfContainedViewListener > registerView(CView *iView) override
This method overrides SelfContainedViewListener::registerView to account for the fact that the frame ...
Definition: GlobalKeyboardHook.h:87
virtual void unregister()
You can call this method at anytime to unregister this class as the listener to the view that was pre...
Definition: SelfContainedViewListener.h:114
std::shared_ptr< GlobalKeyboardHook > onKeyboardEvent(KeyboardEventCallback iOnKeyboardEventCallback)
Call this method to register the callback invoked on a keyboard event.
Definition: GlobalKeyboardHook.h:64
static std::shared_ptr< GlobalKeyboardHook > create(CView *iView)
Factory method to create a global keyboard hook attached to the view.
Definition: GlobalKeyboardHook.h:77
void maybeUnregisterKeyboardHook()
Definition: GlobalKeyboardHook.h:143
void onKeyboardEvent(KeyboardEvent &event, CFrame *frame) override
Delegate to callback.
Definition: GlobalKeyboardHook.h:155
std::function< void(KeyboardEvent &)> KeyboardEventCallback
Used to register global keyboard hooks.
Definition: Types.h:67
void unregister() override
If you need to unregister the keyboard hook early (meaning before the view is deleted),...
Definition: GlobalKeyboardHook.h:118
Definition: CustomController.h:24
void viewAttached(CView *iView) override
Overridden to handle attaching the keyboard hook to the frame.
Definition: GlobalKeyboardHook.h:98
virtual std::shared_ptr< SelfContainedViewListener > registerView(CView *iView)
Registers this class as a view listener.
Definition: SelfContainedViewListener.h:134
The purpose of this class is to implement a view listener that is "self-contained":
Definition: SelfContainedViewListener.h:85
The CView class provides a method to handle keyboard events (CView::onKeyboardEvent) which only works...
Definition: GlobalKeyboardHook.h:54
std::shared_ptr< GlobalKeyboardHook > registerGlobalKeyboardHook(CView *iView)
This is the main entry point that you should use to register a global keyboard hook.
Definition: GlobalKeyboardHook.h:173