Key click sound

Please use this Board for QBasic related requests ( file research, programming, etc.)

Moderators:Administrator, Global Moderator

Post Reply
John_Schofield
Full Member
Posts:36
Joined:Tue Mar 18, 2003 3:04 am
Location:Lancashire, UK
Contact:
Key click sound

Post by John_Schofield » Thu Oct 04, 2007 12:30 am

Does anyone have a code snippet which would generate a click sound each time a key is pressed when typing a string of characters?

I can make a beep when I press "Enter" or but I'd like to be able to hear a click each time a key is pressed as a string is built up as well.

Is that possible?

Cheers!

Valerie
Sr. Member
Posts:54
Joined:Wed Dec 15, 2004 8:10 am
Location:Coromandel, NZ

Key click sound

Post by Valerie » Thu Oct 04, 2007 10:55 am

Hello again John.

This is probably not what you want but the best I have come up with so far:

Code: Select all

CLS

DO
a$ = INPUT$(1)
  PLAY "T255 L64 g-"
  b$ = b$ + a$
  LOCATE 1, 1: PRINT b$
LOOP

Note that the loop is closed, leave it up to you to sort out an appropriate exit. You can also adjust the speed and key to suit.

Regards

Valerie.

John_Schofield
Full Member
Posts:36
Joined:Tue Mar 18, 2003 3:04 am
Location:Lancashire, UK
Contact:

Post by John_Schofield » Thu Oct 04, 2007 1:02 pm

Thanks Valerie

Much appreciated.

I have another solution I thought of last night so I'll try them both!

Regards

Ralph
QBasic God
Posts:134
Joined:Sat Nov 06, 2004 2:27 am
Location:Katy, Texas

Post by Ralph » Thu Oct 04, 2007 7:28 pm

Hello, Valerie. I don't know why the PLAY line didn't respond for me. I changed that line to
SOUND 255,1
and that worked well.
Ralph. Running QuickBASIC Version 4.5, Windows XP Home Edition, Version 2002, Service Pack 2, and HP LaserJet 4L printer.

Valerie
Sr. Member
Posts:54
Joined:Wed Dec 15, 2004 8:10 am
Location:Coromandel, NZ

Post by Valerie » Thu Oct 04, 2007 11:25 pm

Hello Ralph.

I don't understand why Play didn't work for you either. I'm getting the click thru' my soundcard not from the inbuilt speaker.

I had tried Sound before posting but thought that Play was a tad faster, am probably wrong on that. Also Play gives me more of a click than a tone.

Beep also works for me but is only good for very s-l-o-w typing.

BTW am using QB 4.5 in XP Home cmd.exe although Command.com made only one difference, that being that Beep no longer worked.

Regards

Valerie

John_Schofield
Full Member
Posts:36
Joined:Tue Mar 18, 2003 3:04 am
Location:Lancashire, UK
Contact:

Post by John_Schofield » Thu Oct 04, 2007 11:48 pm

I've found that Valerie's PLAY instructions gives a pretty quiet click which is ok with a silent keyboard but not my clacky old thing here at home - the keys make more noise!!

By experimentation, I've settled on SOUND 950, .2 as being just about right for my particular requirement in a potentially slightly noisy enviromnent. If I need to make it more audible I just extend the duration to .5 or something and/or slightly reduce the frequency.

Both come out through the built in speaker rather than the sound card, which fits the bill for me.

I've managed to squeeze the SOUND instruction into a section of code I found in an old program which builds a string from key presses so this works fine for me now.

Thanks for your help.

Valerie
Sr. Member
Posts:54
Joined:Wed Dec 15, 2004 8:10 am
Location:Coromandel, NZ

Post by Valerie » Sat Oct 06, 2007 5:18 am

Thanks for your response John. As I now am using XP perhaps that has something to do with the soundcard being used. Adjusting the Volume control allows for quiet or deafening clicks.

Glad you found a solution which suits your purpose.

V.

John_Schofield
Full Member
Posts:36
Joined:Tue Mar 18, 2003 3:04 am
Location:Lancashire, UK
Contact:

Post by John_Schofield » Sat Oct 06, 2007 3:24 pm

cheers - I'm still stuck in the days of Win98 foir my laptop selection!

Post Reply