Add a single hotkey handler entry to a widget
void PtAddHotkeyHandler( PtWidget_t *widget, unsigned key_sym_cap, unsigned key_mods, short flags, void *data, PtCallbackF_t *callback );
ph
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:
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 are 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 without specifying the Pt_HOTKEY_CHAINED flag, 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.
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 );
Photon
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | No |
Thread | No |
PtAddCallback(), PtAddCallbacks(), PtAddEventHandler(), PtAddEventHandlers(), PtAddFilterCallback(), PtAddFilterCallbacks(), PtRemoveHotkeyHandler()
PtCallbackInfo_t in the Photon Widget Reference
“Hotkey callbacks” in the Editing Resources and Callbacks in PhAB chapter of the Photon Programmer's Guide.