Jamba C++ API 7.5.0
Loading...
Searching...
No Matches
GlobalKeyboardHook Class Reference

The CView class provides a method to handle keyboard events (CView::onKeyboardEvent) which only works as long as the view itself has focus. More...

#include <GlobalKeyboardHook.h>

Inherits SelfContainedViewListener, and IKeyboardHook.

Public Member Functions

 GlobalKeyboardHook ()=default
 public constructor for the sole purpose of std::make_shared.
std::shared_ptr< GlobalKeyboardHookonKeyboardEvent (KeyboardEventCallback iOnKeyboardEventCallback)
 Call this method to register the callback invoked on a keyboard event.
std::shared_ptr< SelfContainedViewListenerregisterView (CView *iView) override
 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.
void unregister () override
 If you need to unregister the keyboard hook early (meaning before the view is deleted), you can do so by calling this method.
Public Member Functions inherited from SelfContainedViewListener
 SelfContainedViewListener ()=default
 The constructor which unfortunately has to be declared public for the purpose of a creating a shared instance.

Static Public Member Functions

static std::shared_ptr< GlobalKeyboardHookcreate (CView *iView)
 Factory method to create a global keyboard hook attached to the view.
Static Public Member Functions inherited from SelfContainedViewListener
template<typename T, typename ... Args>
static std::shared_ptr< T > create (CView *iView, Args &&...iArgs)
 This is the main method that should be used to create an instance of this class.

Protected Member Functions

void maybeRegisterKeyboardHook ()
void maybeUnregisterKeyboardHook ()
void onKeyboardEvent (KeyboardEvent &event, CFrame *frame) override
 Delegate to callback.
void viewAttached (CView *iView) override
 Overridden to handle attaching the keyboard hook to the frame.
void viewRemoved (CView *iView) override
 Overridden to handle detaching the keyboard hook from the frame.
Protected Member Functions inherited from SelfContainedViewListener
void viewWillDelete (CView *iView) override
 Called by the view itself when it is going to be deleted.

Protected Attributes

CFrame * fFrame {}
KeyboardEventCallback fOnKeyboardEventCallback {}
Protected Attributes inherited from SelfContainedViewListener
std::shared_ptr< SelfContainedViewListenerfThis {}
CView * fView {}

Detailed Description

The CView class provides a method to handle keyboard events (CView::onKeyboardEvent) 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)
{
Views::registerGlobalKeyboardHook(this)->onKeyboardEvent([this] (KeyboardEvent &iEvent) {
if(iEvent.character == 'z'
&& iEvent.type == VSTGUI::EventType::KeyDown
&& iEvent.modifiers.empty())
{
zoomToSelection();
iEvent.consumed = true;
}
});
Definition GUIState.h:43
virtual void initState(GUIState *iGUIState)
Called during initialization.
Definition ParamAware.cpp:37
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:174

Constructor & Destructor Documentation

◆ GlobalKeyboardHook()

GlobalKeyboardHook ( )
default

public constructor for the sole purpose of std::make_shared.

Do not call directly

Member Function Documentation

◆ create()

std::shared_ptr< GlobalKeyboardHook > create ( CView * iView)
inlinestatic

Factory method to create a global keyboard hook attached to the view.

You can use the convenient global function Views::registerGlobalKeyboardHook instead.

Parameters
iViewthe target view of the keyboard events
Returns
the helper class to register callback on

◆ maybeRegisterKeyboardHook()

void maybeRegisterKeyboardHook ( )
inlineprotected

◆ maybeUnregisterKeyboardHook()

void maybeUnregisterKeyboardHook ( )
inlineprotected

◆ onKeyboardEvent() [1/2]

void onKeyboardEvent ( KeyboardEvent & event,
CFrame * frame )
inlineoverrideprotected

Delegate to callback.

◆ onKeyboardEvent() [2/2]

std::shared_ptr< GlobalKeyboardHook > onKeyboardEvent ( KeyboardEventCallback iOnKeyboardEventCallback)
inline

Call this method to register the callback invoked on a keyboard event.

It replaces any other if there was one and is optional.

Parameters
iOnKeyboardEventCallbacksee GUI::KeyboardEventCallback for the function definition
Returns
itself (as a shared pointer) for chaining calls (see example at the top)

◆ registerView()

std::shared_ptr< SelfContainedViewListener > registerView ( CView * iView)
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 SelfContainedViewListener.

◆ unregister()

void unregister ( )
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 SelfContainedViewListener.

◆ viewAttached()

void viewAttached ( CView * iView)
inlineoverrideprotected

Overridden to handle attaching the keyboard hook to the frame.

◆ viewRemoved()

void viewRemoved ( CView * iView)
inlineoverrideprotected

Overridden to handle detaching the keyboard hook from the frame.

Member Data Documentation

◆ fFrame

CFrame* fFrame {}
protected

◆ fOnKeyboardEventCallback

KeyboardEventCallback fOnKeyboardEventCallback {}
protected

The documentation for this class was generated from the following file: