Tuesday, 15 March 2011

In this code, copied from ch 15 of eloquent javascript, what does the keyup event listener do? -



In this code, copied from ch 15 of eloquent javascript, what does the keyup event listener do? -

in next code, copied ch 15 of eloquent javascript, how pressed[codes[event.keycode]] end boolean value? can't figure out why need 'keyup' event listener.

the thought create sure 'keydown' gets registered 1 time when beingness held down. thought maybe keyup event gets fired when holding key down, mdn reference on keydown event suggests, resource says functionality discontinued.

var arrowcodes = {37: "left", 38: "up", 39: "right"}; function trackkeys(codes) { var pressed = object.create(null); function handler(event) { if (codes.hasownproperty(event.keycode)) { var downwards = event.type == "keydown"; pressed[codes[event.keycode]] = down; event.preventdefault(); } } addeventlistener("keydown", handler); addeventlistener("keyup", handler); homecoming pressed; }

here text explaining block of code. don't @ all--where true , false come from?

note how same handler function used both event types. looks @ event object’s type property determine whether key state should updated true ("keydown") or false ("keyup").

var downwards = event.type == "keydown";

is same as

var down; if ( event.type == "keydown" ) { downwards = true; } else { downwards = false; }

if question else, please indicate so.

javascript events javascript-events event-handling

No comments:

Post a Comment