? keycode.patch
Index: docs/help.html
===================================================================
RCS file: /data/cvs/cgiirc/docs/help.html,v
retrieving revision 1.4
diff -u -p -u -r1.4 help.html
--- docs/help.html	15 Jun 2002 21:35:16 -0000	1.4
+++ docs/help.html	21 Aug 2003 20:05:33 -0000
@@ -37,10 +37,15 @@ The options window lets you change some 
  immediately.
 
 <h3>Keyboard shortcuts</h3>
-There are several shortcuts to help make using CGI:IRC nicer, tab completion
- which will complete a nickname or channel when you press tab, alt+number will
- go to that number window if you number the windows from the left (Status = 1
- and so on).
+There are several shortcuts to help make using CGI:IRC nicer.
+<table>
+<tr><td>Tab</td><td>Will autocomplete a nickname or channel.</td></tr>
+<tr><td>Ctrl+number / Alt+number</td><td>Will go to that number window if you number
+ the windows from the left (Status = 1 and so on).</td></tr>
+<tr><td>Ctrl+B / Ctrl+Alt+B / Ctrl+Shift+B / Ctrl+Alt+Shift+B</td><td>Write "%B" for bold text.</td></tr>
+<tr><td>Ctrl+C / Ctrl+Alt+C / Ctrl+Shift+C / Ctrl+Alt+Shift+C</td><td>Write "%C" for colored text.</td></tr>
+<tr><td>Cursor Up/Down</td><td>Move in the command history.</td></tr>
+</table>
 
 <h3>About CGI:IRC</h3>
 CGI:IRC is written in Perl by David Leadbeater with help from lots of people. See the <a
Index: interfaces/ie.pm
===================================================================
RCS file: /data/cvs/cgiirc/interfaces/ie.pm,v
retrieving revision 1.59
diff -u -p -u -r1.59 ie.pm
--- interfaces/ie.pm	18 Jan 2003 00:12:23 -0000	1.59
+++ interfaces/ie.pm	21 Aug 2003 20:05:34 -0000
@@ -587,10 +587,15 @@ The options window lets you change some 
  immediately.
 
 <h3>Keyboard shortcuts</h3>
-There are several shortcuts to help make using CGI:IRC nicer, tab completion
- which will complete a nickname or channel when you press tab, alt+number will
- go to that number window if you number the windows from the left (Status = 1
- and so on).
+There are several shortcuts to help make using CGI:IRC nicer.
+<table>
+<tr><td>Tab</td><td>Will autocomplete a nickname or channel.</td></tr>
+<tr><td>Ctrl+number / Alt+number</td><td>Will go to that number window if you number
+ the windows from the left (Status = 1 and so on).</td></tr>
+<tr><td>Ctrl+B / Ctrl+Alt+B / Ctrl+Shift+B / Ctrl+Alt+Shift+B</td><td>Write "%B" for bold text.</td></tr>
+<tr><td>Ctrl+C / Ctrl+Alt+C / Ctrl+Shift+C / Ctrl+Alt+Shift+C</td><td>Write "%C" for colored text.</td></tr>
+<tr><td>Cursor Up/Down</td><td>Move in the command history.</td></tr>
+</table>
 
 <h3>About CGI:IRC</h3>
 CGI:IRC is written in Perl by David Leadbeater with help from lots of people. See the <a
