Note that there are some explanatory texts on larger screens.

plurals
  1. POForwarding keyboard events from one Windows control to another
    primarykey
    data
    text
    <p>In Delphi XE, I'm trying to implement an "instant search" feature - one that resembles Firefox's "search as you type" somewhat, but is better illustrated by a similar feature in an open source clipboard extender, <a href="http://ditto-cp.sourceforge.net/" rel="noreferrer">Ditto</a>:</p> <p><img src="https://i.stack.imgur.com/5I8db.png" alt="Ditto search interface"></p> <p>There is a list of items that handles typical navigation events. However, any alphanumeric keys as well as navigation and editing commands (right/left arrows, shift+arrows, backspace, delete etc.) should be rerouted to the edit box below the list. An OnChange event of the edit box will trigger a refresh of the list.</p> <p>The point of the UI is that user does not have to tab or shift-tab between the controls. The two controls (the list and the edit box) should 'feel" as if they were a single control. The behavior of the search UI should <strong>not</strong> be contingent on which control has focus.</p> <p>It seems my best option is to <strong>forward certain keyboard events</strong> from the list control (I'm using <a href="http://www.devexpress.com/Products/VCL/ExQuantumTreeList/" rel="noreferrer">TcxTreeList</a>) to the edit box, and forward a handful of navigation keys from the edit box to the list. How can I achieve that?</p> <p><em>Notes:</em> </p> <ol> <li><p>TcxTreeList supports incremental search of course, but this is not what I'm after. The search goes to an SQLite database and looks for substring matches. The list displays only the matching items from the db.</p></li> <li><p>There is some overlap, e.g. both controls would normally handle VK_HOME and VK_END, but that's OK - in this case the keys would go to the list. I'll need to decide whether to forward each individual keypress, or handle it in the control that received it.</p></li> </ol> <p><strong>On Edit:</strong> One obvious way seemed to be to invoke the respective KeyDown, KeyUp and KeyPress methods of the edit control, like so:</p> <pre><code>type THackEdit = class( TEdit ); procedure TMainForm.cxTreeList1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin THackEdit( edit1 ).KeyDown( Key, Shift ); end; </code></pre> <p>Unfortunately, this has no effect. My guess is TEdit won't process key events unless it is focused. Using SendMessage( THackEdit( edit1 ).Handle, WM_KEYDOWN, Key, 0 ) has no effect, either.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload