?
Solved

typing component

Posted on 2001-09-02
9
Medium Priority
?
158 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:Mohammed Nasman
ID: 6448722
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
ID: 6448732
thanks mnasman, but what about the typing component?

any ideas?
0
 
LVL 17

Expert Comment

by:inthe
ID: 6448833
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6448912
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
 
LVL 44

Expert Comment

by:bruintje
ID: 6449020
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
ID: 6449181
Mnasman
cheers my mistake ;-)
0
 

Expert Comment

by:DelFreak
ID: 6449796
Listening...
0
 

Author Comment

by:marksmall
ID: 6450424
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 640 total points
ID: 6451422
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Loops Section Overview
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month16 days, 22 hours left to enroll

862 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