Solved

typing component

Posted on 2001-09-02
9
150 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to center only a line in richedit? 4 77
oracle global variables 4 80
When i run adoquery my application freezes 26 207
TAction.OnAfterExecute? 2 31
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…

737 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