From e7c5ffe5e8422c9c4f99ad4e2a3660162b8df0b6 Mon Sep 17 00:00:00 2001 From: Fred Chien Date: Fri, 10 Feb 2012 19:59:08 +0800 Subject: [PATCH] Add a public API to Mouse and Keyboard class, make it be able to set handlers of event in runtime. --- include/input.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/include/input.js b/include/input.js index 3124d083..2a90a639 100644 --- a/include/input.js +++ b/include/input.js @@ -438,6 +438,16 @@ that.ungrab = function() { //Util.Debug(">> Keyboard.ungrab"); }; +that.set_handler = function(handlers) { + if (!handlers) + return; + + for (var name in handlers) { + if (name == 'onKeyPress') + conf[name] = handlers[name]; + } +}; + return that; // Return the public API interface } // End of Keyboard() @@ -614,6 +624,16 @@ that.ungrab = function() { //Util.Debug(">> Mouse.ungrab"); }; +that.set_handler = function(handlers) { + if (!handlers) + return; + + for (var name in handlers) { + if (name == 'onMouseButton' || name == 'onMouseMove') + conf[name] = handlers[name]; + } +}; + return that; // Return the public API interface } // End of Mouse() @@ -1881,4 +1901,4 @@ unicodeTable = { 0x28fd : 0x10028fd, 0x28fe : 0x10028fe, 0x28ff : 0x10028ff -}; \ No newline at end of file +};