SendKey doesn't work with FormKeyUp

From: GB Blanchard (1122_at_1122noexiste.net)
Date: 04/05/04


Date: Mon, 05 Apr 2004 07:34:54 GMT


 This app sends a char to the window that the user has previously
clicked on. I'm getting the window as follows:

procedure TMainForm.Timer1Timer(Sender: TObject);
var
   winname : string;
begin
  HWndActive := GetForegroundWindow;
  winname := GetWindowTitleText(HWndActive);
  if UpperCase(winname) = 'MYPROGRAM' then
  begin
    HWndActive := 1;
    Exit;
  end;
  HWndActive := GetHandleFromWindowTitle(winname);
  PreviousHWndActive := HWndActive;
end; //Timer1Timer

and processing it here:

procedure TMainForm.SendKeyClick(Sender: TObject);
var
  CharToInsert : char;
begin
  SetForeGroundWindow(PreviousHwndActive);

  if Sender is TSpeedButton then CharToInsert :=
TSpeedButton(Sender).Caption[1]
  else CharToInsert := ShortCutChar; //global

  PostCharToKBD(CharToInsert);
end; //SendKeyClick

Everything works fine when Sender is one of the TSpeedButtons I've
created. The problem is that when I try to post a char using
CharToInsert (see code below), CharToInsert is processed properly
but doesn't show up in the target app although the target app gets
focus and the cursor. To confuse the issue even more, it DOES show
up in my Unit1.pas when I'm using the debugger. I don't know what
else to look at. Any advice will be appreciated. In order to avoid
clutter here (and the fact that I'm not sure that it is the
culprit), I've posted the somewhat lengthy PostCharToKBD code at:
http://www.braser.com/sendkey.txt

procedure TMainForm.FormKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 if (ssCtrl in Shift) then
    case key of
    51: //'3'
    begin
      ShortCutChar := 'X';
      SendKeyClick(self);
    end;
    end; //case
end; //FormKeyUp

-- 
Brad Blanchard
Website: http://www.braser.com


Relevant Pages

  • Re: Serial port monitoring
    ... All you want to do is read a character from a serial port. ... I would then have a loop that checks for char in serial buffer. ... Everything is done within my app. ...
    (microsoft.public.vc.mfc)
  • Re: Calculate the string statement
    ... verkn:(vkn:char; ... funkt:(fkt:string; ... var fkt,dfkt: p; ... var fehler: boolean; ...
    (comp.lang.pascal.borland)
  • Re: Evaluate constant parts of expressions in Linq
    ... I have column MyCharColumn of type CHAR in database. ... var q = from p in db.Products ... To fix compile error I changed query to ... How to fix without using temporary string variable? ...
    (microsoft.public.dotnet.languages.csharp)
  • Passing void pointer to p_thread that is a Char
    ... where var is a char variable. ... test.c:58: warning: cast to pointer from integer of different size. ... Now I thought that when it was a void I could pass anything? ... works when I use an int, but in this case I wanted to use a char. ...
    (comp.lang.c)
  • Re: Passing void pointer to p_thread that is a Char
    ... where var is a char variable. ... works when I use an int, but in this case I wanted to use a char. ... Im trying to pass a void thats a char. ...
    (comp.lang.c)