I am trying to detect if the control key has been pressed to change and action. I am using the latest proto build. Here is my code: <script type="text/javascript"> document.observe(''keydown'', function(k) { if (k.keyCode != 17) return; alert(''ctrl''); }); </script> For the control key, it will only trigger the alert every other time the key is pressed. For other keys it works every time thou. Can you offer any advice. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
For other readers: Several replies in louis'' cross-posted thread http://groups.google.com/group/prototype-core/browse_thread/thread/50b00979f9d54d82 As kangax indicated, best to continue the discussion (if needed) here in spinoffs, not there in core. On Mar 6, 4:44 pm, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am trying to detect if the control key has been pressed to change > and action. I am using the latest proto build. > > Here is my code: > > <script type="text/javascript"> > document.observe(''keydown'', function(k) { > if (k.keyCode != 17) return; > alert(''ctrl''); > }); > </script> > > For the control key, it will only trigger the alert every other time > the key is pressed. For other keys it works every time thou. > > Can you offer any advice.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks TJ. Does anyone have thoughts on this? The solution proposed by tancurrom seems kind of long. I would think that proto would have the cross- browser keydown stuff already built in. On Mar 7, 7:07 am, "T.J. Crowder" <tjcrow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> For other readers: Several replies in louis'' cross-posted threadhttp://groups.google.com/group/prototype-core/browse_thread/thread/50... > > As kangax indicated, best to continue the discussion (if needed) here > in spinoffs, not there in core. > > On Mar 6, 4:44 pm, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I am trying to detect if the control key has been pressed to change > > and action. I am using the latest proto build. > > > Here is my code: > > > <script type="text/javascript"> > > document.observe(''keydown'', function(k) { > > if (k.keyCode != 17) return; > > alert(''ctrl''); > > }); > > </script> > > > For the control key, it will only trigger the alert every other time > > the key is pressed. For other keys it works every time thou. > > > Can you offer any advice.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Observing "keydown" and checking event''s "ctrlKey" seems to be somewhat consistent. There''s a great article describing what the state of key detection is these days http://unixpapa.com/js/key.html Best, kangax On Mar 7, 12:18 pm, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks TJ. > > Does anyone have thoughts on this? The solution proposed by tancurrom > seems kind of long. I would think that proto would have the cross- > browser keydown stuff already built in. > > On Mar 7, 7:07 am, "T.J. Crowder" <tjcrow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > For other readers: Several replies in louis'' cross-posted threadhttp://groups.google.com/group/prototype-core/browse_thread/thread/50... > > > As kangax indicated, best to continue the discussion (if needed) here > > in spinoffs, not there in core. > > > On Mar 6, 4:44 pm, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I am trying to detect if the control key has been pressed to change > > > and action. I am using the latest proto build. > > > > Here is my code: > > > > <script type="text/javascript"> > > > document.observe(''keydown'', function(k) { > > > if (k.keyCode != 17) return; > > > alert(''ctrl''); > > > }); > > > </script> > > > > For the control key, it will only trigger the alert every other time > > > the key is pressed. For other keys it works every time thou. > > > > Can you offer any advice.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
My solution is quite long, but only for usability. It can be reduced further to this... Object.extend(Array.prototype,{ inArray: function(value) { for (var i = 0, item; item = this[i]; i++) if (item === value) return true; return false; } }); Object.extend(Event,{ isKey: function(event, key, modifiers) { var KeyCode = function(event) { return Try.these( function() { return event.keyCode }, function() { return event.which }, function() { return event.charCode } ) || false } var withModifiers = function(event, keys) { if (!keys) return true var modifiers = [''shift'',''ctrl'',''alt''], check = [] modifiers.each(function(key, index){ if (keys.inArray(key)) check[check.length] = event[key+''Key''] }) return check.all() } if ( (KeyCode(event) == key) && (!modifiers ? true : withModifiers(event, modifiers)) ) return true return false } }); Some example usage.... document.observe(''keydown'',function(event){ if (Event.isKey(event,65)) { console.log(''a was pressed'') } if (Event.isKey(event,65,[''shift''])) { console.log(''a was pressed with shift (A)'') } if (Event.isKey(event,65,[''shift'',''ctrl''])) { console.log(''a was pressed with shift && ctrl (A)'') } }) As you can see... The first argument is the event, second is the keyCode to check, third is optional modifiers (shift, ctrl, alt). Hope this helps. On Mar 7, 7:32 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Observing "keydown" and checking event''s "ctrlKey" seems to be > somewhat consistent. > There''s a great article describing what the state of key detection is > these dayshttp://unixpapa.com/js/key.html > > Best, > kangax > > On Mar 7, 12:18 pm, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Thanks TJ. > > > Does anyone have thoughts on this? The solution proposed by tancurrom > > seems kind of long. I would think that proto would have the cross- > > browser keydown stuff already built in. > > > On Mar 7, 7:07 am, "T.J. Crowder" <tjcrow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > For other readers: Several replies in louis'' cross-posted threadhttp://groups.google.com/group/prototype-core/browse_thread/thread/50... > > > > As kangax indicated, best to continue the discussion (if needed) here > > > in spinoffs, not there in core. > > > > On Mar 6, 4:44 pm, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I am trying to detect if the control key has been pressed to change > > > > and action. I am using the latest proto build. > > > > > Here is my code: > > > > > <script type="text/javascript"> > > > > document.observe(''keydown'', function(k) { > > > > if (k.keyCode != 17) return; > > > > alert(''ctrl''); > > > > }); > > > > </script> > > > > > For the control key, it will only trigger the alert every other time > > > > the key is pressed. For other keys it works every time thou. > > > > > Can you offer any advice.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Array.prototype.inArray looks very much like Enumerable#include [1] which Array.prototype mixes in. The only difference is your method does identity comparison and #include does equality one (which should be enough in this case). [1] http://www.prototypejs.org/api/enumerable/include - kangax On Mar 9, 2:35 pm, tancurrom <tancur...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> My solution is quite long, but only for usability. It can be reduced > further to this... > > Object.extend(Array.prototype,{ > inArray: function(value) { > for (var i = 0, item; item = this[i]; i++) if (item === value) return > true; > return false; > } > > }); > > Object.extend(Event,{ > isKey: function(event, key, modifiers) { > var KeyCode = function(event) { > return Try.these( > function() { return event.keyCode }, > function() { return event.which }, > function() { return event.charCode } > ) || false > } > var withModifiers = function(event, keys) { > if (!keys) return true > var modifiers = [''shift'',''ctrl'',''alt''], check = [] > modifiers.each(function(key, index){ > if (keys.inArray(key)) check[check.length] = event[key+''Key''] > }) > return check.all() > } > if ( (KeyCode(event) == key) && (!modifiers ? true : > withModifiers(event, modifiers)) ) return true > return false > } > > }); > > Some example usage.... > > document.observe(''keydown'',function(event){ > if (Event.isKey(event,65)) { > console.log(''a was pressed'') > } > if (Event.isKey(event,65,[''shift''])) { > console.log(''a was pressed with shift (A)'') > } > if (Event.isKey(event,65,[''shift'',''ctrl''])) { > console.log(''a was pressed with shift && ctrl (A)'') > } > > }) > > As you can see... The first argument is the event, second is the > keyCode to check, third is optional > modifiers (shift, ctrl, alt). > Hope this helps. > > On Mar 7, 7:32 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Observing "keydown" and checking event''s "ctrlKey" seems to be > > somewhat consistent. > > There''s a great article describing what the state of key detection is > > these dayshttp://unixpapa.com/js/key.html > > > Best, > > kangax > > > On Mar 7, 12:18 pm, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Thanks TJ. > > > > Does anyone have thoughts on this? The solution proposed by tancurrom > > > seems kind of long. I would think that proto would have the cross- > > > browser keydown stuff already built in. > > > > On Mar 7, 7:07 am, "T.J. Crowder" <tjcrow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > For other readers: Several replies in louis'' cross-posted threadhttp://groups.google.com/group/prototype-core/browse_thread/thread/50... > > > > > As kangax indicated, best to continue the discussion (if needed) here > > > > in spinoffs, not there in core. > > > > > On Mar 6, 4:44 pm, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > I am trying to detect if the control key has been pressed to change > > > > > and action. I am using the latest proto build. > > > > > > Here is my code: > > > > > > <script type="text/javascript"> > > > > > document.observe(''keydown'', function(k) { > > > > > if (k.keyCode != 17) return; > > > > > alert(''ctrl''); > > > > > }); > > > > > </script> > > > > > > For the control key, it will only trigger the alert every other time > > > > > the key is pressed. For other keys it works every time thou. > > > > > > Can you offer any advice.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks kangax. Its much easier to use that. In this case it''s possible to use include because === type comparison isn''t needed. I originally only used my own method because I needed it somewhere else in the app and don''t now Enumerable that well. On Mar 10, 12:28 am, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Array.prototype.inArray looks very much like Enumerable#include [1] > which Array.prototype mixes in. The only difference is your method > does identity comparison and #include does equality one (which should > be enough in this case). > > [1]http://www.prototypejs.org/api/enumerable/include > > - kangax > > On Mar 9, 2:35 pm, tancurrom <tancur...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > My solution is quite long, but only for usability. It can be reduced > > further to this... > > > Object.extend(Array.prototype,{ > > inArray: function(value) { > > for (var i = 0, item; item = this[i]; i++) if (item === value) return > > true; > > return false; > > } > > > }); > > > Object.extend(Event,{ > > isKey: function(event, key, modifiers) { > > var KeyCode = function(event) { > > return Try.these( > > function() { return event.keyCode }, > > function() { return event.which }, > > function() { return event.charCode } > > ) || false > > } > > var withModifiers = function(event, keys) { > > if (!keys) return true > > var modifiers = [''shift'',''ctrl'',''alt''], check = [] > > modifiers.each(function(key, index){ > > if (keys.inArray(key)) check[check.length] = event[key+''Key''] > > }) > > return check.all() > > } > > if ( (KeyCode(event) == key) && (!modifiers ? true : > > withModifiers(event, modifiers)) ) return true > > return false > > } > > > }); > > > Some example usage.... > > > document.observe(''keydown'',function(event){ > > if (Event.isKey(event,65)) { > > console.log(''a was pressed'') > > } > > if (Event.isKey(event,65,[''shift''])) { > > console.log(''a was pressed with shift (A)'') > > } > > if (Event.isKey(event,65,[''shift'',''ctrl''])) { > > console.log(''a was pressed with shift && ctrl (A)'') > > } > > > }) > > > As you can see... The first argument is the event, second is the > > keyCode to check, third is optional > > modifiers (shift, ctrl, alt). > > Hope this helps. > > > On Mar 7, 7:32 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Observing "keydown" and checking event''s "ctrlKey" seems to be > > > somewhat consistent. > > > There''s a great article describing what the state of key detection is > > > these dayshttp://unixpapa.com/js/key.html > > > > Best, > > > kangax > > > > On Mar 7, 12:18 pm, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Thanks TJ. > > > > > Does anyone have thoughts on this? The solution proposed by tancurrom > > > > seems kind of long. I would think that proto would have the cross- > > > > browser keydown stuff already built in. > > > > > On Mar 7, 7:07 am, "T.J. Crowder" <tjcrow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > For other readers: Several replies in louis'' cross-posted threadhttp://groups.google.com/group/prototype-core/browse_thread/thread/50... > > > > > > As kangax indicated, best to continue the discussion (if needed) here > > > > > in spinoffs, not there in core. > > > > > > On Mar 6, 4:44 pm, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > I am trying to detect if the control key has been pressed to change > > > > > > and action. I am using the latest proto build. > > > > > > > Here is my code: > > > > > > > <script type="text/javascript"> > > > > > > document.observe(''keydown'', function(k) { > > > > > > if (k.keyCode != 17) return; > > > > > > alert(''ctrl''); > > > > > > }); > > > > > > </script> > > > > > > > For the control key, it will only trigger the alert every other time > > > > > > the key is pressed. For other keys it works every time thou. > > > > > > > Can you offer any advice.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, I tried your solution and can not get it to work. Here is the test page: http://tinyurl.com/3xd4md On Mar 9, 2:35 pm, tancurrom <tancur...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> My solution is quite long, but only for usability. It can be reduced > further to this... > > Object.extend(Array.prototype,{ > inArray: function(value) { > for (var i = 0, item; item = this[i]; i++) if (item === value) return > true; > return false; > } > > }); > > Object.extend(Event,{ > isKey: function(event, key, modifiers) { > var KeyCode = function(event) { > return Try.these( > function() { return event.keyCode }, > function() { return event.which }, > function() { return event.charCode } > ) || false > } > var withModifiers = function(event, keys) { > if (!keys) return true > var modifiers = [''shift'',''ctrl'',''alt''], check = [] > modifiers.each(function(key, index){ > if (keys.inArray(key)) check[check.length] = event[key+''Key''] > }) > return check.all() > } > if ( (KeyCode(event) == key) && (!modifiers ? true : > withModifiers(event, modifiers)) ) return true > return false > } > > }); > > Some example usage.... > > document.observe(''keydown'',function(event){ > if (Event.isKey(event,65)) { > console.log(''a was pressed'') > } > if (Event.isKey(event,65,[''shift''])) { > console.log(''a was pressed with shift (A)'') > } > if (Event.isKey(event,65,[''shift'',''ctrl''])) { > console.log(''a was pressed with shift && ctrl (A)'') > } > > }) > > As you can see... The first argument is the event, second is the > keyCode to check, third is optional > modifiers (shift, ctrl, alt). > Hope this helps. > > On Mar 7, 7:32 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Observing "keydown" and checking event''s "ctrlKey" seems to be > > somewhat consistent. > > There''s a great article describing what the state of key detection is > > these dayshttp://unixpapa.com/js/key.html > > > Best, > > kangax > > > On Mar 7, 12:18 pm, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Thanks TJ. > > > > Does anyone have thoughts on this? The solution proposed by tancurrom > > > seems kind of long. I would think that proto would have the cross- > > > browser keydown stuff already built in. > > > > On Mar 7, 7:07 am, "T.J. Crowder" <tjcrow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > For other readers: Several replies in louis'' cross-posted threadhttp://groups.google.com/group/prototype-core/browse_thread/thread/50... > > > > > As kangax indicated, best to continue the discussion (if needed) here > > > > in spinoffs, not there in core. > > > > > On Mar 6, 4:44 pm, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > I am trying to detect if the control key has been pressed to change > > > > > and action. I am using the latest proto build. > > > > > > Here is my code: > > > > > > <script type="text/javascript"> > > > > > document.observe(''keydown'', function(k) { > > > > > if (k.keyCode != 17) return; > > > > > alert(''ctrl''); > > > > > }); > > > > > </script> > > > > > > For the control key, it will only trigger the alert every other time > > > > > the key is pressed. For other keys it works every time thou. > > > > > > Can you offer any advice.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Got it working, there was a bunch of missing ; I am getting the same results thou. I press CTRL and i get the alert, hit it again and nothing, hit it again and it alerts. It''s only alerting every other time i press the CTRL key. I am on FF on Mac. On Mar 11, 10:38 am, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, I tried your solution and can not get it to work. Here is the test > page:http://tinyurl.com/3xd4md > > On Mar 9, 2:35 pm, tancurrom <tancur...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > My solution is quite long, but only for usability. It can be reduced > > further to this... > > > Object.extend(Array.prototype,{ > > inArray: function(value) { > > for (var i = 0, item; item = this[i]; i++) if (item === value) return > > true; > > return false; > > } > > > }); > > > Object.extend(Event,{ > > isKey: function(event, key, modifiers) { > > var KeyCode = function(event) { > > return Try.these( > > function() { return event.keyCode }, > > function() { return event.which }, > > function() { return event.charCode } > > ) || false > > } > > var withModifiers = function(event, keys) { > > if (!keys) return true > > var modifiers = [''shift'',''ctrl'',''alt''], check = [] > > modifiers.each(function(key, index){ > > if (keys.inArray(key)) check[check.length] = event[key+''Key''] > > }) > > return check.all() > > } > > if ( (KeyCode(event) == key) && (!modifiers ? true : > > withModifiers(event, modifiers)) ) return true > > return false > > } > > > }); > > > Some example usage.... > > > document.observe(''keydown'',function(event){ > > if (Event.isKey(event,65)) { > > console.log(''a was pressed'') > > } > > if (Event.isKey(event,65,[''shift''])) { > > console.log(''a was pressed with shift (A)'') > > } > > if (Event.isKey(event,65,[''shift'',''ctrl''])) { > > console.log(''a was pressed with shift && ctrl (A)'') > > } > > > }) > > > As you can see... The first argument is the event, second is the > > keyCode to check, third is optional > > modifiers (shift, ctrl, alt). > > Hope this helps. > > > On Mar 7, 7:32 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Observing "keydown" and checking event''s "ctrlKey" seems to be > > > somewhat consistent. > > > There''s a great article describing what the state of key detection is > > > these dayshttp://unixpapa.com/js/key.html > > > > Best, > > > kangax > > > > On Mar 7, 12:18 pm, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Thanks TJ. > > > > > Does anyone have thoughts on this? The solution proposed by tancurrom > > > > seems kind of long. I would think that proto would have the cross- > > > > browser keydown stuff already built in. > > > > > On Mar 7, 7:07 am, "T.J. Crowder" <tjcrow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > For other readers: Several replies in louis'' cross-posted threadhttp://groups.google.com/group/prototype-core/browse_thread/thread/50... > > > > > > As kangax indicated, best to continue the discussion (if needed) here > > > > > in spinoffs, not there in core. > > > > > > On Mar 6, 4:44 pm, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > I am trying to detect if the control key has been pressed to change > > > > > > and action. I am using the latest proto build. > > > > > > > Here is my code: > > > > > > > <script type="text/javascript"> > > > > > > document.observe(''keydown'', function(k) { > > > > > > if (k.keyCode != 17) return; > > > > > > alert(''ctrl''); > > > > > > }); > > > > > > </script> > > > > > > > For the control key, it will only trigger the alert every other time > > > > > > the key is pressed. For other keys it works every time thou. > > > > > > > Can you offer any advice.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
OMG. SORRY! I am looking at the wrong page, sorry for the million crazy emails. I still can not get your code to work, I added some missing ; but don''t know if i got them all. The page is still here: http://tinyurl.com/3xd4md On Mar 11, 10:38 am, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, I tried your solution and can not get it to work. Here is the test > page:http://tinyurl.com/3xd4md > > On Mar 9, 2:35 pm, tancurrom <tancur...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > My solution is quite long, but only for usability. It can be reduced > > further to this... > > > Object.extend(Array.prototype,{ > > inArray: function(value) { > > for (var i = 0, item; item = this[i]; i++) if (item === value) return > > true; > > return false; > > } > > > }); > > > Object.extend(Event,{ > > isKey: function(event, key, modifiers) { > > var KeyCode = function(event) { > > return Try.these( > > function() { return event.keyCode }, > > function() { return event.which }, > > function() { return event.charCode } > > ) || false > > } > > var withModifiers = function(event, keys) { > > if (!keys) return true > > var modifiers = [''shift'',''ctrl'',''alt''], check = [] > > modifiers.each(function(key, index){ > > if (keys.inArray(key)) check[check.length] = event[key+''Key''] > > }) > > return check.all() > > } > > if ( (KeyCode(event) == key) && (!modifiers ? true : > > withModifiers(event, modifiers)) ) return true > > return false > > } > > > }); > > > Some example usage.... > > > document.observe(''keydown'',function(event){ > > if (Event.isKey(event,65)) { > > console.log(''a was pressed'') > > } > > if (Event.isKey(event,65,[''shift''])) { > > console.log(''a was pressed with shift (A)'') > > } > > if (Event.isKey(event,65,[''shift'',''ctrl''])) { > > console.log(''a was pressed with shift && ctrl (A)'') > > } > > > }) > > > As you can see... The first argument is the event, second is the > > keyCode to check, third is optional > > modifiers (shift, ctrl, alt). > > Hope this helps. > > > On Mar 7, 7:32 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Observing "keydown" and checking event''s "ctrlKey" seems to be > > > somewhat consistent. > > > There''s a great article describing what the state of key detection is > > > these dayshttp://unixpapa.com/js/key.html > > > > Best, > > > kangax > > > > On Mar 7, 12:18 pm, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Thanks TJ. > > > > > Does anyone have thoughts on this? The solution proposed by tancurrom > > > > seems kind of long. I would think that proto would have the cross- > > > > browser keydown stuff already built in. > > > > > On Mar 7, 7:07 am, "T.J. Crowder" <tjcrow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > For other readers: Several replies in louis'' cross-posted threadhttp://groups.google.com/group/prototype-core/browse_thread/thread/50... > > > > > > As kangax indicated, best to continue the discussion (if needed) here > > > > > in spinoffs, not there in core. > > > > > > On Mar 6, 4:44 pm, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > I am trying to detect if the control key has been pressed to change > > > > > > and action. I am using the latest proto build. > > > > > > > Here is my code: > > > > > > > <script type="text/javascript"> > > > > > > document.observe(''keydown'', function(k) { > > > > > > if (k.keyCode != 17) return; > > > > > > alert(''ctrl''); > > > > > > }); > > > > > > </script> > > > > > > > For the control key, it will only trigger the alert every other time > > > > > > the key is pressed. For other keys it works every time thou. > > > > > > > Can you offer any advice.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
The code is fine. The problem is your on a Mac. Mac''s don''t detect control (ctrl - keyCode 17) at all [http://www.quirksmode.org/js/ keys.html#t14]. I believe it detects cmd instead. There are different objects that are detected. On Mar 11, 2:47 pm, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> OMG. SORRY! I am looking at the wrong page, sorry for the million > crazy emails. > > I still can not get your code to work, I added some missing ; but > don''t know if i got them all. The page is still here:http://tinyurl.com/3xd4md > > On Mar 11, 10:38 am, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi, I tried your solution and can not get it to work. Here is the test > > page:http://tinyurl.com/3xd4md > > > On Mar 9, 2:35 pm, tancurrom <tancur...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > My solution is quite long, but only for usability. It can be reduced > > > further to this... > > > > Object.extend(Array.prototype,{ > > > inArray: function(value) { > > > for (var i = 0, item; item = this[i]; i++) if (item === value) return > > > true; > > > return false; > > > } > > > > }); > > > > Object.extend(Event,{ > > > isKey: function(event, key, modifiers) { > > > var KeyCode = function(event) { > > > return Try.these( > > > function() { return event.keyCode }, > > > function() { return event.which }, > > > function() { return event.charCode } > > > ) || false > > > } > > > var withModifiers = function(event, keys) { > > > if (!keys) return true > > > var modifiers = [''shift'',''ctrl'',''alt''], check = [] > > > modifiers.each(function(key, index){ > > > if (keys.inArray(key)) check[check.length] = event[key+''Key''] > > > }) > > > return check.all() > > > } > > > if ( (KeyCode(event) == key) && (!modifiers ? true : > > > withModifiers(event, modifiers)) ) return true > > > return false > > > } > > > > }); > > > > Some example usage.... > > > > document.observe(''keydown'',function(event){ > > > if (Event.isKey(event,65)) { > > > console.log(''a was pressed'') > > > } > > > if (Event.isKey(event,65,[''shift''])) { > > > console.log(''a was pressed with shift (A)'') > > > } > > > if (Event.isKey(event,65,[''shift'',''ctrl''])) { > > > console.log(''a was pressed with shift && ctrl (A)'') > > > } > > > > }) > > > > As you can see... The first argument is the event, second is the > > > keyCode to check, third is optional > > > modifiers (shift, ctrl, alt). > > > Hope this helps. > > > > On Mar 7, 7:32 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Observing "keydown" and checking event''s "ctrlKey" seems to be > > > > somewhat consistent. > > > > There''s a great article describing what the state of key detection is > > > > these dayshttp://unixpapa.com/js/key.html > > > > > Best, > > > > kangax > > > > > On Mar 7, 12:18 pm, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Thanks TJ. > > > > > > Does anyone have thoughts on this? The solution proposed by tancurrom > > > > > seems kind of long. I would think that proto would have the cross- > > > > > browser keydown stuff already built in. > > > > > > On Mar 7, 7:07 am, "T.J. Crowder" <tjcrow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > For other readers: Several replies in louis'' cross-posted threadhttp://groups.google.com/group/prototype-core/browse_thread/thread/50... > > > > > > > As kangax indicated, best to continue the discussion (if needed) here > > > > > > in spinoffs, not there in core. > > > > > > > On Mar 6, 4:44 pm, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > I am trying to detect if the control key has been pressed to change > > > > > > > and action. I am using the latest proto build. > > > > > > > > Here is my code: > > > > > > > > <script type="text/javascript"> > > > > > > > document.observe(''keydown'', function(k) { > > > > > > > if (k.keyCode != 17) return; > > > > > > > alert(''ctrl''); > > > > > > > }); > > > > > > > </script> > > > > > > > > For the control key, it will only trigger the alert every other time > > > > > > > the key is pressed. For other keys it works every time thou. > > > > > > > > Can you offer any advice.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
This works to detect CTRL on mac: http://tinyurl.com/3bm7wc But it only works every other time i press the key. On Mar 11, 1:39 pm, tancurrom <tancur...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> The code is fine. The problem is your on a Mac. Mac''s don''t detect > control (ctrl - keyCode 17) at all [http://www.quirksmode.org/js/ > keys.html#t14]. I believe it detects cmd instead. There are different > objects that are detected. > > On Mar 11, 2:47 pm, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > OMG. SORRY! I am looking at the wrong page, sorry for the million > > crazy emails. > > > I still can not get your code to work, I added some missing ; but > > don''t know if i got them all. The page is still here:http://tinyurl.com/3xd4md > > > On Mar 11, 10:38 am, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi, I tried your solution and can not get it to work. Here is the test > > > page:http://tinyurl.com/3xd4md > > > > On Mar 9, 2:35 pm, tancurrom <tancur...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > > My solution is quite long, but only for usability. It can be reduced > > > > further to this... > > > > > Object.extend(Array.prototype,{ > > > > inArray: function(value) { > > > > for (var i = 0, item; item = this[i]; i++) if (item === value) return > > > > true; > > > > return false; > > > > } > > > > > }); > > > > > Object.extend(Event,{ > > > > isKey: function(event, key, modifiers) { > > > > var KeyCode = function(event) { > > > > return Try.these( > > > > function() { return event.keyCode }, > > > > function() { return event.which }, > > > > function() { return event.charCode } > > > > ) || false > > > > } > > > > var withModifiers = function(event, keys) { > > > > if (!keys) return true > > > > var modifiers = [''shift'',''ctrl'',''alt''], check = [] > > > > modifiers.each(function(key, index){ > > > > if (keys.inArray(key)) check[check.length] = event[key+''Key''] > > > > }) > > > > return check.all() > > > > } > > > > if ( (KeyCode(event) == key) && (!modifiers ? true : > > > > withModifiers(event, modifiers)) ) return true > > > > return false > > > > } > > > > > }); > > > > > Some example usage.... > > > > > document.observe(''keydown'',function(event){ > > > > if (Event.isKey(event,65)) { > > > > console.log(''a was pressed'') > > > > } > > > > if (Event.isKey(event,65,[''shift''])) { > > > > console.log(''a was pressed with shift (A)'') > > > > } > > > > if (Event.isKey(event,65,[''shift'',''ctrl''])) { > > > > console.log(''a was pressed with shift && ctrl (A)'') > > > > } > > > > > }) > > > > > As you can see... The first argument is the event, second is the > > > > keyCode to check, third is optional > > > > modifiers (shift, ctrl, alt). > > > > Hope this helps. > > > > > On Mar 7, 7:32 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Observing "keydown" and checking event''s "ctrlKey" seems to be > > > > > somewhat consistent. > > > > > There''s a great article describing what the state of key detection is > > > > > these dayshttp://unixpapa.com/js/key.html > > > > > > Best, > > > > > kangax > > > > > > On Mar 7, 12:18 pm, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > Thanks TJ. > > > > > > > Does anyone have thoughts on this? The solution proposed by tancurrom > > > > > > seems kind of long. I would think that proto would have the cross- > > > > > > browser keydown stuff already built in. > > > > > > > On Mar 7, 7:07 am, "T.J. Crowder" <tjcrow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > For other readers: Several replies in louis'' cross-posted threadhttp://groups.google.com/group/prototype-core/browse_thread/thread/50... > > > > > > > > As kangax indicated, best to continue the discussion (if needed) here > > > > > > > in spinoffs, not there in core. > > > > > > > > On Mar 6, 4:44 pm, louis w <louiswa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > I am trying to detect if the control key has been pressed to change > > > > > > > > and action. I am using the latest proto build. > > > > > > > > > Here is my code: > > > > > > > > > <script type="text/javascript"> > > > > > > > > document.observe(''keydown'', function(k) { > > > > > > > > if (k.keyCode != 17) return; > > > > > > > > alert(''ctrl''); > > > > > > > > }); > > > > > > > > </script> > > > > > > > > > For the control key, it will only trigger the alert every other time > > > > > > > > the key is pressed. For other keys it works every time thou. > > > > > > > > > Can you offer any advice.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---