Please support our Pascal and Delphi advertiser: Programming Forums
![]() |
•
•
Join Date: Jul 2005
Posts: 18
Reputation:
Rep Power: 4
Solved Threads: 0
Just wondering if it is possible to do this? I am writing a program for a touchscreen monitor and would like an onscreen keypad. Is there any way to pass a key by pressing a button? For example, I press button '1' on the virtual keypad and I want the number 1 to appear in whatever editbox etc is selected at the time.
Thanks
Sean Bedford
Thanks
Sean Bedford
•
•
Join Date: May 2005
Posts: 41
Reputation:
Rep Power: 4
Solved Threads: 0
if using an edit box then don't need to use writeln
for each button give it a tag number corresponding to the ascii value you want it to display (ie 0 = 48, 1 = 49, 2 = 50, etc)
create the following procedure
and then set the OnClick event for each button to go to ButtonPressed
hope this helps
mrmike
for each button give it a tag number corresponding to the ascii value you want it to display (ie 0 = 48, 1 = 49, 2 = 50, etc)
create the following procedure
procedure TForm1.ButtonPressed(Sender: TObject); var index :Integer; begin for index:=0 to ControlCount -1 do begin if Controls[index] is TWinControl then if (Controls[index] as TWinControl).Focused then Edit1.Text:=Edit1.Text+Char(((Controls[index] as TWinControl).Tag) end; end;
hope this helps
mrmike
•
•
Join Date: Aug 2005
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 0
Try checking the Application object to see if it has an available property/method to return the control that has focus...
You can also revise the sample code (above) to check for TCustomEdit (instead of TWinControl), i.e.
...
if (Controls[index] is TCustomEdit) and TCustomEdit(Controls[index]).Focused then
result := Controls[index];
...
You can also revise the sample code (above) to check for TCustomEdit (instead of TWinControl), i.e.
...
if (Controls[index] is TCustomEdit) and TCustomEdit(Controls[index]).Focused then
result := Controls[index];
...
•
•
Join Date: May 2005
Posts: 41
Reputation:
Rep Power: 4
Solved Threads: 0
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.
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.
regards
mrmike
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
•
•
Join Date: Jul 2005
Posts: 18
Reputation:
Rep Power: 4
Solved Threads: 0
Right, what ive done is create a procedure which sets a var of type TEdit to the correct box, then upon clicking say, key number 1, it does
This works fine as long as the box is clicked before you try to use the keypad.
Now, the only problem I have is if users do tab to move between boxes - is there any way to make a focus on an edit box force it to do the onclick event?
focusededitbox.Text:=focusededitbox.Text+inttostr(1)
This works fine as long as the box is clicked before you try to use the keypad.
Now, the only problem I have is if users do tab to move between boxes - is there any way to make a focus on an edit box force it to do the onclick event?
![]() |
Other Threads in the Pascal and Delphi Forum
- Previous Thread: Creating a program to run under various OS
- Next Thread: report in quickreport
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)





Linear Mode