20 #include <vstgui4/vstgui/lib/cframe.h> 74 fOnKeyDownCallback = std::move(iOnKeyDownCallback);
75 return std::dynamic_pointer_cast<GlobalKeyboardHook>(shared_from_this());
87 fOnKeyUpCallback = std::move(iOnKeyUpCallback);
88 return std::dynamic_pointer_cast<GlobalKeyboardHook>(shared_from_this());
98 static std::shared_ptr<GlobalKeyboardHook>
create(CView *iView)
100 return SelfContainedViewListener::create<GlobalKeyboardHook>(iView);
108 std::shared_ptr<SelfContainedViewListener>
registerView(CView *iView)
override 111 maybeRegisterKeyboardHook();
121 DCHECK_F(iView == fView);
122 maybeRegisterKeyboardHook();
130 DCHECK_F(iView == fView);
131 maybeUnregisterKeyboardHook();
141 maybeUnregisterKeyboardHook();
155 fFrame = fView->getFrame();
158 fFrame->registerKeyboardHook(
this);
168 fFrame->unregisterKeyboardHook(
this);
176 int32_t
onKeyDown(
const VstKeyCode &iCode, CFrame *frame)
override 184 int32_t
onKeyUp(
const VstKeyCode &iCode, CFrame *frame)
override
void viewRemoved(CView *iView) override
Overridden to handle detaching the keyboard hook from the frame.
Definition: GlobalKeyboardHook.h:128
void maybeRegisterKeyboardHook()
Definition: GlobalKeyboardHook.h:151
std::shared_ptr< GlobalKeyboardHook > onKeyDown(KeyboardEventCallback iOnKeyDownCallback)
Call this method to register the callback invoked on a key down event.
Definition: GlobalKeyboardHook.h:72
std::shared_ptr< SelfContainedViewListener > registerView(CView *iView) override
This method overrides SelfContainedViewListener::registerView to account for the fact that the frame ...
Definition: GlobalKeyboardHook.h:108
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
static std::shared_ptr< GlobalKeyboardHook > create(CView *iView)
Factory method to create a global keyboard hook attached to the view.
Definition: GlobalKeyboardHook.h:98
void maybeUnregisterKeyboardHook()
Definition: GlobalKeyboardHook.h:164
void unregister() override
If you need to unregister the keyboard hook early (meaning before the view is deleted),...
Definition: GlobalKeyboardHook.h:139
Definition: CustomController.h:24
void viewAttached(CView *iView) override
Overridden to handle attaching the keyboard hook to the frame.
Definition: GlobalKeyboardHook.h:119
virtual std::shared_ptr< SelfContainedViewListener > registerView(CView *iView)
Registers this class as a view listener.
Definition: SelfContainedViewListener.h:134
int32_t onKeyUp(const VstKeyCode &iCode, CFrame *frame) override
Delegate to callback.
Definition: GlobalKeyboardHook.h:184
The purpose of this class is to implement a view listener that is "self-contained":
Definition: SelfContainedViewListener.h:85
The CView class provides 2 methods to handle keyboard events (CView::onKeyDown and CView::onKeyUp) wh...
Definition: GlobalKeyboardHook.h:62
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:202
std::function< CKeyboardEventResult(VstKeyCode const &)> KeyboardEventCallback
Used to register global keyboard hooks.
Definition: Types.h:68
std::shared_ptr< GlobalKeyboardHook > onKeyUp(KeyboardEventCallback iOnKeyUpCallback)
Call this method to register the callback invoked on a key up event.
Definition: GlobalKeyboardHook.h:85
int32_t onKeyDown(const VstKeyCode &iCode, CFrame *frame) override
Delegate to callback.
Definition: GlobalKeyboardHook.h:176