473,721 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:no ne", 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.eve nt; var k=e.keyCode;
k=String.fromCh arCode(k).toLow erCase();
if( k=="w" && e.altKey) { if( rip('thediv') ) {
var i=document.f.wr p; i.checked=!i.ch ecked; wrapta(); } return false;
}
if( k=="b" && e.altKey) { if( rip('thediv') ) {
var i=document.f.bl d; i.checked=!i.ch ecked; } return false;
}
}
function rip(n){
return document.getEle mentById(n).cla ssName=='hid'?1 :0;
}

Thanks
Ivo
Jul 23 '05 #1
2 2306
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:no ne", 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.eve nt; var k=e.keyCode;
k=String.fromCh arCode(k).toLow erCase();
if( k=="w" && e.altKey) { if( rip('thediv') ) {
var i=document.f.wr p; i.checked=!i.ch ecked; wrapta(); } return false;
}
if( k=="b" && e.altKey) { if( rip('thediv') ) {
var i=document.f.bl d; i.checked=!i.ch ecked; } return false;
}
}
function rip(n){
return document.getEle mentById(n).cla ssName=='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.getEl ementById(n).cl assName == '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*****@agrico reunited.com>
comp.lang.javas cript 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:no ne", 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.getEle mentById(n).cla ssName=='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.getEl ementById(n).cl assName == '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*****@agrico reunited.com>
comp.lang.javas cript 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
8757
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 Boolean Dim dwFreq As Long Dim dwDuration As Long
1
1680
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)? onkeydown="if ((event.keyCode||event.which) != 9) { something(); }"
2
1636
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 want to know if the event has already been delegated or not. Even though events use the "+=" syntax, they're not true indexers, so they don't have a Count. Any ideas?
6
1768
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
6455
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? Thanks in advance. -Lee
0
1172
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) only if there is an event on that day while other days are not clickable if there is no event. I have see the post on scottonwriting about customizing the calendar to get ti to have clickable days for .text. But i havent been able to modify this...
14
7441
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 DataSourceChanged has anything assigned. I can add it to the watch because it says it needs to be on the left side of a -= or +=. Thanks,
1
33181
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", I'll need to kill the session. Now, with the onbeforeunload event, I can handle this quite easily in IE, but in FireFox, it's another matter. For one thing, FireFox seems to empty out its event object on a page unload, so it's very hard to track...
0
9366
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9214
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9130
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9059
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5977
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4484
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3187
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2572
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2129
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.