RSS Forums RSS
Please support our Pascal and Delphi advertiser: Programming Forums

Emulating a keyboard key press

Join Date: May 2005
Posts: 41
Reputation: mrmike is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
mrmike mrmike is offline Offline
Light Poster

Re: Emulating a keyboard key press

  #7  
Sep 15th, 2005
The labels are not required, but were used for testing, as you change from the editbox to the button, the editbox will lose focus, and the button will become focused, thus giving you an issue if using more than one edit box.

The procedure ButtonPressed uses the TAG option to assign the ascii codes for each button pressed to be displayed in the correct edit box, which is obtained from the EditClick procedure. Remember to set the OnClick event for each of the corresponding buttons.

procedure ButtonPressed(Sender: TObject);
var
index   :Integer;
result  :Integer;
begin
result:=0;
for index:=0 to ControlCount -1 do
 begin
 if (Controls[index] is TButton) and TButton(Controls[index]).Focused then
 result:=index;
end;
    Label2.Caption:='Button Active '+Char(TButton(Controls[result]).Tag);
    TEdit(Controls[cureditbox]).Text:=TEdit(Controls[cureditbox]).Text+Char(TButton(Controls[result]).Tag);
end;

As the focus will change from the editbox selected to the button being pressed, the following procedure will handle which box will be updated when pressing button. You will need to set the OnClick event for each edit box to point to this procedure.

procedure EditClick(Sender: TObject);
var
 loop :integer;
begin
 cureditbox:=1;
for loop:=0 to ControlCount -1 do
begin
 if (Controls[loop] is TEdit) and TEdit(Controls[loop]).Focused then
  cureditbox:=loop;
end;
Label1.Caption:='Edit Box Active '+Char(TEdit(Controls[cureditbox]).Tag+48);
end;

regards
mrmike
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 5:20 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC