473,385 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

avoiding beep sound if(event.altKey)

Ivo
In an Win/IE-only application, some checkboxes and the like have been
assigned accesskeys, so pressing alt+w focuses a checkbox, alt+b another.
This is very convenient. However, when the checkboxes are hidden, for
example because they are in a div styled "display:none", pressing the magic
key combination does not work of course, but instead Windows generates an
warning beep, a sound. Now I have written a function that will toggle the
elements for me when they are out of view, but the beep still occurs.
Does anyone have a bright idea how to evade the warning?

function keyd(e) {
e=e||window.event; var k=e.keyCode;
k=String.fromCharCode(k).toLowerCase();
if( k=="w" && e.altKey) { if( rip('thediv') ) {
var i=document.f.wrp; i.checked=!i.checked; wrapta(); } return false;
}
if( k=="b" && e.altKey) { if( rip('thediv') ) {
var i=document.f.bld; i.checked=!i.checked; } return false;
}
}
function rip(n){
return document.getElementById(n).className=='hid'?1:0;
}

Thanks
Ivo
Jul 23 '05 #1
2 2273
Ivo wrote:
In an Win/IE-only application, some checkboxes and the like have been
assigned accesskeys, so pressing alt+w focuses a checkbox, alt+b another.
This is very convenient. However, when the checkboxes are hidden, for
example because they are in a div styled "display:none", pressing the magic
key combination does not work of course, but instead Windows generates an
warning beep, a sound. Now I have written a function that will toggle the
elements for me when they are out of view, but the beep still occurs.
Does anyone have a bright idea how to evade the warning?
There is no way to stop the beep. IE/Windows is recognizing that there is no
ALT key combination matching what the user is pressing prior to your code ever
being run.
function keyd(e) {
e=e||window.event; var k=e.keyCode;
k=String.fromCharCode(k).toLowerCase();
if( k=="w" && e.altKey) { if( rip('thediv') ) {
var i=document.f.wrp; i.checked=!i.checked; wrapta(); } return false;
}
if( k=="b" && e.altKey) { if( rip('thediv') ) {
var i=document.f.bld; i.checked=!i.checked; } return false;
}
}
function rip(n){
return document.getElementById(n).className=='hid'?1:0;


You want rip() to return a boolean (true or false), not 1 or 0 (which then have
to be evaluated to true or false). For functions like this:

return (document.getElementById(n).className == 'hid');

is sufficient. The test evaluates to a boolean (true or false). That boolean
value is returned and the if (...). It's sort of silly to test a boolean
condition, return an integer and force JavaScript to evaluate that integer
value back into a boolean.

This has nothing to do with your problem, but it's just better code design.

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #2
Ivo
"Grant Wagner" wrote
Ivo wrote:
In an Win/IE-only application, some checkboxes and the like have been
assigned accesskeys, so pressing alt+w focuses a checkbox, alt+b another. This is very convenient. However, when the checkboxes are hidden, for
example because they are in a div styled "display:none", pressing the magic key combination does not work of course, but instead Windows generates an warning beep, a sound. Now I have written a function that will toggle the elements for me when they are out of view, but the beep still occurs.
Does anyone have a bright idea how to evade the warning?
There is no way to stop the beep. IE/Windows is recognizing that there is

no ALT key combination matching what the user is pressing prior to your code ever being run.
Was afraid so. Thanks for the confirmation. I have been experimenting with
dynamically assigning the keys to an arbitrary element that is visible, but
whatever I try, the beep comes before the code. On a sidenote, I find it
strange that you cannot have multiple accesskeys on an element. For example,
<input accesskey="z" accesskey="k">
will make alt+z but not alt+k focus the element (tested in IE and Moz). This
is clearly an unnecessary restriction unless I 'm missing something (again).

<snip>
function rip(n){
return document.getElementById(n).className=='hid'?1:0;


You want rip() to return a boolean (true or false), not 1 or 0 (which then

have to be evaluated to true or false). For functions like this:

return (document.getElementById(n).className == 'hid');

is sufficient. The test evaluates to a boolean (true or false). That boolean value is returned and the if (...). It's sort of silly to test a boolean
condition, return an integer and force JavaScript to evaluate that integer
value back into a boolean.

This has nothing to do with your problem, but it's just better code design.

Very true, thanks a lot.
Ivo
--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: bill_m | last post by:
Has anyone tried to use the .NET Beep function? The following works in VBA: Private Declare Function Beep Lib "Kernel32.dll" _ (ByVal X As Long, ByVal Y As Long) As Long Dim blVal As...
1
by: Matthew | last post by:
I have this code snippet that is ignoring a Tab key and executing something(); on all other key-presses. How would I efficiently modify this to include a second key, such as backspace (KeyCode 8)?...
2
by: Vince | last post by:
I'm writing a framework component, and I would like to be able to determine if a particular event has been delegated or not. By event delegation, I mean: control.event += handler (method); I...
6
by: Julia Briggs | last post by:
Hi, can someone help me put together a if (event.keyCode function, that will detect when the # character is pressed twice, and then dosomething() ? Sincerely, %Julia%
7
by: Lee Moody | last post by:
I just want quick and easy way to play a .wav file out the standard sound device. It could even be as simple as activating a sound assigned to an existing windows sound event. Any suggestions?...
0
by: Showjumper | last post by:
I have seen the article on 4 guys that descibes creating an event calandar. However what i would like to do is have the days be clickable (i.e. click the day and it show the details for that event)...
14
by: Brett Romero | last post by:
I'm using a DataGrid and have assigned this.DataSourceChanged += new EventHandler( DataGrid_DataSourceChanged ); This works fine but there is one case where it doesn't. How can I check if...
1
by: nebulus | last post by:
I'm working on a web app that under normal circumstances will be happy with the Session_OnEnd event, but when a user leaves a page by closing the browser by either Alt+F4 or just hitting the "X",...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.