Solved

typing component

Posted on 2001-09-02
9
147 Views
Last Modified: 2010-04-06
i am using delphi 5 pro and would like to know if there is a component available that allows me to:

type text one letter at a time and play a sound while each letter is being typed. The only think i can relate to is in the film "the MATRIX" where the black screen comes up on neo's computer and it starts to type a message one letter at a time with sound effects!!


AM i asking for too much

PLEASE can someone help


thanks
0
Comment
Question by:marksmall
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 22

Expert Comment

by:mnasman
Comment Utility
Hello

use the PlaySound api to play sound when you press on any key, drop memo on ur form and write this code onkeypress event

// add mmssytem to unit clause
uses mmsystem;

procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
begin
  PlaySound('c:\sound.wav',0,Snd_ASYNC)
end;


0
 

Author Comment

by:marksmall
Comment Utility
thanks mnasman, but what about the typing component?

any ideas?
0
 
LVL 17

Expert Comment

by:inthe
Comment Utility
i find playsound seems to take to long for this sort of thing , i tried commenting it out and using messagebeep instead for a standard beep and seemed to work faster.
(actually too fast hence the sleep() to control it a bit


//uses mmsystem;

procedure TForm1.Button1Click(Sender: TObject);
Var
Str : String;
i : integer;
begin
Str := 'Hi, im a typing like in the Matrix demo';
memo1.Clear;
for i := 0 to length(Str) do
 begin
  memo1.Text := memo1.Text + Str[i];
  memo1.Repaint;
 if Str[i] <> ' ' then
 messagebeep(MB_OK);
 sleep(100);
//  PlaySound(pChar('SYSTEMEXCLAMATION'),0,SND_SYNC);
 end;
end;
0
 
LVL 22

Expert Comment

by:mnasman
Comment Utility
Barry

 you are right but that's happen cuz you using Playsound with SND_SYNC, that's will play the sound and when finish playing will back to your application, but if you use Snd_ASYNC, that's will start to play the sound and back to the application

 SND_SYNC  
 Synchronous playback of a sound event.  PlaySound  returns after the sound event completes.

SND_ASYNC
 
 The sound is played asynchronously and  PlaySound  returns immediately after beginning the sound. To terminate an  asynchronously played waveform sound, call  PlaySound  with  pszSound  set to NULL.

0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 44

Expert Comment

by:bruintje
Comment Utility
there should be more but this is one
http://www.pcmag.com/article/0,2997,s=1478&a=4232,00.asp?download_url=http://common.ziffdavisinternet.com/download/0/1047/keytick.zip

it needs registering, but you can take a look at the source

:O)Bruintje
0
 
LVL 17

Expert Comment

by:inthe
Comment Utility
Mnasman
cheers my mistake ;-)
0
 

Expert Comment

by:DelFreak
Comment Utility
Listening...
0
 

Author Comment

by:marksmall
Comment Utility
thanks inthe/barry, you get the points, but is it possible to put this code into a procedure so that if i want to add text to this memo over and over again i don't have to type in all this code

ie

on buttonA click

memo1.text := whatever i want to say

on buttonB click

memo1.text := more text

and so on, and is it possible to make this text effect work in a LISTBOX and a label?

I have posted more points 4 u, in hoping that u can provide code to do this!!!


cheers
0
 
LVL 17

Accepted Solution

by:
inthe earned 160 total points
Comment Utility
here some stuff:
memos,labels etc are easy enough listboxes are a bit diferent and could be done many ways ,because they can have items,subitems,columns etc so below is only one way of many but you get the general idea ;-)

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls , mmsystem;
type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    Edit1: TEdit;
    Label1: TLabel;
    ListBox1: TListBox;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  procedure AutotypeMemo(Str : String);
  procedure AutotypeLabel(Str : String);
  procedure AutotypeListbox(Str : String;itemno: integer);
  end;


var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.AutotypeMemo(Str : String);
Var
i : integer;
begin
Str := Str + #13#10;
//makes a new line or use ' ' to just add a space
for i := 0 to length(Str) do
begin
 memo1.Text := memo1.Text + Str[i];
if (Str[i] in ['0'..'9','a'..'z','A'..'Z']) then
 begin  //dont beep on returns or spaces
  sleep(300);
  PlaySound(pChar('SYSTEMEXCLAMATION'),0,SND_ASYNC);
 end;
 memo1.Repaint;
 Application.Processmessages;
end;
end;

procedure TForm1.AutotypeLabel(Str : String);
Var
i : integer;
begin
Str := ' ' + Str; //add a space first
for i := 0 to length(Str) do
begin
 label1.caption := label1.caption + Str[i];
 //dont beep on spaces
if (Str[i] in ['0'..'9','a'..'z','A'..'Z']) then
 begin
  sleep(300);
  PlaySound(pChar('SYSTEMEXCLAMATION'),0,SND_ASYNC);
 end;
 label1.Repaint;
 Application.Processmessages;
end;
end;

procedure TForm1.AutotypeListbox(Str : String; itemno : integer);
Var
i : integer;
begin
Str := ' ' + Str; //add a space first
for i := 0 to length(Str) do
begin
 listbox1.Items[itemno] := listbox1.Items[itemno] + Str[i];
if (Str[i] in ['0'..'9','a'..'z','A'..'Z']) then
 begin
  sleep(300);
  PlaySound(pChar('SYSTEMEXCLAMATION'),0,SND_ASYNC);
 end;
 listbox1.Repaint;
 Application.Processmessages;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
//AutotypeMemo(edit1.Text);
//AutotypeLabel(edit1.Text);
listbox1.items.add(' ');  //add two items
listbox1.Items.add(' ');
AutotypeListbox('item1 caption',0); //listbox item is zero-based
AutotypeListbox('item2 caption',1);
end;

end.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now