|
Jamba
3.1.0
|
#include <GlobalKeyboardHook.h>
Inherits pongasoft::VST::GUI::Views::SelfContainedViewListener, and IKeyboardHook.
Public Member Functions | |
| GlobalKeyboardHook ()=default | |
| std::shared_ptr< GlobalKeyboardHook > | onKeyDown (KeyboardEventCallback iOnKeyDownCallback) |
| std::shared_ptr< GlobalKeyboardHook > | onKeyUp (KeyboardEventCallback iOnKeyUpCallback) |
| std::shared_ptr< SelfContainedViewListener > | registerView (CView *iView) override |
| void | unregister () override |
Public Member Functions inherited from pongasoft::VST::GUI::Views::SelfContainedViewListener | |
| SelfContainedViewListener ()=default | |
Static Public Member Functions | |
| static std::shared_ptr< GlobalKeyboardHook > | create (CView *iView) |
Static Public Member Functions inherited from pongasoft::VST::GUI::Views::SelfContainedViewListener | |
| template<typename T , typename ... Args> | |
| static std::shared_ptr< T > | create (CView *iView, Args &&...iArgs) |
Protected Member Functions | |
| void | maybeRegisterKeyboardHook () |
| void | maybeUnregisterKeyboardHook () |
| int32_t | onKeyDown (const VstKeyCode &iCode, CFrame *frame) override |
| int32_t | onKeyUp (const VstKeyCode &iCode, CFrame *frame) override |
| void | viewAttached (CView *iView) override |
| void | viewRemoved (CView *iView) override |
Protected Member Functions inherited from pongasoft::VST::GUI::Views::SelfContainedViewListener | |
| void | viewWillDelete (CView *iView) override |
Protected Attributes | |
| CFrame * | fFrame {} |
| KeyboardEventCallback | fOnKeyDownCallback {} |
| KeyboardEventCallback | fOnKeyUpCallback {} |
Protected Attributes inherited from pongasoft::VST::GUI::Views::SelfContainedViewListener | |
| std::shared_ptr< SelfContainedViewListener > | fThis {} |
| CView * | fView {} |
The CView class provides 2 methods to handle keyboard events (CView::onKeyDown and CView::onKeyUp) which only works as long as the view itself has focus. This helper class is designed to set a keyboard hook which is global so it will work whether the view has the focus or not. This class automatically handles registering the hook to the frame (when it becomes available) and unregistering it automatically as well. As an added bonus it is possible to dynamically change the callbacks after registration.
Typical usage would be to use Views::registerGlobalKeyboardHook this way:
// assuming we are writing a custom view
void initState(GUIState *iGUIState)
{
CustomView::initState(iGUIState);
Views::registerGlobalKeyboardHook(this)
->onKeyDown([this](VstKeyCode const &iKeyCode) -> auto {
if(iKeyCode.character == 'z')
{
// do something...
return CKeyboardEventResult::kKeyboardEventHandled;
}
return CKeyboardEventResult::kKeyboardEventNotHandled;
})
->onKeyUp([this](VstKeyCode const &iKeyCode) -> auto {
if(iKeyCode.character == 'z')
{
// do something else...
return CKeyboardEventResult::kKeyboardEventHandled;
}
return CKeyboardEventResult::kKeyboardEventNotHandled;
});
}
|
default |
public constructor for the sole purpose of std::make_shared. Do not call directly
|
inlinestatic |
Factory method to create a global keyboard hook attached to the view. You can use the convenient global function Views::registerGlobalKeyboardHook instead.
| iView | the target view of the keyboard events |
|
inlineprotected |
|
inlineprotected |
|
inline |
Call this method to register the callback invoked on a key down event. It replaces any other if there was one and is optional.
| iOnKeyDownCallback | see GUI::KeyboardEventCallback for the function definition |
|
inlineoverrideprotected |
Delegate to callback
|
inline |
Call this method to register the callback invoked on a key up event. It replaces any other if there was one and is optional.
| iOnKeyUpCallback | see GUI::KeyboardEventCallback for the function definition |
|
inlineoverrideprotected |
Delegate to callback
|
inlineoverridevirtual |
This method overrides SelfContainedViewListener::registerView to account for the fact that the frame (on which the global keyboard hook is registered) may already be available. We just don't know at which point in the lifecycle of the view, this method is being called.
Reimplemented from pongasoft::VST::GUI::Views::SelfContainedViewListener.
|
inlineoverridevirtual |
If you need to unregister the keyboard hook early (meaning before the view is deleted), you can do so by calling this method.
Reimplemented from pongasoft::VST::GUI::Views::SelfContainedViewListener.
|
inlineoverrideprotected |
Overridden to handle attaching the keyboard hook to the frame
|
inlineoverrideprotected |
Overridden to handle detaching the keyboard hook from the frame
|
protected |
|
protected |
|
protected |