QNX RTOS v4 Knowledge Base
QNX RTOS v4 Knowledge Base
Title |
Adding a hotkey handler |
Ref. No. |
QNX.000009892 |
Category(ies) |
Development |
Issue |
We want to add a hotkey callback to process the Enter key when pressed on a text box in PhAB. Regardless of whether or not we created the widget and callback in code, or in PhAB, we cannot get the application to invoke the hotkey callback on the Enter key or any other key for that matter.
What if we want to hotkey the SHIFT key rather than the ENTER key?
|
Solution |
You do not need a callback for Enter key, because when you press it, the widget's Pt_CB_ACTIVATE callback is invoked.
If you want to hotkey the 'SHIFT' key rather than 'ENTER' key, here is an explanation. This example illustrate a frequently misunderstood aspect of default hotkey bahaviour, which is: A hotkey is processed AFTER all widgets have been given the key event. If the widget consumes the event, no hotkey callback is called. When a text field has focus, the enter key, arrow keys, space and all displayable characters won't work as hotkeys because the widget consumes those events. This is usually the desired behaviour (consider editing in an application which has hotkeys defined for all the arrow keys).
You can force the hotkey processing to be done by setting the Pt_HOTKEYS_FIRST flag on a container (window, pane...) that contains the widgets which would normally consume your hotkey events.
Setting this flag on the window guarantees all hotkey processing is done prior to any widget getting a shot at a key event.
So, for your text field example, if you want to attach a hotkey to the text field, you would have to make the text field selectable (you'd probably want to set the Pt_SELECT_NOREDRAW widget flag).
Often it's not important to which widget a callback is connected to. In those cases just attach the hotkey to the window.
|
|