@@ -1314,21 +1319,32 @@ function hisdo() {
 }
 
 function enter_key_trap(e) {
-   if(e == null) {
-      return keypress(event.srcElement, event.keyCode, event);
-   }else{
-      // mozilla dodginess
-      return keypress(e.target, e.keyCode == 0 ? e.which : e.keyCode, e);
+   if(e == null) { // MSIE
+      return keypress(event.srcElement, event);
+   }else{ // Mozilla, Netscape, W3C
+      return keypress(e.target, e);
    }
 }
 
-function keypress(srcEl, keyCode, event) {
+function keypress(srcEl, event) {
    if (srcEl.tagName != 'INPUT' || srcEl.name.toLowerCase() != 'say')
        return true;
-
-   if(keyCode == 66 && event.ctrlKey) {
-	   append('\%B');
-   }else if(keyCode == 67 && event.ctrlKey) {
+   var charCode = event.charCode; // MSIE: undef, Mozilla: different when shifted
+   var keyCode = event.keyCode; // the only one in MSIE, Mozilla: only special keys (up, down, etc)
+   var which = event.which; // the only one in NN
+
+   if(keyCode == null) { // NN
+      charCode = which;
+      if(which < 32) keyCode = which;
+      // NN only has charcodes (and some special keys below 32, i.e. Esc)
+   }
+   if(charCode == null) charCode = keyCode; // MSIE
+
+   if((charCode == 66 || charCode == 98) && event.ctrlKey) {
+       // Ctrl + b(or B) is often bound to browser functions, Ctrl+Alt works in such cases
+       append('\%B');
+   }else if((charCode == 67 || charCode == 99) && event.ctrlKey) {
+       // Ctrl + c(or C) is mostly bound to system/browser functions, use Ctrl+Alt then
        append('\%C');
    }else if(keyCode == 9) { // TAB
        var tabIndex = srcEl.value.lastIndexOf(' ');
@@ -1368,14 +1384,14 @@ function keypress(srcEl, keyCode, event)
 		  tabpos = (tabIndex == -1 ? 0 : tabIndex + 1) + tablen;
 		  tabinc = 1;
 	   }
-   }else if(keyCode == 38) { // UP
+   }else if(keyCode == 38) { // UP, doesn't work in NN
        if(!shistory[hispos]) {
 	      if(document.myform["say"].value) hisadd();
 		  hispos = shistory.length;
 	   }
 	   hispos--;
 	   hisdo();
-   }else if(keyCode == 40) { // DOWN
+   }else if(keyCode == 40) { // DOWN, dito
        if(!shistory[hispos]) {
 	      if(document.myform["say"].value) hisadd();
 		  document.myform["say"].value = '';
@@ -1383,8 +1399,10 @@ function keypress(srcEl, keyCode, event)
 	   }
 	   hispos++;
 	   hisdo();
-   }else if(event.altKey && !event.ctrlKey && keyCode > 47 && keyCode < 58) {
-       var num = keyCode - 48;
+   }else if((event.altKey || event.ctrlKey) && charCode > 47 && charCode < 58) {
+       // Alt or Ctrl + number is often bind to browser functions
+       // so use any of the combinations browser passes through to event handler
+       var num = charCode - 48;
 	   if(num == 0) num = 10;
 
 	   var name = parent.fwindowlist.witemchgnum(num);
Index: interfaces/konqueror.pm
===================================================================
RCS file: /data/cvs/cgiirc/interfaces/konqueror.pm,v
retrieving revision 1.18
diff -u -p -u -r1.18 konqueror.pm
--- interfaces/konqueror.pm	18 Jan 2003 00:12:24 -0000	1.18
+++ interfaces/konqueror.pm	21 Aug 2003 20:05:35 -0000
@@ -348,10 +348,15 @@ The options window lets you change some 
  immediately.
 
 <h3>Keyboard shortcuts</h3>
-There are several shortcuts to help make using CGI:IRC nicer, tab completion
- which will complete a nickname or channel when you press tab, alt+number will
- go to that number window if you number the windows from the left (Status = 1
- and so on).
+There are several shortcuts to help make using CGI:IRC nicer.
+<table>
+<tr><td>Tab</td><td>Will autocomplete a nickname or channel.</td></tr>
+<tr><td>Ctrl+number / Alt+number</td><td>Will go to that number window if you number
+ the windows from the left (Status = 1 and so on).</td></tr>
+<tr><td>Ctrl+B / Ctrl+Alt+B / Ctrl+Shift+B / Ctrl+Alt+Shift+B</td><td>Write "%B" for bold text.</td></tr>
+<tr><td>Ctrl+C / Ctrl+Alt+C / Ctrl+Shift+C / Ctrl+Alt+Shift+C</td><td>Write "%C" for colored text.</td></tr>
+<tr><td>Cursor Up/Down</td><td>Move in the command history.</td></tr>
+</table>
 
 <h3>About CGI:IRC</h3>
 CGI:IRC is written in Perl by David Leadbeater with help from lots of people. See the <a
@@ -1061,21 +1066,32 @@ function hisdo() {
 }
 
 function enter_key_trap(e) {
-   if(e == null) {
-      return keypress(event.srcElement, event.keyCode, event);
-   }else{
-      // mozilla dodginess
-      return keypress(e.target, e.keyCode == 0 ? e.which : e.keyCode, e);
+   if(e == null) { // MSIE
+      return keypress(event.srcElement, event);
+   }else{ // Mozilla, Netscape, W3C
+      return keypress(e.target, e);
    }
 }
 
-function keypress(srcEl, keyCode, event) {
+function keypress(srcEl, event) {
    if (srcEl.tagName != 'INPUT' || srcEl.name.toLowerCase() != 'say')
        return true;
-
-   if(keyCode == 66 && event.ctrlKey) {
-	   append('\%B');
-   }else if(keyCode == 67 && event.ctrlKey) {
+   var charCode = event.charCode; // MSIE: undef, Mozilla: different when shifted
+   var keyCode = event.keyCode; // the only one in MSIE, Mozilla: only special keys (up, down, etc)
+   var which = event.which; // the only one in NN
+
+   if(keyCode == null) { // NN
+      charCode = which;
+      if(which < 32) keyCode = which;
+      // NN only has charcodes (and some special keys below 32, i.e. Esc)
+   }
+   if(charCode == null) charCode = keyCode; // MSIE
+
+   if((charCode == 66 || charCode == 98) && event.ctrlKey) {
+       // Ctrl + b(or B) is often bound to browser functions, Ctrl+Alt works in such cases
+       append('\%B');
+   }else if((charCode == 67 || charCode == 99) && event.ctrlKey) {
+       // Ctrl + c(or C) is mostly bound to system/browser functions, use Ctrl+Alt then
        append('\%C');
    }else if(keyCode == 9) { // TAB
        var tabIndex = srcEl.value.lastIndexOf(' ');
@@ -1115,14 +1131,14 @@ function keypress(srcEl, keyCode, event)
 		  tabpos = (tabIndex == -1 ? 0 : tabIndex + 1) + tablen;
 		  tabinc = 1;
 	   }
-   }else if(keyCode == 38) { // UP
+   }else if(keyCode == 38) { // UP, doesn't work in NN
        if(!shistory[hispos]) {
 	      if(document.myform["say"].value) hisadd();
 		  hispos = shistory.length;
 	   }
 	   hispos--;
 	   hisdo();
-   }else if(keyCode == 40) { // DOWN
+   }else if(keyCode == 40) { // DOWN, dito
        if(!shistory[hispos]) {
 	      if(document.myform["say"].value) hisadd();
 		  document.myform["say"].value = '';
@@ -1130,8 +1146,10 @@ function keypress(srcEl, keyCode, event)
 	   }
 	   hispos++;
 	   hisdo();
-   }else if(event.altKey && !event.ctrlKey && keyCode > 47 && keyCode < 58) {
-       var num = keyCode - 48;
+   }else if((event.altKey || event.ctrlKey) && charCode > 47 && charCode < 58) {
+       // Alt or Ctrl + number is often bind to browser functions
+       // so use any of the combinations browser passes through to event handler
+       var num = charCode - 48;
 	   if(num == 0) num = 10;
 
 	   var name = parent.fwindowlist.witemchgnum(num);
Index: interfaces/mozilla.pm
===================================================================
RCS file: /data/cvs/cgiirc/interfaces/mozilla.pm,v
retrieving revision 1.58
diff -u -p -u -r1.58 mozilla.pm
--- interfaces/mozilla.pm	18 Jan 2003 00:12:24 -0000	1.58
+++ interfaces/mozilla.pm	21 Aug 2003 20:05:36 -0000
@@ -334,10 +334,15 @@ The options window lets you change some 
  immediately.
 
 <h3>Keyboard shortcuts</h3>
-There are several shortcuts to help make using CGI:IRC nicer, tab completion
- which will complete a nickname or channel when you press tab, alt+number will
- go to that number window if you number the windows from the left (Status = 1
- and so on).
+There are several shortcuts to help make using CGI:IRC nicer.
+<table>
+<tr><td>Tab</td><td>Will autocomplete a nickname or channel.</td></tr>
+<tr><td>Ctrl+number / Alt+number</td><td>Will go to that number window if you number
+ the windows from the left (Status = 1 and so on).</td></tr>
+<tr><td>Ctrl+B / Ctrl+Alt+B / Ctrl+Shift+B / Ctrl+Alt+Shift+B</td><td>Write "%B" for bold text.</td></tr>
+<tr><td>Ctrl+C / Ctrl+Alt+C / Ctrl+Shift+C / Ctrl+Alt+Shift+C</td><td>Write "%C" for colored text.</td></tr>
+<tr><td>Cursor Up/Down</td><td>Move in the command history.</td></tr>
+</table>
 
 <h3>About CGI:IRC</h3>
 CGI:IRC is written in Perl by David Leadbeater with help from lots of people. See the <a
@@ -1047,21 +1052,32 @@ function hisdo() {
 }
 
 function enter_key_trap(e) {
-   if(e == null) {
-      return keypress(event.srcElement, event.keyCode, event);
-   }else{
-      // mozilla dodginess
-      return keypress(e.target, e.keyCode == 0 ? e.which : e.keyCode, e);
+   if(e == null) { // MSIE
+      return keypress(event.srcElement, event);
+   }else{ // Mozilla, Netscape, W3C
+      return keypress(e.target, e);
    }
 }
 
-function keypress(srcEl, keyCode, event) {
+function keypress(srcEl, event) {
    if (srcEl.tagName != 'INPUT' || srcEl.name.toLowerCase() != 'say')
        return true;
-
-   if(keyCode == 66 && event.ctrlKey) {
-	   append('\%B');
-   }else if(keyCode == 67 && event.ctrlKey) {
+   var charCode = event.charCode; // MSIE: undef, Mozilla: different when shifted
+   var keyCode = event.keyCode; // the only one in MSIE, Mozilla: only special keys (up, down, etc)
+   var which = event.which; // the only one in NN
+
+   if(keyCode == null) { // NN
+      charCode = which;
+      if(which < 32) keyCode = which;
+      // NN only has charcodes (and some special keys below 32, i.e. Esc)
+   }
+   if(charCode == null) charCode = keyCode; // MSIE
+
+   if((charCode == 66 || charCode == 98) && event.ctrlKey) {
+       // Ctrl + b(or B) is often bound to browser functions, Ctrl+Alt works in such cases
+       append('\%B');
+   }else if((charCode == 67 || charCode == 99) && event.ctrlKey) {
+       // Ctrl + c(or C) is mostly bound to system/browser functions, use Ctrl+Alt then
        append('\%C');
    }else if(keyCode == 9) { // TAB
        var tabIndex = srcEl.value.lastIndexOf(' ');
@@ -1101,14 +1117,14 @@ function keypress(srcEl, keyCode, event)
 		  tabpos = (tabIndex == -1 ? 0 : tabIndex + 1) + tablen;
 		  tabinc = 1;
 	   }
-   }else if(keyCode == 38) { // UP
+   }else if(keyCode == 38) { // UP, doesn't work in NN
        if(!shistory[hispos]) {
 	      if(document.myform["say"].value) hisadd();
 		  hispos = shistory.length;
 	   }
 	   hispos--;
 	   hisdo();
-   }else if(keyCode == 40) { // DOWN
+   }else if(keyCode == 40) { // DOWN, dito
        if(!shistory[hispos]) {
 	      if(document.myform["say"].value) hisadd();
 		  document.myform["say"].value = '';
@@ -1116,8 +1132,10 @@ function keypress(srcEl, keyCode, event)
 	   }
 	   hispos++;
 	   hisdo();
-   }else if(event.altKey && !event.ctrlKey && keyCode > 47 && keyCode < 58) {
-       var num = keyCode - 48;
+   }else if((event.altKey || event.ctrlKey) && charCode > 47 && charCode < 58) {
+       // Alt or Ctrl + number is often bind to browser functions
+       // so use any of the combinations browser passes through to event handler
+       var num = charCode - 48;
 	   if(num == 0) num = 10;
 
 	   var name = parent.fwindowlist.witemchgnum(num);
Index: interfaces/interface-make/fform.pm
===================================================================
RCS file: /data/cvs/cgiirc/interfaces/interface-make/fform.pm,v
retrieving revision 1.4
diff -u -p -u -r1.4 fform.pm
--- interfaces/interface-make/fform.pm	24 Nov 2002 19:02:06 -0000	1.4
+++ interfaces/interface-make/fform.pm	21 Aug 2003 20:05:36 -0000
@@ -74,21 +74,32 @@ function hisdo() {
 }
 
 function enter_key_trap(e) {
-   if(e == null) {
-      return keypress(event.srcElement, event.keyCode, event);
-   }else{
-      // mozilla dodginess
-      return keypress(e.target, e.keyCode == 0 ? e.which : e.keyCode, e);
+   if(e == null) { // MSIE
+      return keypress(event.srcElement, event);
+   }else{ // Mozilla, Netscape, W3C
+      return keypress(e.target, e);
    }
 }
 
-function keypress(srcEl, keyCode, event) {
+function keypress(srcEl, event) {
    if (srcEl.tagName != 'INPUT' || srcEl.name.toLowerCase() != 'say')
        return true;
+   var charCode = event.charCode; // MSIE: undef, Mozilla: different when shifted
+   var keyCode = event.keyCode; // the only one in MSIE, Mozilla: only special keys (up, down, etc)
+   var which = event.which; // the only one in NN
 
-   if(keyCode == 66 && event.ctrlKey) {
-	   append('\%B');
-   }else if(keyCode == 67 && event.ctrlKey) {
+   if(keyCode == null) { // NN
+      charCode = which;
+      if(which < 32) keyCode = which;
+      // NN only has charcodes (and some special keys below 32, i.e. Esc)
+   }
+   if(charCode == null) charCode = keyCode; // MSIE
+
+   if((charCode == 66 || charCode == 98) && event.ctrlKey) {
+       // Ctrl + b(or B) is often bound to browser functions, Ctrl+Alt works in such cases
+       append('\%B');
+   }else if((charCode == 67 || charCode == 99) && event.ctrlKey) {
+       // Ctrl + c(or C) is mostly bound to system/browser functions, use Ctrl+Alt then
        append('\%C');
    }else if(keyCode == 9) { // TAB
        var tabIndex = srcEl.value.lastIndexOf(' ');
@@ -128,14 +139,14 @@ function keypress(srcEl, keyCode, event)
 		  tabpos = (tabIndex == -1 ? 0 : tabIndex + 1) + tablen;
 		  tabinc = 1;
 	   }
-   }else if(keyCode == 38) { // UP
+   }else if(keyCode == 38) { // UP, doesn't work in NN
        if(!shistory[hispos]) {
 	      if(document.myform["say"].value) hisadd();
 		  hispos = shistory.length;
 	   }
 	   hispos--;
 	   hisdo();
-   }else if(keyCode == 40) { // DOWN
+   }else if(keyCode == 40) { // DOWN, dito
        if(!shistory[hispos]) {
 	      if(document.myform["say"].value) hisadd();
 		  document.myform["say"].value = '';
@@ -143,8 +154,10 @@ function keypress(srcEl, keyCode, event)
 	   }
 	   hispos++;
 	   hisdo();
-   }else if(event.altKey && !event.ctrlKey && keyCode > 47 && keyCode < 58) {
-       var num = keyCode - 48;
+   }else if((event.altKey || event.ctrlKey) && charCode > 47 && charCode < 58) {
+       // Alt or Ctrl + number is often bind to browser functions
+       // so use any of the combinations browser passes through to event handler
+       var num = charCode - 48;
 	   if(num == 0) num = 10;
 
 	   var name = parent.fwindowlist.witemchgnum(num);
