ShadowWares Forum

Programming (Languages) => PHP, HTML, CSS, XML, Javascript, Database => ข้อความที่เริ่มโดย: ShadowMan ที่ ธันวาคม 13, 2015, 05:46:09 pm



หัวข้อ: JavaScript Listens Impotent Events
เริ่มหัวข้อโดย: ShadowMan ที่ ธันวาคม 13, 2015, 05:46:09 pm
JavaScript Listens Impotent Events



(http://upic.me/i/zk/events.jpg)

Code:
window.onload = function() {

var _debug = true;

window_width  = window.innerWidth;
window_height = window.innerHeight;

if(_debug) console.log(window_width);
if(_debug) console.log(window_height);


window.addEventListener("mousemove", function(e){
if(_debug) console.log("MousePos[" + "X: " + e.clientX + " Y: " + e.clientY +"]");
});

window.addEventListener("mousedown", function(e){
if(_debug) console.log("MouseDown[" + "X: " + e.clientX + " Y: " + e.clientY +"]");
});

window.addEventListener("mouseup", function(e){
if(_debug) console.log("MouseUp[" + "X: " + e.clientX + " Y: " + e.clientY +"]");
});

window.addEventListener("click", function(e){
if(_debug) console.log("Clicked[" + "X: " + e.clientX + " Y: " + e.clientY +"]");
});

window.addEventListener("keydown", function(e){
console.log("KeyDown[which: " + e.which +"]");
});

window.addEventListener("keyup", function(e){
console.log("KeyUp[which: " + e.which +"]");
});


window.addEventListener("keypress", function(e){
console.log("KeyPress[char: " + String.fromCharCode(e.charCode) + "]");
});

window.addEventListener("resize", function(e){
window_width  = window.innerWidth;
window_height = window.innerHeight;
if(_debug) console.log("Size[" + "X: " + window_width + " Y: " + window_height +"]");
});

}