Re: keybd_event

From: AlanGLLoyd (alanglloyd_at_aol.com)
Date: 09/08/04


Date: 08 Sep 2004 10:30:42 GMT

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



Relevant Pages

  • Re: Which special ability? [O, YACD]
    ... IF you can sustain the low armour, this can keep you in a melee ... Probably not often as a ranger; might be worth it if you had some ... Trap setting can be very powerful, but it's kind of a lifestyle ... My second character just reached level 20. ...
    (rec.games.roguelike.angband)
  • 4E:- Previews for May & beyond (long)
    ... you command an ally to attack. ... Trap or Hazard? ... The character notices trigger plates around the chamber. ... Then, the Monster Manual ...
    (rec.games.frp.dnd)
  • Re: Search traps?
    ... Blinded: The character cannot see. ... and takes a -4 penalty on Search checks and on most Strength- ... Disable device is Int based, ... that allows him to tell there's a trap there. ...
    (rec.games.frp.dnd)
  • Re: shell: trap any letter
    ... > I wanna use trap to trap a paticular ... The KEYBD trap can be used to intercept keys as they are typed ... and change the characters that are actually seen by the shell. ... characters when the first character is ESC) is entered while ...
    (comp.unix.shell)