C
Csaba Gabor
I'd like to detect the shift key when a button is "clicked" in
Firefox/Mozilla. If the button is clicked with the mouse, no problem.
However, if the onclick event is keyboard originated, then my method is
not working. Same thing for SELECT elements.
The simple web page below shows the issue. Click with the mouse while
holding down the shift key, and the Shift key's status registers.
However, use Shift+Alt+o, or either (while the button has focus)
Shift+Space or Shift+Enter to kick off the onClick event and the shift
key is not detected. Works fine with IE 6 on my Win XP Pro.
<html><body><title>onClick and Shift key detection</title></head>
<body>
<button type=button accessKey=i
onclick="bclick(this,event)">on<u>C</u>lick</button>
<button type=button accessKey=a
onactivate="aclick(this,event)">on<u>A</u>ctivate</button>
<script type='text/javascript'>
function bclick(ctl,evt) {
evt = evt || window.event;
if (evt.shiftKey) alert("Shift key was pressed");
else alert("Shift key not detected");
}
function aclick(ctl, evt) {
/* evidently not working - see
http://www.w3.org/TR/1999/WD-DOM-Level-2-19990923/events.html#Events-UIEvent
*/
alert(evt.detail);
}
</script>
</body>
</html>
Any suggestions or comments?
Csaba Gabor from Vienna
Firefox/Mozilla. If the button is clicked with the mouse, no problem.
However, if the onclick event is keyboard originated, then my method is
not working. Same thing for SELECT elements.
The simple web page below shows the issue. Click with the mouse while
holding down the shift key, and the Shift key's status registers.
However, use Shift+Alt+o, or either (while the button has focus)
Shift+Space or Shift+Enter to kick off the onClick event and the shift
key is not detected. Works fine with IE 6 on my Win XP Pro.
<html><body><title>onClick and Shift key detection</title></head>
<body>
<button type=button accessKey=i
onclick="bclick(this,event)">on<u>C</u>lick</button>
<button type=button accessKey=a
onactivate="aclick(this,event)">on<u>A</u>ctivate</button>
<script type='text/javascript'>
function bclick(ctl,evt) {
evt = evt || window.event;
if (evt.shiftKey) alert("Shift key was pressed");
else alert("Shift key not detected");
}
function aclick(ctl, evt) {
/* evidently not working - see
http://www.w3.org/TR/1999/WD-DOM-Level-2-19990923/events.html#Events-UIEvent
*/
alert(evt.detail);
}
</script>
</body>
</html>
Any suggestions or comments?
Csaba Gabor from Vienna