?
Solved

typing component

Posted on 2001-09-02
9
Medium Priority
?
156 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

649 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