Solved

typing component

Posted on 2001-09-02
9
148 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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 160 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Intraweb submit form as a POST request 4 303
Newbie Thread Programming 1 151
FMX enumerated colours 2 98
I want to use librsync in my Delphi backup application. 3 47
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

776 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