[Previous] [Contents] [Index] [Next]

PtAddHotkeyHandler()

Add a single hotkey handler entry to a widget

Synopsis:

void PtAddHotkeyHandler( PtWidget_t *widget,
                         unsigned  key_sym_cap,
                         unsigned  key_mods,
                         short flags,
                         void *data,
                         PtCallbackF_t *callback );

Description:

This function adds the specified callback to the Pt_CB_HOTKEY callback list that belongs to the specified widget. The widget will invoke this callback whenever all three of the following conditions are met:

The flags argument can contain the following:

Pt_HOTKEY_SYM
Interpret key_sym_cap as a key sym; the default is to interpret it as a key cap.
Pt_HOTKEY_IGNORE_MODS
Ignore the key_mods argument. This flag is typically used in menus, where you want both upper- and lowercase letters to be accepted as hot keys.

The callback argument points to a function that takes this form:

int (*callback)(PtWidget_t *, void *, PtCallbackInfo_t *)

Hotkey entries are stacked. As a result, the last hotkey attached is the first to be checked.

If a hotkey callback is triggered, the key event is consumed and no other hotkey callbacks will be invoked. If callback is NULL, the widget's Pt_CB_ACTIVATE callback list is invoked when the hotkey is pressed.

Note the following:

Hotkeys are handled at the window level. So if two widgets within the same window happen to register the same hotkey definition, only the callback for the last duplicate hotkey is invoked.

Hotkey callbacks are automatically registered when the owner widget is realized, and automatically removed when the owner widget is unrealized.

Examples:

PtWidget_t *widget1, *widget2, *widget3,  *window;
...
// add a hotkey to the window on the key sym 
// for Escape.

PtAddHotkeyHandler( window, Pk_Escape, 0,
                    Pt_HOTKEY_SYM, 
                    NULL, escape_callback );

// add a hotkey handler for the digit "1" to                      
// widget1 that ignores the states of Ctrl/Alt/Shift.

PtAddHotkeyHandler( widget1, Pk_1, 0,
                    Pt_HOTKEY_IGNORE_MODS, 
                    NULL, one_callback );

// add a hotkey handler for the digit "2" to widget2 
// that will be triggered only if the CTRL modifier            
// is pressed when "2" is hit.

PtAddHotkeyHandler( widget2, Pk_2, Pk_KM_CTRL, 0, 
                    NULL, ctrl_2_callback );

// add a hotkey handler for the digit 3 to widget3. 
// When triggered, widget3's activate callback will be 
// invoked with a reason type of Pt_CB_ACTIVATE and a
//  reason_subtype of Pt_CB_HOTKEY.

PtAddHotkeyHandler( widget3, Pk_3, 0, 0, NULL, NULL );

// Remove the hotkey handlers.

PtRemoveHotkeyHandler( window, Pk_Escape, 0,
                       Pt_HOTKEY_SYM, 
                       NULL, escape_callback );
PtRemoveHotkeyHandler( widget1, Pk_1, 0,
                       Pt_HOTKEY_IGNORE_MODS, 
                       NULL, one_callback );
PtRemoveHotkeyHandler( widget2, Pk_2, Pk_KM_CTRL, 0, 
                       NULL, ctrl_2_callback );
PtRemoveHotkeyHandler( widget3, Pk_3, 0, 0,
                       NULL, NULL );

Classification:

Photon

Safety:
Interrupt handler No
Signal handler No
Thread No

See also:

PtRemoveHotkeyHandler(), PtAddCallback(), PtAddCallbacks(), PtAddEventHandler(), PtAddEventHandlers()

"Hotkey callbacks" in the Editing Resources and Callbacks in PhAB chapter of the Photon Programmer's Guide.


[Previous] [Contents] [Index] [Next]