Recent

Author Topic: simulate button click with other key + play sound  (Read 2593 times)

tomino

  • New Member
  • *
  • Posts: 28
simulate button click with other key + play sound
« on: April 22, 2014, 08:04:16 pm »
hi , after every input to edit i have to click button again , i know maybe are more ways but especially in my program it has to be "R" which i click and it will simulate button click and then

i have in program some If then else ,

if ..... then (and here i want to play the sound which i can store on my usb do what is the command to play sound ... ? but i dont want it to open windows media player ... i want it will instantly play sound one time

thanks )

and also after writing in edit and hiting R it will automaticaly clear edit ... how to do it

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: simulate button click with other key + play sound
« Reply #1 on: April 23, 2014, 01:19:53 pm »
Set KeyPreview of the form to True
In OI doubleclick on OnKeyPress, this will create an OnKeyPress handler, in this handler just invoke the code that is executed when one clicks the button:

Untested code...
Code: [Select]
procedure TForm1.PlayTheSound;
begin
  ////this routine does all the sound playing, you'll have to implement that yourself
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  PlayTheSound;
end;

procedure TForm1.Form1KeyPress(Sender: TObject; var Key: Char);
begin
  if Key = 'R' then
  begin
    Key := #0; //suppress keystroke from further handling by e.g. the edit
    PlayTheSound;
  end;
end;

You could also have an Action associated with the button and set it's shortcut to 'R' maybe.

Bart

tomino

  • New Member
  • *
  • Posts: 28
Re: simulate button click with other key + play sound
« Reply #2 on: April 23, 2014, 03:53:35 pm »
Error: method identifier expected


i did : Set KeyPreview of the form to True , In OI doubleclick on OnKeyPress too


procedure TForm1.Form1KeyPress(Sender: TObject; var Key: Char);
begin
  if Key = 'R' then Key := 82
end;
« Last Edit: April 23, 2014, 04:21:02 pm by tomino »

 

TinyPortal © 2005-2018