Newsgroup: it.comp.lang.javascript
Titolo: Ancora event.which X ATIPOWER

Su eventi relativi ai pulsanti del mouse funzia, quello che perň non
riesco ad ottenere č il valore unicode del tasto premuto(da tastiera)
per esempio nell'evento onMouseOver di un'immagine.
Faccio presente che non riesco a far funzionare neanche
event.modifiers che in teoria dovrebbe restituire eventuali tasti
modificatori premuto al momento in cui si verifica l'evento.
Ti sarei molto grato se tu potessi ancora una volta aiutare.
Ciao
Claudio Bellucci

 wrote in message
39afd42...@news.interbusiness.it...

Ciao!
Vedi esempi.............penso che bastino!!
<html>
 <head>
 <script language="JavaScript1.2"><!--
 function netscapeKeyPress(e) {
      if (e.modifiers & Event.CONTROL_MASK)
          document.test.control.value = 'true';
      else
          document.test.control.value = '';
      if (e.modifiers & Event.ALT_MASK)
          document.test.alt.value = 'true';
      else
          document.test.alt.value = '';
      if (e.modifiers & Event.SHIFT_MASK)
          document.test.shift.value = 'true';
      else
          document.test.shift.value = '';
      document.test.key.value = e.which;
 }
 function microsoftKeyPress() {
     var prefix = '';
     if (window.event.ctrlKey)
          document.test.control.value = 'true';
      else
          document.test.control.value = '';
     if (window.event.altKey)
          document.test.alt.value = 'true';
      else
          document.test.alt.value = '';
     if (window.event.shiftKey)
          document.test.shift.value = 'true';
      else
          document.test.shift.value = '';
     document.test.key.value = window.event.keyCode;
 }
 if (navigator.appName == 'Netscape') {
     window.captureEvents(Event.KEYPRESS);
     window.onKeyPress = netscapeKeyPress;
 }
 file://--></script>
 </head>
 <body onKeyPress="microsoftKeyPress()">
 <form name="test">
 <p>Test<br><input type="text">
 <p>Key<br><input type="text" name="key">
 <p>Control<br><input type="text" name="control">
 <p>Alt<br><input type="text" name="alt">
 <p>Shift<br><input type="text" name="shift">
 </form>
 </body>
 </html>
Esempio 2........
<script language="JavaScript"><!--
 function handler(e) {
     if (document.all) {
         e = window.event;
     }
     var key;
     if (document.layers)
         key = e.which;
     if (document.all)
         key = e.keyCode
     alert('Unicode value of key pressed was ' + key);
 }
 file://--></script>
Esempio 3..........
<script language="JavaScript"><!--
 function handler(e) {
     if (document.all) {
         e = window.event;
     }
     var key;
     if (document.layers)
         key = e.which;
     if (document.all)
         key = e.keyCode
     var chr = String.fromCharCode(key);
     alert('Character representation of pressed was ' + chr);
     alert('Unicode value of key pressed was ' + chr.charcodeAt(1));
 }
 file://--></script>
Esempio 4................
<script language="JavaScript"><!--
 function noLetterJ(e) {
     var myChar;
     if (document.all) {
         e = window.event;
         myChar = String.fromCharCode(e.keyCode);
     }
     else
         if (document.layers)
             var myChar = String.fromCharCode(e.which);
     if (myChar == 'J' || myChar == 'j') {
         if (document.layers)
             return false;
         else if (document.all)
             e.returnValue = false
     }
 }
 document.onkeypress = noLetterJ;
 file://--></script>
 <form>
 <input type="text" onKeyPress="return noLetterJ(event)">
 <br>
 <textarea onKeyPress="return noLetterJ(event)"></textarea>
 </form>
____________________
andreotta fabiano
WebMŞster ATI POWER s.n.c.
andr...@atipower.it
http://www.atipower.it
http://www.afdsoftware.freeweb.org
____________________