I ran 2 tests. One using proto''s Event.observe, and another using an in-line handler of the "keydown" event in a textbox. Using .bindAsEventListener, the event.keyCode is always returning a capital letter, no matter what. The in-line event handler returns lowercase vs. uppercase correctly... What''s going on? I guess I find it hard to believe no one has tried capturing keyboard events before, so I''m hoping I''m just royally screwing something up. Can anyone help me on this? The information transmitted in this electronic mail is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Code? Can''t help much without seeing what you''re doing. ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Ryan Gahl Sent: Friday, March 03, 2006 1:48 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: [Rails-spinoffs] event.keyCode broken in prototype? I ran 2 tests. One using proto''s Event.observe, and another using an in-line handler of the "keydown" event in a textbox. Using .bindAsEventListener, the event.keyCode is always returning a capital letter, no matter what. The in-line event handler returns lowercase vs. uppercase correctly... What''s going on? I guess I find it hard to believe no one has tried capturing keyboard events before, so I''m hoping I''m just royally screwing something up. Can anyone help me on this? The information transmitted in this electronic mail is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
<input type="text" onkeypress="alert(String.fromCharCode(event.keyCode));" /> The above returns "g" when "g" is pressed and "G" when "G" is pressed. WHILE... <input type="text" id="tb" /> someClass = Class.create(); someClass.prototype { initialize: function() { Event.observe($("tb"), "keypress", this.showkeyPressed.bindAsEventListener(this) ); }, showKeyPressed: function(evt) { alert(String.fromCharCode(evt.keyCode)); } }; ...returns "G" all the time when the g key I pressed, no matter what. (Simplified example of course) For some weird reason, the event object from proto''s bindAsEventListener method is always returning the capitalized keyCode of the key that was pressed. ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Gregory Hill Sent: Friday, March 03, 2006 3:07 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: RE: [Rails-spinoffs] event.keyCode broken in prototype? Code? Can''t help much without seeing what you''re doing. ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Ryan Gahl Sent: Friday, March 03, 2006 1:48 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: [Rails-spinoffs] event.keyCode broken in prototype? I ran 2 tests. One using proto''s Event.observe, and another using an in-line handler of the "keydown" event in a textbox. Using .bindAsEventListener, the event.keyCode is always returning a capital letter, no matter what. The in-line event handler returns lowercase vs. uppercase correctly... What''s going on? I guess I find it hard to believe no one has tried capturing keyboard events before, so I''m hoping I''m just royally screwing something up. Can anyone help me on this? The information transmitted in this electronic mail is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Just a random thought, but what if you change ''evt'' to ''event''. Does it work then? What browser are you testing in, btw? My thought is based on the fact that event is a global object in IE that gets the last event triggered. I thought that you had to pass the object in as a parameter in other browsers, though, so I don''t know how your inline handler would work at all in non-IE browsers. But, I''ve been wrong many times before. Greg ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Ryan Gahl Sent: Friday, March 03, 2006 2:16 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: RE: [Rails-spinoffs] event.keyCode broken in prototype? <input type="text" onkeypress="alert(String.fromCharCode(event.keyCode));" /> The above returns "g" when "g" is pressed and "G" when "G" is pressed. WHILE... <input type="text" id="tb" /> someClass = Class.create(); someClass.prototype { initialize: function() { Event.observe($("tb"), "keypress", this.showkeyPressed.bindAsEventListener(this) ); }, showKeyPressed: function(evt) { alert(String.fromCharCode(evt.keyCode)); } }; ...returns "G" all the time when the g key I pressed, no matter what. (Simplified example of course) For some weird reason, the event object from proto''s bindAsEventListener method is always returning the capitalized keyCode of the key that was pressed. ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Gregory Hill Sent: Friday, March 03, 2006 3:07 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: RE: [Rails-spinoffs] event.keyCode broken in prototype? Code? Can''t help much without seeing what you''re doing. ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Ryan Gahl Sent: Friday, March 03, 2006 1:48 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: [Rails-spinoffs] event.keyCode broken in prototype? I ran 2 tests. One using proto''s Event.observe, and another using an in-line handler of the "keydown" event in a textbox. Using .bindAsEventListener, the event.keyCode is always returning a capital letter, no matter what. The in-line event handler returns lowercase vs. uppercase correctly... What''s going on? I guess I find it hard to believe no one has tried capturing keyboard events before, so I''m hoping I''m just royally screwing something up. Can anyone help me on this? The information transmitted in this electronic mail is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
I''ve simplified my example. Changing "evt" to "event" makes no difference, you can name that parameter anything you want, it''s just a function argument variable (which is a reference to the actual event object). I''m using IE6. I''m implementing a textbox input masking script in a proto OO behavior class (the script was originally non OO and required inline event handlers). Anyway, you can replace my inline example below with <input type="text" onkeypress="showKeyPressed();" /> function showKeyPressed () { alert(String.fromCharCode(event.keyCode)); } ..and get the same results. I guess I''m at a loss. I can check to see if the shift key is down I guess (not sure if that also covers CAPSLOCK cases)... it''s very strange that it works fine if the event if hooked up inline, and not fine using the DOM2 methods... sucks. ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Gregory Hill Sent: Friday, March 03, 2006 3:23 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: RE: [Rails-spinoffs] event.keyCode broken in prototype? Just a random thought, but what if you change ''evt'' to ''event''. Does it work then? What browser are you testing in, btw? My thought is based on the fact that event is a global object in IE that gets the last event triggered. I thought that you had to pass the object in as a parameter in other browsers, though, so I don''t know how your inline handler would work at all in non-IE browsers. But, I''ve been wrong many times before. Greg ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Ryan Gahl Sent: Friday, March 03, 2006 2:16 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: RE: [Rails-spinoffs] event.keyCode broken in prototype? <input type="text" onkeypress="alert(String.fromCharCode(event.keyCode));" /> The above returns "g" when "g" is pressed and "G" when "G" is pressed. WHILE... <input type="text" id="tb" /> someClass = Class.create(); someClass.prototype { initialize: function() { Event.observe($("tb"), "keypress", this.showkeyPressed.bindAsEventListener(this) ); }, showKeyPressed: function(evt) { alert(String.fromCharCode(evt.keyCode)); } }; ...returns "G" all the time when the g key I pressed, no matter what. (Simplified example of course) For some weird reason, the event object from proto''s bindAsEventListener method is always returning the capitalized keyCode of the key that was pressed. ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Gregory Hill Sent: Friday, March 03, 2006 3:07 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: RE: [Rails-spinoffs] event.keyCode broken in prototype? Code? Can''t help much without seeing what you''re doing. ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Ryan Gahl Sent: Friday, March 03, 2006 1:48 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: [Rails-spinoffs] event.keyCode broken in prototype? I ran 2 tests. One using proto''s Event.observe, and another using an in-line handler of the "keydown" event in a textbox. Using .bindAsEventListener, the event.keyCode is always returning a capital letter, no matter what. The in-line event handler returns lowercase vs. uppercase correctly... What''s going on? I guess I find it hard to believe no one has tried capturing keyboard events before, so I''m hoping I''m just royally screwing something up. Can anyone help me on this? The information transmitted in this electronic mail is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Well, my point was that in IE, the variable that is passed to the function does not exist, so you need to reference the global ''event'' object. Or does prototype handle that in the bindAsEventListener code already? What happens if you do this, instead of the inline handler? $(''id'').onkeypress = showKeyPressed; That should at least tell you if it''s something specific to using prototype or whether it just doesn''t work at all if you don''t use an inline handler. Greg ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Ryan Gahl Sent: Friday, March 03, 2006 2:31 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: RE: [Rails-spinoffs] event.keyCode broken in prototype? I''ve simplified my example. Changing "evt" to "event" makes no difference, you can name that parameter anything you want, it''s just a function argument variable (which is a reference to the actual event object). I''m using IE6. I''m implementing a textbox input masking script in a proto OO behavior class (the script was originally non OO and required inline event handlers). Anyway, you can replace my inline example below with <input type="text" onkeypress="showKeyPressed();" /> function showKeyPressed () { alert(String.fromCharCode(event.keyCode)); } ..and get the same results. I guess I''m at a loss. I can check to see if the shift key is down I guess (not sure if that also covers CAPSLOCK cases)... it''s very strange that it works fine if the event if hooked up inline, and not fine using the DOM2 methods... sucks. ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Gregory Hill Sent: Friday, March 03, 2006 3:23 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: RE: [Rails-spinoffs] event.keyCode broken in prototype? Just a random thought, but what if you change ''evt'' to ''event''. Does it work then? What browser are you testing in, btw? My thought is based on the fact that event is a global object in IE that gets the last event triggered. I thought that you had to pass the object in as a parameter in other browsers, though, so I don''t know how your inline handler would work at all in non-IE browsers. But, I''ve been wrong many times before. Greg ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Ryan Gahl Sent: Friday, March 03, 2006 2:16 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: RE: [Rails-spinoffs] event.keyCode broken in prototype? <input type="text" onkeypress="alert(String.fromCharCode(event.keyCode));" /> The above returns "g" when "g" is pressed and "G" when "G" is pressed. WHILE... <input type="text" id="tb" /> someClass = Class.create(); someClass.prototype { initialize: function() { Event.observe($("tb"), "keypress", this.showkeyPressed.bindAsEventListener(this) ); }, showKeyPressed: function(evt) { alert(String.fromCharCode(evt.keyCode)); } }; ...returns "G" all the time when the g key I pressed, no matter what. (Simplified example of course) For some weird reason, the event object from proto''s bindAsEventListener method is always returning the capitalized keyCode of the key that was pressed. ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Gregory Hill Sent: Friday, March 03, 2006 3:07 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: RE: [Rails-spinoffs] event.keyCode broken in prototype? Code? Can''t help much without seeing what you''re doing. ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Ryan Gahl Sent: Friday, March 03, 2006 1:48 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: [Rails-spinoffs] event.keyCode broken in prototype? I ran 2 tests. One using proto''s Event.observe, and another using an in-line handler of the "keydown" event in a textbox. Using .bindAsEventListener, the event.keyCode is always returning a capital letter, no matter what. The in-line event handler returns lowercase vs. uppercase correctly... What''s going on? I guess I find it hard to believe no one has tried capturing keyboard events before, so I''m hoping I''m just royally screwing something up. Can anyone help me on this? The information transmitted in this electronic mail is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Yes, prototype handles that (so it does exist) Function.prototype.bindAsEventListener = function(object) { var __method = this; return function(event) { return __method.call(object, event || window.event); } } Now... just attaching the event handler as you suggested works (as I would expect). It appears that for some (DAMNEDDDDD) reason, the DOM2 event handler attachment methods just do not work with the keyCode. It''s always just returning the UNICODE for the capital letter. That may be W3C recommended (not sure), but either way, it''s stupid. Stupid Stupid Stupid. sTUpiD. Sorry... So now I guess I either use the old method of $(''id'').onkeypress = method, or I add some stupid "is the shift key down, and if so, is the CAPSLOCK key down..." logic... Hrmm... stupid... ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Gregory Hill Sent: Friday, March 03, 2006 4:14 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: RE: [Rails-spinoffs] event.keyCode broken in prototype? Well, my point was that in IE, the variable that is passed to the function does not exist, so you need to reference the global ''event'' object. Or does prototype handle that in the bindAsEventListener code already? What happens if you do this, instead of the inline handler? $(''id'').onkeypress = showKeyPressed; That should at least tell you if it''s something specific to using prototype or whether it just doesn''t work at all if you don''t use an inline handler. Greg ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Ryan Gahl Sent: Friday, March 03, 2006 2:31 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: RE: [Rails-spinoffs] event.keyCode broken in prototype? I''ve simplified my example. Changing "evt" to "event" makes no difference, you can name that parameter anything you want, it''s just a function argument variable (which is a reference to the actual event object). I''m using IE6. I''m implementing a textbox input masking script in a proto OO behavior class (the script was originally non OO and required inline event handlers). Anyway, you can replace my inline example below with <input type="text" onkeypress="showKeyPressed();" /> function showKeyPressed () { alert(String.fromCharCode(event.keyCode)); } ..and get the same results. I guess I''m at a loss. I can check to see if the shift key is down I guess (not sure if that also covers CAPSLOCK cases)... it''s very strange that it works fine if the event if hooked up inline, and not fine using the DOM2 methods... sucks. ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Gregory Hill Sent: Friday, March 03, 2006 3:23 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: RE: [Rails-spinoffs] event.keyCode broken in prototype? Just a random thought, but what if you change ''evt'' to ''event''. Does it work then? What browser are you testing in, btw? My thought is based on the fact that event is a global object in IE that gets the last event triggered. I thought that you had to pass the object in as a parameter in other browsers, though, so I don''t know how your inline handler would work at all in non-IE browsers. But, I''ve been wrong many times before. Greg ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Ryan Gahl Sent: Friday, March 03, 2006 2:16 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: RE: [Rails-spinoffs] event.keyCode broken in prototype? <input type="text" onkeypress="alert(String.fromCharCode(event.keyCode));" /> The above returns "g" when "g" is pressed and "G" when "G" is pressed. WHILE... <input type="text" id="tb" /> someClass = Class.create(); someClass.prototype { initialize: function() { Event.observe($("tb"), "keypress", this.showkeyPressed.bindAsEventListener(this) ); }, showKeyPressed: function(evt) { alert(String.fromCharCode(evt.keyCode)); } }; ...returns "G" all the time when the g key I pressed, no matter what. (Simplified example of course) For some weird reason, the event object from proto''s bindAsEventListener method is always returning the capitalized keyCode of the key that was pressed. ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Gregory Hill Sent: Friday, March 03, 2006 3:07 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: RE: [Rails-spinoffs] event.keyCode broken in prototype? Code? Can''t help much without seeing what you''re doing. ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Ryan Gahl Sent: Friday, March 03, 2006 1:48 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: [Rails-spinoffs] event.keyCode broken in prototype? I ran 2 tests. One using proto''s Event.observe, and another using an in-line handler of the "keydown" event in a textbox. Using .bindAsEventListener, the event.keyCode is always returning a capital letter, no matter what. The in-line event handler returns lowercase vs. uppercase correctly... What''s going on? I guess I find it hard to believe no one has tried capturing keyboard events before, so I''m hoping I''m just royally screwing something up. Can anyone help me on this? The information transmitted in this electronic mail is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
This is another case of what we were talking about yesterday. Browser inconsistencies. Why would, in the same browser, attaching an event handler one way give you different results from attaching it another way? ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Ryan Gahl Sent: Friday, March 03, 2006 4:25 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: RE: [Rails-spinoffs] event.keyCode broken in prototype? Yes, prototype handles that (so it does exist) Function.prototype.bindAsEventListener = function(object) { var __method = this; return function(event) { return __method.call(object, event || window.event); } } Now... just attaching the event handler as you suggested works (as I would expect). It appears that for some (DAMNEDDDDD) reason, the DOM2 event handler attachment methods just do not work with the keyCode. It''s always just returning the UNICODE for the capital letter. That may be W3C recommended (not sure), but either way, it''s stupid. Stupid Stupid Stupid. sTUpiD. Sorry... So now I guess I either use the old method of $(''id'').onkeypress = method, or I add some stupid "is the shift key down, and if so, is the CAPSLOCK key down..." logic... Hrmm... stupid... ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Gregory Hill Sent: Friday, March 03, 2006 4:14 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: RE: [Rails-spinoffs] event.keyCode broken in prototype? Well, my point was that in IE, the variable that is passed to the function does not exist, so you need to reference the global ''event'' object. Or does prototype handle that in the bindAsEventListener code already? What happens if you do this, instead of the inline handler? $(''id'').onkeypress = showKeyPressed; That should at least tell you if it''s something specific to using prototype or whether it just doesn''t work at all if you don''t use an inline handler. Greg ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Ryan Gahl Sent: Friday, March 03, 2006 2:31 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: RE: [Rails-spinoffs] event.keyCode broken in prototype? I''ve simplified my example. Changing "evt" to "event" makes no difference, you can name that parameter anything you want, it''s just a function argument variable (which is a reference to the actual event object). I''m using IE6. I''m implementing a textbox input masking script in a proto OO behavior class (the script was originally non OO and required inline event handlers). Anyway, you can replace my inline example below with <input type="text" onkeypress="showKeyPressed();" /> function showKeyPressed () { alert(String.fromCharCode(event.keyCode)); } ..and get the same results. I guess I''m at a loss. I can check to see if the shift key is down I guess (not sure if that also covers CAPSLOCK cases)... it''s very strange that it works fine if the event if hooked up inline, and not fine using the DOM2 methods... sucks. ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Gregory Hill Sent: Friday, March 03, 2006 3:23 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: RE: [Rails-spinoffs] event.keyCode broken in prototype? Just a random thought, but what if you change ''evt'' to ''event''. Does it work then? What browser are you testing in, btw? My thought is based on the fact that event is a global object in IE that gets the last event triggered. I thought that you had to pass the object in as a parameter in other browsers, though, so I don''t know how your inline handler would work at all in non-IE browsers. But, I''ve been wrong many times before. Greg ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Ryan Gahl Sent: Friday, March 03, 2006 2:16 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: RE: [Rails-spinoffs] event.keyCode broken in prototype? <input type="text" onkeypress="alert(String.fromCharCode(event.keyCode));" /> The above returns "g" when "g" is pressed and "G" when "G" is pressed. WHILE... <input type="text" id="tb" /> someClass = Class.create(); someClass.prototype { initialize: function() { Event.observe($("tb"), "keypress", this.showkeyPressed.bindAsEventListener(this) ); }, showKeyPressed: function(evt) { alert(String.fromCharCode(evt.keyCode)); } }; ...returns "G" all the time when the g key I pressed, no matter what. (Simplified example of course) For some weird reason, the event object from proto''s bindAsEventListener method is always returning the capitalized keyCode of the key that was pressed. ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Gregory Hill Sent: Friday, March 03, 2006 3:07 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: RE: [Rails-spinoffs] event.keyCode broken in prototype? Code? Can''t help much without seeing what you''re doing. ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Ryan Gahl Sent: Friday, March 03, 2006 1:48 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: [Rails-spinoffs] event.keyCode broken in prototype? I ran 2 tests. One using proto''s Event.observe, and another using an in-line handler of the "keydown" event in a textbox. Using .bindAsEventListener, the event.keyCode is always returning a capital letter, no matter what. The in-line event handler returns lowercase vs. uppercase correctly... What''s going on? I guess I find it hard to believe no one has tried capturing keyboard events before, so I''m hoping I''m just royally screwing something up. Can anyone help me on this? The information transmitted in this electronic mail is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
I''d say, returning letters consistently cased makes sense. element.nodeName is always returned in capital letters for the same reason - because 99% of the time the case doesn''t matter, and you really don''t want to be calling case-conversion functions when you just want to see if something == a letter. For the other 1%, I guess yes, people are supposed to test for shift and/or caps lock. -Rob Ryan Gahl wrote:> Yes, prototype handles that (so it does exist) > > > > Function.prototype.bindAsEventListener = function(object) { > > var __method = this; > > return function(event) { > > return __method.call(object, event || window.event); > > } > > } > > > > > > Now… just attaching the event handler as you suggested works (as I would > expect). It appears that for some (DAMNEDDDDD) reason, the DOM2 event > handler attachment methods just do not work with the keyCode. It’s > always just returning the UNICODE for the capital letter. That may be > W3C recommended (not sure), but either way, it’s stupid. Stupid Stupid > Stupid. sTUpiD. > > > > Sorry… So now I guess I either use the old method of $(‘id’).onkeypress > = method, or I add some stupid “is the shift key down, and if so, is the > CAPSLOCK key down…” logic… > > > > Hrmm… stupid… > > > > ------------------------------------------------------------------------ > > *From:* rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] *On Behalf Of > *Gregory Hill > *Sent:* Friday, March 03, 2006 4:14 PM > *To:* rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > *Subject:* RE: [Rails-spinoffs] event.keyCode broken in prototype? > > > > Well, my point was that in IE, the variable that is passed to the > function does not exist, so you need to reference the global ‘event’ > object. Or does prototype handle that in the bindAsEventListener code > already? > > > > What happens if you do this, instead of the inline handler? > > $(‘id’).onkeypress = showKeyPressed; > > > > That should at least tell you if it’s something specific to using > prototype or whether it just doesn’t work at all if you don’t use an > inline handler. > > > > Greg > > > > ------------------------------------------------------------------------ > > *From:* rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] *On Behalf Of > *Ryan Gahl > *Sent:* Friday, March 03, 2006 2:31 PM > *To:* rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > *Subject:* RE: [Rails-spinoffs] event.keyCode broken in prototype? > > > > I’ve simplified my example. Changing “evt” to “event” makes no > difference, you can name that parameter anything you want, it’s just a > function argument variable (which is a reference to the actual event > object). > > > > I’m using IE6. I’m implementing a textbox input masking script in a > proto OO behavior class (the script was originally non OO and required > inline event handlers). > > > > Anyway, you can replace my inline example below with > > > > <input type=”text” onkeypress=”showKeyPressed();” /> > > > > function showKeyPressed () > > { > > alert(String.fromCharCode(event.keyCode)); > > } > > > > ..and get the same results. > > > > I guess I’m at a loss. I can check to see if the shift key is down I > guess (not sure if that also covers CAPSLOCK cases)… it’s very strange > that it works fine if the event if hooked up inline, and not fine using > the DOM2 methods… sucks. > > > > > > > > ------------------------------------------------------------------------ > > *From:* rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] *On Behalf Of > *Gregory Hill > *Sent:* Friday, March 03, 2006 3:23 PM > *To:* rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > *Subject:* RE: [Rails-spinoffs] event.keyCode broken in prototype? > > > > Just a random thought, but what if you change ‘evt’ to ‘event’. Does it > work then? What browser are you testing in, btw? My thought is based > on the fact that event is a global object in IE that gets the last event > triggered. I thought that you had to pass the object in as a parameter > in other browsers, though, so I don’t know how your inline handler would > work at all in non-IE browsers. But, I’ve been wrong many times before. > > > Greg > > > > ------------------------------------------------------------------------ > > *From:* rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] *On Behalf Of > *Ryan Gahl > *Sent:* Friday, March 03, 2006 2:16 PM > *To:* rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > *Subject:* RE: [Rails-spinoffs] event.keyCode broken in prototype? > > > > <input type=”text” > onkeypress=”alert(String.fromCharCode(event.keyCode));” /> > > > > The above returns “g” when “g” is pressed and “G” when “G” is pressed. > > > > WHILE… > > > > <input type=”text” id=”tb” /> > > > > someClass = Class.create(); > > someClass.prototype > > { > > initialize: function() > > { > > Event.observe($(“tb”), “keypress”, > this.showkeyPressed.bindAsEventListener(this) ); > > }, > > > > showKeyPressed: function(evt) > > { > > alert(String.fromCharCode(evt.keyCode)); > > } > > }; > > > > …returns “G” all the time when the g key I pressed, no matter what. > (Simplified example of course) > > > > For some weird reason, the event object from proto’s bindAsEventListener > method is always returning the capitalized keyCode of the key that was > pressed. > > > > ------------------------------------------------------------------------ > > *From:* rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] *On Behalf Of > *Gregory Hill > *Sent:* Friday, March 03, 2006 3:07 PM > *To:* rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > *Subject:* RE: [Rails-spinoffs] event.keyCode broken in prototype? > > > > Code? Can’t help much without seeing what you’re doing. > > > > > > ------------------------------------------------------------------------ > > *From:* rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] *On Behalf Of > *Ryan Gahl > *Sent:* Friday, March 03, 2006 1:48 PM > *To:* rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > *Subject:* [Rails-spinoffs] event.keyCode broken in prototype? > > > > I ran 2 tests. One using proto’s Event.observe, and another using an > in-line handler of the “keydown” event in a textbox. > > > > Using .bindAsEventListener, the event.keyCode is always returning a > capital letter, no matter what. The in-line event handler returns > lowercase vs. uppercase correctly… What’s going on? > > > > I guess I find it hard to believe no one has tried capturing keyboard > events before, so I’m hoping I’m just royally screwing something up. Can > anyone help me on this? > > The information transmitted in this electronic mail is intended only for > the person or entity to which it is addressed and may contain > confidential, proprietary, and/or privileged material. Any review, > retransmission, dissemination or other use of, or taking of any action > in reliance upon, this information by persons or entities other than the > intended recipient is prohibited. If you received this in error, please > contact the sender and delete the material from all computers. > > > ------------------------------------------------------------------------ > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Because that''s what you get when you produce a product which is a just a series of dirty hacks added on to the last version. Honestly, I would bet any money that is the real answer. -Rob Ryan Gahl wrote:> This is another case of what we were talking about yesterday. Browser > inconsistencies. Why would, in the same browser, attaching an event > handler one way give you different results from attaching it another way? > > > > ------------------------------------------------------------------------ > > *From:* rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] *On Behalf Of > *Ryan Gahl > *Sent:* Friday, March 03, 2006 4:25 PM > *To:* rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > *Subject:* RE: [Rails-spinoffs] event.keyCode broken in prototype? > > > > Yes, prototype handles that (so it does exist) > > > > Function.prototype.bindAsEventListener = function(object) { > > var __method = this; > > return function(event) { > > return __method.call(object, event || window.event); > > } > > } > > > > > > Now… just attaching the event handler as you suggested works (as I would > expect). It appears that for some (DAMNEDDDDD) reason, the DOM2 event > handler attachment methods just do not work with the keyCode. It’s > always just returning the UNICODE for the capital letter. That may be > W3C recommended (not sure), but either way, it’s stupid. Stupid Stupid > Stupid. sTUpiD. > > > > Sorry… So now I guess I either use the old method of $(‘id’).onkeypress > = method, or I add some stupid “is the shift key down, and if so, is the > CAPSLOCK key down…” logic… > > > > Hrmm… stupid… > > > > ------------------------------------------------------------------------ > > *From:* rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] *On Behalf Of > *Gregory Hill > *Sent:* Friday, March 03, 2006 4:14 PM > *To:* rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > *Subject:* RE: [Rails-spinoffs] event.keyCode broken in prototype? > > > > Well, my point was that in IE, the variable that is passed to the > function does not exist, so you need to reference the global ‘event’ > object. Or does prototype handle that in the bindAsEventListener code > already? > > > > What happens if you do this, instead of the inline handler? > > $(‘id’).onkeypress = showKeyPressed; > > > > That should at least tell you if it’s something specific to using > prototype or whether it just doesn’t work at all if you don’t use an > inline handler. > > > > Greg > > > > ------------------------------------------------------------------------ > > *From:* rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] *On Behalf Of > *Ryan Gahl > *Sent:* Friday, March 03, 2006 2:31 PM > *To:* rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > *Subject:* RE: [Rails-spinoffs] event.keyCode broken in prototype? > > > > I’ve simplified my example. Changing “evt” to “event” makes no > difference, you can name that parameter anything you want, it’s just a > function argument variable (which is a reference to the actual event > object). > > > > I’m using IE6. I’m implementing a textbox input masking script in a > proto OO behavior class (the script was originally non OO and required > inline event handlers). > > > > Anyway, you can replace my inline example below with > > > > <input type=”text” onkeypress=”showKeyPressed();” /> > > > > function showKeyPressed () > > { > > alert(String.fromCharCode(event.keyCode)); > > } > > > > ..and get the same results. > > > > I guess I’m at a loss. I can check to see if the shift key is down I > guess (not sure if that also covers CAPSLOCK cases)… it’s very strange > that it works fine if the event if hooked up inline, and not fine using > the DOM2 methods… sucks. > > > > > > > > ------------------------------------------------------------------------ > > *From:* rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] *On Behalf Of > *Gregory Hill > *Sent:* Friday, March 03, 2006 3:23 PM > *To:* rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > *Subject:* RE: [Rails-spinoffs] event.keyCode broken in prototype? > > > > Just a random thought, but what if you change ‘evt’ to ‘event’. Does it > work then? What browser are you testing in, btw? My thought is based > on the fact that event is a global object in IE that gets the last event > triggered. I thought that you had to pass the object in as a parameter > in other browsers, though, so I don’t know how your inline handler would > work at all in non-IE browsers. But, I’ve been wrong many times before. > > > Greg > > > > ------------------------------------------------------------------------ > > *From:* rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] *On Behalf Of > *Ryan Gahl > *Sent:* Friday, March 03, 2006 2:16 PM > *To:* rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > *Subject:* RE: [Rails-spinoffs] event.keyCode broken in prototype? > > > > <input type=”text” > onkeypress=”alert(String.fromCharCode(event.keyCode));” /> > > > > The above returns “g” when “g” is pressed and “G” when “G” is pressed. > > > > WHILE… > > > > <input type=”text” id=”tb” /> > > > > someClass = Class.create(); > > someClass.prototype > > { > > initialize: function() > > { > > Event.observe($(“tb”), “keypress”, > this.showkeyPressed.bindAsEventListener(this) ); > > }, > > > > showKeyPressed: function(evt) > > { > > alert(String.fromCharCode(evt.keyCode)); > > } > > }; > > > > …returns “G” all the time when the g key I pressed, no matter what. > (Simplified example of course) > > > > For some weird reason, the event object from proto’s bindAsEventListener > method is always returning the capitalized keyCode of the key that was > pressed. > > > > ------------------------------------------------------------------------ > > *From:* rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] *On Behalf Of > *Gregory Hill > *Sent:* Friday, March 03, 2006 3:07 PM > *To:* rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > *Subject:* RE: [Rails-spinoffs] event.keyCode broken in prototype? > > > > Code? Can’t help much without seeing what you’re doing. > > > > > > ------------------------------------------------------------------------ > > *From:* rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] *On Behalf Of > *Ryan Gahl > *Sent:* Friday, March 03, 2006 1:48 PM > *To:* rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > *Subject:* [Rails-spinoffs] event.keyCode broken in prototype? > > > > I ran 2 tests. One using proto’s Event.observe, and another using an > in-line handler of the “keydown” event in a textbox. > > > > Using .bindAsEventListener, the event.keyCode is always returning a > capital letter, no matter what. The in-line event handler returns > lowercase vs. uppercase correctly… What’s going on? > > > > I guess I find it hard to believe no one has tried capturing keyboard > events before, so I’m hoping I’m just royally screwing something up. Can > anyone help me on this? > > The information transmitted in this electronic mail is intended only for > the person or entity to which it is addressed and may contain > confidential, proprietary, and/or privileged material. Any review, > retransmission, dissemination or other use of, or taking of any action > in reliance upon, this information by persons or entities other than the > intended recipient is prohibited. If you received this in error, please > contact the sender and delete the material from all computers. > > > ------------------------------------------------------------------------ > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Totally disagree. Which is easier? if (keyThatWasPressed.toLowerCase() == "g") << for your "99%" of people or... if (keyThatWasPressed.toLowerCase() == "g") { ...Now figure out if shift and/or capslock is down.. } -----Original Message----- From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Robin Haswell Sent: Friday, March 03, 2006 5:08 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails-spinoffs] event.keyCode broken in prototype? I''d say, returning letters consistently cased makes sense. element.nodeName is always returned in capital letters for the same reason - because 99% of the time the case doesn''t matter, and you really don''t want to be calling case-conversion functions when you just want to see if something == a letter. For the other 1%, I guess yes, people are supposed to test for shift and/or caps lock. -Rob Ryan Gahl wrote:> Yes, prototype handles that (so it does exist) > > > > Function.prototype.bindAsEventListener = function(object) { > > var __method = this; > > return function(event) { > > return __method.call(object, event || window.event); > > } > > } > > > > > > Now... just attaching the event handler as you suggested works (as Iwould> expect). It appears that for some (DAMNEDDDDD) reason, the DOM2 event> handler attachment methods just do not work with the keyCode. It''s > always just returning the UNICODE for the capital letter. That may be > W3C recommended (not sure), but either way, it''s stupid. Stupid Stupid> Stupid. sTUpiD. > > > > Sorry... So now I guess I either use the old method of$(''id'').onkeypress> = method, or I add some stupid "is the shift key down, and if so, isthe> CAPSLOCK key down..." logic... > > > > Hrmm... stupid... > > > >------------------------------------------------------------------------> > *From:* rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] *On Behalf Of > *Gregory Hill > *Sent:* Friday, March 03, 2006 4:14 PM > *To:* rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > *Subject:* RE: [Rails-spinoffs] event.keyCode broken in prototype? > > > > Well, my point was that in IE, the variable that is passed to the > function does not exist, so you need to reference the global ''event'' > object. Or does prototype handle that in the bindAsEventListener code> already? > > > > What happens if you do this, instead of the inline handler? > > $(''id'').onkeypress = showKeyPressed; > > > > That should at least tell you if it''s something specific to using > prototype or whether it just doesn''t work at all if you don''t use an > inline handler. > > > > Greg > > > >------------------------------------------------------------------------> > *From:* rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] *On Behalf Of > *Ryan Gahl > *Sent:* Friday, March 03, 2006 2:31 PM > *To:* rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > *Subject:* RE: [Rails-spinoffs] event.keyCode broken in prototype? > > > > I''ve simplified my example. Changing "evt" to "event" makes no > difference, you can name that parameter anything you want, it''s just a> function argument variable (which is a reference to the actual event > object). > > > > I''m using IE6. I''m implementing a textbox input masking script in a > proto OO behavior class (the script was originally non OO and required> inline event handlers). > > > > Anyway, you can replace my inline example below with > > > > <input type="text" onkeypress="showKeyPressed();" /> > > > > function showKeyPressed () > > { > > alert(String.fromCharCode(event.keyCode)); > > } > > > > ..and get the same results. > > > > I guess I''m at a loss. I can check to see if the shift key is down I > guess (not sure if that also covers CAPSLOCK cases)... it''s verystrange> that it works fine if the event if hooked up inline, and not fineusing> the DOM2 methods... sucks. > > > > > > > >------------------------------------------------------------------------> > *From:* rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] *On Behalf Of > *Gregory Hill > *Sent:* Friday, March 03, 2006 3:23 PM > *To:* rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > *Subject:* RE: [Rails-spinoffs] event.keyCode broken in prototype? > > > > Just a random thought, but what if you change ''evt'' to ''event''. Doesit> work then? What browser are you testing in, btw? My thought isbased> on the fact that event is a global object in IE that gets the lastevent> triggered. I thought that you had to pass the object in as aparameter> in other browsers, though, so I don''t know how your inline handlerwould> work at all in non-IE browsers. But, I''ve been wrong many timesbefore.> > > Greg > > > >------------------------------------------------------------------------> > *From:* rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] *On Behalf Of > *Ryan Gahl > *Sent:* Friday, March 03, 2006 2:16 PM > *To:* rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > *Subject:* RE: [Rails-spinoffs] event.keyCode broken in prototype? > > > > <input type="text" > onkeypress="alert(String.fromCharCode(event.keyCode));" /> > > > > The above returns "g" when "g" is pressed and "G" when "G" is pressed. > > > > WHILE... > > > > <input type="text" id="tb" /> > > > > someClass = Class.create(); > > someClass.prototype > > { > > initialize: function() > > { > > Event.observe($("tb"), "keypress", > this.showkeyPressed.bindAsEventListener(this) ); > > }, > > > > showKeyPressed: function(evt) > > { > > alert(String.fromCharCode(evt.keyCode)); > > } > > }; > > > > ...returns "G" all the time when the g key I pressed, no matter what. > (Simplified example of course) > > > > For some weird reason, the event object from proto''sbindAsEventListener> method is always returning the capitalized keyCode of the key that was> pressed. > > > >------------------------------------------------------------------------> > *From:* rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] *On Behalf Of > *Gregory Hill > *Sent:* Friday, March 03, 2006 3:07 PM > *To:* rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > *Subject:* RE: [Rails-spinoffs] event.keyCode broken in prototype? > > > > Code? Can''t help much without seeing what you''re doing. > > > > > >------------------------------------------------------------------------> > *From:* rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] *On Behalf Of > *Ryan Gahl > *Sent:* Friday, March 03, 2006 1:48 PM > *To:* rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > *Subject:* [Rails-spinoffs] event.keyCode broken in prototype? > > > > I ran 2 tests. One using proto''s Event.observe, and another using an > in-line handler of the "keydown" event in a textbox. > > > > Using .bindAsEventListener, the event.keyCode is always returning a > capital letter, no matter what. The in-line event handler returns > lowercase vs. uppercase correctly... What''s going on? > > > > I guess I find it hard to believe no one has tried capturing keyboard > events before, so I''m hoping I''m just royally screwing something up.Can> anyone help me on this? > > The information transmitted in this electronic mail is intended onlyfor> the person or entity to which it is addressed and may contain > confidential, proprietary, and/or privileged material. Any review, > retransmission, dissemination or other use of, or taking of any action> in reliance upon, this information by persons or entities other thanthe> intended recipient is prohibited. If you received this in error,please> contact the sender and delete the material from all computers. > > >------------------------------------------------------------------------> > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
These inconsistencies exist in ALL the browsers... different cases for each one. Yea yea yea, I like FF better also, but it has just as many problems. No one has made a perfect browser yet. Anyway, I just reverted to using the old event attachment method for this class, so I could use the INTUITIVE .keyCode. -----Original Message----- From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Robin Haswell Sent: Friday, March 03, 2006 5:09 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails-spinoffs] event.keyCode broken in prototype? Because that''s what you get when you produce a product which is a just a series of dirty hacks added on to the last version. Honestly, I would bet any money that is the real answer. -Rob Ryan Gahl wrote:> This is another case of what we were talking about yesterday. Browser > inconsistencies. Why would, in the same browser, attaching an event > handler one way give you different results from attaching it anotherway?> > > >------------------------------------------------------------------------> > *From:* rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] *On Behalf Of > *Ryan Gahl > *Sent:* Friday, March 03, 2006 4:25 PM > *To:* rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > *Subject:* RE: [Rails-spinoffs] event.keyCode broken in prototype? > > > > Yes, prototype handles that (so it does exist) > > > > Function.prototype.bindAsEventListener = function(object) { > > var __method = this; > > return function(event) { > > return __method.call(object, event || window.event); > > } > > } > > > > > > Now... just attaching the event handler as you suggested works (as Iwould> expect). It appears that for some (DAMNEDDDDD) reason, the DOM2 event> handler attachment methods just do not work with the keyCode. It''s > always just returning the UNICODE for the capital letter. That may be > W3C recommended (not sure), but either way, it''s stupid. Stupid Stupid> Stupid. sTUpiD. > > > > Sorry... So now I guess I either use the old method of$(''id'').onkeypress> = method, or I add some stupid "is the shift key down, and if so, isthe> CAPSLOCK key down..." logic... > > > > Hrmm... stupid... > > > >------------------------------------------------------------------------> > *From:* rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] *On Behalf Of > *Gregory Hill > *Sent:* Friday, March 03, 2006 4:14 PM > *To:* rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > *Subject:* RE: [Rails-spinoffs] event.keyCode broken in prototype? > > > > Well, my point was that in IE, the variable that is passed to the > function does not exist, so you need to reference the global ''event'' > object. Or does prototype handle that in the bindAsEventListener code> already? > > > > What happens if you do this, instead of the inline handler? > > $(''id'').onkeypress = showKeyPressed; > > > > That should at least tell you if it''s something specific to using > prototype or whether it just doesn''t work at all if you don''t use an > inline handler. > > > > Greg > > > >------------------------------------------------------------------------> > *From:* rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] *On Behalf Of > *Ryan Gahl > *Sent:* Friday, March 03, 2006 2:31 PM > *To:* rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > *Subject:* RE: [Rails-spinoffs] event.keyCode broken in prototype? > > > > I''ve simplified my example. Changing "evt" to "event" makes no > difference, you can name that parameter anything you want, it''s just a> function argument variable (which is a reference to the actual event > object). > > > > I''m using IE6. I''m implementing a textbox input masking script in a > proto OO behavior class (the script was originally non OO and required> inline event handlers). > > > > Anyway, you can replace my inline example below with > > > > <input type="text" onkeypress="showKeyPressed();" /> > > > > function showKeyPressed () > > { > > alert(String.fromCharCode(event.keyCode)); > > } > > > > ..and get the same results. > > > > I guess I''m at a loss. I can check to see if the shift key is down I > guess (not sure if that also covers CAPSLOCK cases)... it''s verystrange> that it works fine if the event if hooked up inline, and not fineusing> the DOM2 methods... sucks. > > > > > > > >------------------------------------------------------------------------> > *From:* rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] *On Behalf Of > *Gregory Hill > *Sent:* Friday, March 03, 2006 3:23 PM > *To:* rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > *Subject:* RE: [Rails-spinoffs] event.keyCode broken in prototype? > > > > Just a random thought, but what if you change ''evt'' to ''event''. Doesit> work then? What browser are you testing in, btw? My thought isbased> on the fact that event is a global object in IE that gets the lastevent> triggered. I thought that you had to pass the object in as aparameter> in other browsers, though, so I don''t know how your inline handlerwould> work at all in non-IE browsers. But, I''ve been wrong many timesbefore.> > > Greg > > > >------------------------------------------------------------------------> > *From:* rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] *On Behalf Of > *Ryan Gahl > *Sent:* Friday, March 03, 2006 2:16 PM > *To:* rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > *Subject:* RE: [Rails-spinoffs] event.keyCode broken in prototype? > > > > <input type="text" > onkeypress="alert(String.fromCharCode(event.keyCode));" /> > > > > The above returns "g" when "g" is pressed and "G" when "G" is pressed. > > > > WHILE... > > > > <input type="text" id="tb" /> > > > > someClass = Class.create(); > > someClass.prototype > > { > > initialize: function() > > { > > Event.observe($("tb"), "keypress", > this.showkeyPressed.bindAsEventListener(this) ); > > }, > > > > showKeyPressed: function(evt) > > { > > alert(String.fromCharCode(evt.keyCode)); > > } > > }; > > > > ...returns "G" all the time when the g key I pressed, no matter what. > (Simplified example of course) > > > > For some weird reason, the event object from proto''sbindAsEventListener> method is always returning the capitalized keyCode of the key that was> pressed. > > > >------------------------------------------------------------------------> > *From:* rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] *On Behalf Of > *Gregory Hill > *Sent:* Friday, March 03, 2006 3:07 PM > *To:* rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > *Subject:* RE: [Rails-spinoffs] event.keyCode broken in prototype? > > > > Code? Can''t help much without seeing what you''re doing. > > > > > >------------------------------------------------------------------------> > *From:* rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] *On Behalf Of > *Ryan Gahl > *Sent:* Friday, March 03, 2006 1:48 PM > *To:* rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > *Subject:* [Rails-spinoffs] event.keyCode broken in prototype? > > > > I ran 2 tests. One using proto''s Event.observe, and another using an > in-line handler of the "keydown" event in a textbox. > > > > Using .bindAsEventListener, the event.keyCode is always returning a > capital letter, no matter what. The in-line event handler returns > lowercase vs. uppercase correctly... What''s going on? > > > > I guess I find it hard to believe no one has tried capturing keyboard > events before, so I''m hoping I''m just royally screwing something up.Can> anyone help me on this? > > The information transmitted in this electronic mail is intended onlyfor> the person or entity to which it is addressed and may contain > confidential, proprietary, and/or privileged material. Any review, > retransmission, dissemination or other use of, or taking of any action> in reliance upon, this information by persons or entities other thanthe> intended recipient is prohibited. If you received this in error,please> contact the sender and delete the material from all computers. > > >------------------------------------------------------------------------> > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs