SendKey doesn't work with FormKeyUp
From: GB Blanchard (1122_at_1122noexiste.net)
Date: 04/05/04
- Next message: Rashid: "Re: Menu Items"
- Previous message: Kenneth Payne: "Re: OLE Automation: Generating a Footer"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Rashid: "Re: Menu Items"
- Previous message: Kenneth Payne: "Re: OLE Automation: Generating a Footer"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|