[DUG] Stringgrid - intercepting keys
John Bird
johnkbird at paradise.net.nz
Tue Oct 6 00:51:53 NZDT 2009
Yeah OnKeyDown does it.
Only hard part was finding how to detect the 'F' key...not in the usual VK_
lists
here is code for Ctrl+F and F3
procedure TForm1.strgrd1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (key = $46) and (ssCtrl in Shift) then
GridFind(strgrd1,FindStr,strFound);
if key = VK_F3 then GridFindNext(strgrd1,FindStr,strFound);
end;
(the gridfind routines do the actual search...)
Thanks for the hint....
John
> For other keys wouldn't you simply intercept those keyboard events using
> the
> "normal" windows keyboard event messages, OnKeyDown/Press etc, and handle
> those events on the specific tronol, rather than trying to intercept them
> on
> the form before they reach those controls.
>
> That may not be the answer you were looking for but it might set you on
> the
> right track (or elicit some further information about your specific
> implementation - such as why you can't handle key events on the control
> itself).
>
> Regards,
>
> Jolyon
>
>
> -----Original Message-----
> From: delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz]
> On
> Behalf Of John Bird
> Sent: Monday, 5 October 2009 17:26
> To: NZ Borland Developers Group - Delphi List
> Subject: [DUG] Stringgrid - intercepting keys
>
> For a long time I have been intercepting keys such as Escape/Enter/Tab no
> problem
>
> I have been wanting to put a simple search facility in a string grid, and
> would like to intercept Ctrl/F and F3.....but the code as I am using does
> not get them (D2007) - they are just ignored.
>
> Looks like the only characters I can intercept are Tab, Enter and
> Escape...
>
> Any suggestions?
>
>
> procedure TfrmTimeSh2.CMDialogKey(var Msg: TWMKEY);
> {
> This converts ENTER key messages to TAB key messages, provided a few
> conditions hold
> }
> begin
> if (ActiveControl is TCustomEdit)
> or (ActiveControl is TStringGrid)
> then
> begin
> ATPKeyDir:='';
> if Msg.CharCode = VK_RETURN then
> begin
> Msg.CharCode := VK_TAB;
> ATPKeyDir:='Next';
> end;
> if Msg.Charcode = VK_ESCAPE then
> begin
> Msg.CharCode := VK_TAB;
> ATPKeyDir:='Prev';
> end;
> if Msg.Charcode = VK_F2 then <=== never
> intercepted
> begin
> xcGridFind((ActiveControl as TStringGrid),FindStr,strFound);
> end;
> if Msg.Charcode = VK_F3 then <=== never intercepted
> begin
> xcGridFindNext((ActiveControl as TStringGrid),FindStr,strFound);
> end;
> end;
> inherited;
> end;
>
>
> John
>
>
> _______________________________________________
> NZ Borland Developers Group - Delphi mailing list
> Post: delphi at delphi.org.nz
> Admin: http://delphi.org.nz/mailman/listinfo/delphi
> Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject:
> unsubscribe
>
> _______________________________________________
> NZ Borland Developers Group - Delphi mailing list
> Post: delphi at delphi.org.nz
> Admin: http://delphi.org.nz/mailman/listinfo/delphi
> Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject:
> unsubscribe
More information about the Delphi
mailing list