Re: keybd_event

From: Stark (franco.jommi_at_tin.it)
Date: 09/09/04


Date: Thu, 09 Sep 2004 13:53:01 GMT

I did not know the ComboBox1.Perform instruction; is that something like
IndexOf ?

"AlanGLLoyd" <alanglloyd@aol.com> ha scritto nel messaggio
news:20040908063042.10083.00000474@mb-m11.aol.com...
> In article <NFFZc.187878$OR2.8749904@news3.tin.it>, "Stark"
> <franco.jommi@tin.it> writes:
>
> >I've learned how to simulate sending characters to the keyboard, but I
only
> >know how to send numbers. I want to trap any character the user types in
an
> >edit window and send them to a ComboBox so that it opens and it
highligths
> >any line matching the typed digits.
> >
> >I was trying the following :
> >
> >Edit1KeyPress(Sender: TObject; var Key: Char);
> >var
> > Car: char;
> >begin
> > ComboBox1.SetFocus;
> > keybd_event(ord(Key), 0, 0, 0); //this only works with numbers
> > Edit1.SetFocus;
> > .....
> >end;
> >
> >How can I replace ord(Key) so that I can send any alphanumeric character
?
> >
>
> Don't forget ...
>
> 1 keybd_event should have a key up as well as a key down.
>
> 2 Its parameter is a KEY, not a character. Keys on a keyboard are a key
and are
> interpreted to a character.
>
> The following works for me in D3. If you have a later Delphi, the virtual
> key-codes VK_0 to VK_Z may be defined. Note that unlike characters, the
value
> for VK_SPACE is not part of the continuum with '0' to 'Z'.
>
> procedure TForm1.Edit1KeyUp(Sender: TObject; var Key: Word;
> Shift: TShiftState);
> var
> Idx : integer;
> const
> VK_0 : word = Ord('0'); // VK_<zero> not defined in D3
> VK_Z : word = Ord('Z'); // not defined in D3
> begin
> if (Key in [VK_SPACE,VK_0..VK_Z]) then begin
> Idx := ComboBox1.Perform(CB_FINDSTRING, 0,
integer(PChar(Edit1.Text)));
> if (Idx = CB_ERR) then
> ComboBox1.DroppedDown := false
> else begin
> ComboBox1.DroppedDown := true;
> ComboBox1.ItemIndex := Idx;
> ComboBox1.Refresh;
> end; {if (Idx = CB_ERR) else}
> end;
> end;
>
> Alan Lloyd
> alanglloyd@aol.com