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: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Robin
Haswell
Sent: Friday, March 03, 2006 5:08 PM
To: rails-spinoffs@lists.rubyonrails.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 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:* [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] *On Behalf Of 
> *Gregory Hill
> *Sent:* Friday, March 03, 2006 4:14 PM
> *To:* rails-spinoffs@lists.rubyonrails.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:* [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] *On Behalf Of 
> *Ryan Gahl
> *Sent:* Friday, March 03, 2006 2:31 PM
> *To:* rails-spinoffs@lists.rubyonrails.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:* [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] *On Behalf Of 
> *Gregory Hill
> *Sent:* Friday, March 03, 2006 3:23 PM
> *To:* rails-spinoffs@lists.rubyonrails.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:* [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] *On Behalf Of 
> *Ryan Gahl
> *Sent:* Friday, March 03, 2006 2:16 PM
> *To:* rails-spinoffs@lists.rubyonrails.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:* [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] *On Behalf Of 
> *Gregory Hill
> *Sent:* Friday, March 03, 2006 3:07 PM
> *To:* rails-spinoffs@lists.rubyonrails.org
> *Subject:* RE: [Rails-spinoffs] event.keyCode broken in prototype?
> 
>  
> 
> Code?  Can't help much without seeing what you're doing.
> 
>  
> 
>  
> 
>
------------------------------------------------------------------------
> 
> *From:* [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] *On Behalf Of 
> *Ryan Gahl
> *Sent:* Friday, March 03, 2006 1:48 PM
> *To:* rails-spinoffs@lists.rubyonrails.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@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

Reply via email to