keydown - Using Jquery, why is this function being called when I only click one of the two keys? -
i have code:
$(document).bind('keydown', 'ctrl+1', function () { alert('you found hotkey ctrl+1!'); });
but if click on either control or 1 key, code seems fire. want code fire when both keys pressed.
can clarify missing?
as can see in documentation, second argument bind
function eventdata
,
an object containing data passed event handler.
this used access variables outside inner function use handler, avoid problem accessing mutable variables closure.
if want filter keys trigger action handle inside of function.
$(document).bind("keydown", function(ev){ // notice function argument if(ev.ctrlkey && ev.keycode == 49){ // 49 being keycode "1" alert("foo!"); } });
Comments
Post a Comment