A pixel art painter geared specifically at NES pixel art. Includes export for .chr binary file as well as palette and namespace data.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

759 行
21KB

  1. import {EventCaller} from "/app/js/common/EventCaller.js";
  2. import Utils from "/app/js/common/Utils.js";
  3. // Keycode list based on...
  4. // https://keycode.info/
  5. var KEYBYCODE = {
  6. 3:"break",
  7. 8:"backspace",
  8. 9:"tab",
  9. 13:"enter",
  10. 16:"shift",
  11. 17:"ctrl",
  12. 18:"alt",
  13. 19:"pause",
  14. 20:"capslock",
  15. 27:"esc",
  16. 32:"space",
  17. 33:"pageup",
  18. 34:"pagedown",
  19. 35:"end",
  20. 36:"home",
  21. 37:"left",
  22. 38:"up",
  23. 39:"right",
  24. 40:"down",
  25. 41:"select",
  26. 42:"print",
  27. 43:"execute",
  28. 44:"printscreen",
  29. 45:"insert",
  30. 46:"delete",
  31. 47:"help",
  32. 48:"0",
  33. 49:"1",
  34. 50:"2",
  35. 51:"3",
  36. 52:"4",
  37. 53:"5",
  38. 54:"6",
  39. 55:"7",
  40. 56:"8",
  41. 57:"9",
  42. 65:"a",
  43. 66:"b",
  44. 67:"c",
  45. 68:"d",
  46. 69:"e",
  47. 70:"f",
  48. 71:"g",
  49. 72:"h",
  50. 73:"i",
  51. 74:"j",
  52. 75:"k",
  53. 76:"l",
  54. 77:"m",
  55. 78:"n",
  56. 79:"o",
  57. 80:"p",
  58. 81:"q",
  59. 82:"r",
  60. 83:"s",
  61. 84:"t",
  62. 85:"u",
  63. 86:"v",
  64. 87:"w",
  65. 88:"x",
  66. 89:"y",
  67. 90:"z",
  68. 91:"leftmod", // Window key (left)
  69. 92:"rightwin",// Window key (right)
  70. 93:"rightmod",// Window key (right)
  71. 96:"num0",
  72. 97:"num1",
  73. 98:"num2",
  74. 99:"num3",
  75. 100:"num4",
  76. 101:"num5",
  77. 102:"num6",
  78. 103:"num7",
  79. 104:"num8",
  80. 105:"num9",
  81. 112:"f1",
  82. 113:"f2",
  83. 114:"f3",
  84. 115:"f4",
  85. 116:"f5",
  86. 117:"f6",
  87. 118:"f7",
  88. 119:"f8",
  89. 120:"f9",
  90. 121:"f10",
  91. 122:"f11",
  92. 123:"f12",
  93. 144:"numlock",
  94. 145:"scrolllock",
  95. };
  96. var KEYBYNAME = (function(){
  97. var keys = Object.keys(KEYBYCODE);
  98. var o = {};
  99. for (var i=0; i < keys.length; i++){
  100. if (KEYBYCODE.hasOwnProperty(keys[i])){
  101. o[KEYBYCODE[keys[i]]] = keys[i];
  102. }
  103. }
  104. return o;
  105. })();
  106. var KEYTYPE = {
  107. "number":[48,49,50,51,52,53,54,55,56,57,96,97,98,99,100,101,102,103,104,105],
  108. "letter":[65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90],
  109. "mod":[16,17,18],
  110. "arrow":[37,38,39,40],
  111. "wasd":[87,65,83,68],
  112. "fn":[112,113,114,115,116,117,118,119,120,121,122,123],
  113. "n1":[48,96],
  114. "n2":[49,97],
  115. "n3":[50,98],
  116. "n4":[51,99],
  117. "n5":[52,100],
  118. "n6":[53,101],
  119. "n7":[54,102],
  120. "n8":[55,103],
  121. "n9":[56,104],
  122. "n0":[57,105]
  123. };
  124. var KEYMAP = {
  125. "lastcode":null,
  126. "lastaction":"",
  127. "currentcodes":[]
  128. };
  129. var MOUSEBYCODE = {
  130. 0: "mbl", // (M)ouse (B)utton (L)eft
  131. 1: "mbm", // (M)ouse (B)utton (M)iddle
  132. 2: "mbr" // (M)ouse (B)utton (R)ight
  133. };
  134. var MOUSEBYNAME = {
  135. "mbl": 0,
  136. "mbm": 1,
  137. "mbr": 2
  138. };
  139. // TODO: Reeval this idea.
  140. const KEYPRESS_DELAY = 350; // Time in milliseconds. NOTE: May make this a variable in future.
  141. const MOUSECLICK_DELAY = 350; // Time in milliseconds.
  142. function AssignCodeName(code, name){
  143. name = name.toLowerCase();
  144. var remove = (code in Object.keys(KEYBYCODE));
  145. if (name in Object.keys(KEYBYNAME)){
  146. if (remove && KEYBYCODE[code] === name){
  147. return; // We're being asked to replace the exact same thing. SKIP!
  148. }
  149. throw new ValueError("Key name '" + name + "' already assigned. Cannot use duplicate key names.");
  150. }
  151. if (remove){
  152. delete KEYBYNAME[KEYBYCODE[code]];
  153. }
  154. KEYBYCODE[code] = name;
  155. KEYBYNAME[name] = code;
  156. }
  157. function KeymapContains(code){
  158. return KEYMAP["currentcodes"].findIndex(c=>c[0] == code) >= 0;
  159. }
  160. function AddToKeymap(code, action){
  161. KEYMAP["lastcode"] = code;
  162. KEYMAP["lastaction"] = action;
  163. if (KeymapContains(code) == false){
  164. KEYMAP["currentcodes"].push([code, Math.floor(Date.now())]);
  165. if (KEYMAP["currentcodes"].length > 1){
  166. KEYMAP["currentcodes"].sort(function(a, b){return a[0] - b[0];});
  167. }
  168. return true;
  169. }
  170. return false;
  171. }
  172. function RemoveFromKeymap(code, action){
  173. KEYMAP["lastcode"] = code;
  174. KEYMAP["lastaction"] = action;
  175. var ctime = Math.floor(Date.now());
  176. for (var i=0; i < KEYMAP["currentcodes"].length; i++){
  177. if (KEYMAP["currentcodes"][i][0] === code){
  178. var timediff = ctime - KEYMAP["currentcodes"][i][1];
  179. KEYMAP["currentcodes"].splice(i, 1);
  180. return timediff;
  181. }
  182. }
  183. return -1;
  184. }
  185. function KeyNameToCode(key){
  186. return (key in Object.keys(KEYBYNAME)) ? KEYBYNAME[key] : -1;
  187. }
  188. function CodeToKeyName(code){
  189. return (code in Object.keys(KEYBYCODE)) ? KEYBYCODE[code] : "" + code;
  190. }
  191. function CodesToEventName(codes, mouse){
  192. var ename = "";
  193. mouse = (mouse === true);
  194. for (var i=0; i < codes.length; i++){
  195. if (mouse){
  196. switch(codes[i]){
  197. case 0:
  198. ename += ((ename !== "") ? "+" : "") + "mouseleft";
  199. break;
  200. case 1:
  201. ename += ((ename !== "") ? "+" : "") + "mouseright";
  202. break;
  203. case 2:
  204. ename += ((ename !== "") ? "+" : "") + "mousemiddle";
  205. break;
  206. case 8000:
  207. ename += ((ename !== "") ? "+" : "") + "mousemove";
  208. break;
  209. case 8001:
  210. ename += ((ename !== "") ? "+" : "") + "wheel";
  211. default:
  212. ename += ((ename !== "") ? "+" : "") + "mousebtn" + codes[i].toString();
  213. }
  214. } else {
  215. ename += ((ename !== "") ? "+" : "") + CodeToKeyName(codes[i]);
  216. }
  217. }
  218. return ename;
  219. }
  220. function KeymapEventName(){
  221. return CodesToEventName(KEYMAP["currentcodes"].map(e=>e[0]));
  222. }
  223. function ReorderEventName(ename){
  224. // This function takes a keyboard and mouse event name and reorders it into key-code order.
  225. // This way users can write the event any way they want, but should still result in proper
  226. // event being called.
  227. var elist = ename.split("+");
  228. // TODO: Need to test for duplicate event names for both keyboard and mouse event names.
  229. var ecodes = [];
  230. var mcodes = [];
  231. for (var i=0; i < elist.length; i++){
  232. var key = elist[i].trim().toLowerCase();
  233. // Check for mouse events first. These are hardcoded for now.
  234. if (key === "mouseleft"){
  235. mcodes.push(0);
  236. } else if (key === "mouseright"){
  237. mcodes.push(1);
  238. } else if (key === "mousemiddle"){
  239. mcodes.push(2);
  240. } else if (key.startsWith("mousebtn")){
  241. var sub = key.substring(8);
  242. if (!isNaN(sub)){
  243. mcodes.push(parseInt(sub));
  244. } else {
  245. return ""; // This event name does not include valid mouse button code.
  246. }
  247. } else if (key === "mousemove"){
  248. mcodes.push(8000);
  249. } else if (key === "wheel"){
  250. mcodes.push(8001);
  251. }
  252. // Now handle keyboard event names.
  253. else if (!(key in Object.keys(KEYBYNAME))){
  254. if (!isNaN(key))
  255. ecodes.push(parseInt(key));
  256. else
  257. return ""; // This event name does not include valid key name!
  258. } else {
  259. ecodes.push(KEYBYNAME[key]);
  260. }
  261. }
  262. if (ecodes.length > 0 || mcodes.length > 0){
  263. var rename = "";
  264. if (ecodes.length > 0){
  265. ecodes.sort(function(a, b){return a-b;});
  266. rename = CodesToEventName(ecodes);
  267. }
  268. if (mcodes.length > 0){
  269. mcodes.sort(function(a, b){return a-b;});
  270. rename += ((rename !== "") ? "+" : "") + CodesToEventName(mcodes, true);
  271. }
  272. return rename;
  273. }
  274. return "";
  275. }
  276. export default class Input{
  277. constructor(){
  278. this.__emitter = new EventCaller();
  279. this.__preventDefaults = false;
  280. // Internet Explorer... that fudged up p.o.s. has to make mouse button detection difficult
  281. // with different button values from ALL other browsers. So... if Input has this value set to
  282. // true, then mouseup and mousedown events will base it's detection of IE button values, instead
  283. // of the real values.
  284. this.__ieMouseMode = false;
  285. // If set, this is the element that the mouse will focus on and adjust it's position against.
  286. this.__mouseTarget = null;
  287. this.__mousePosition = null;
  288. this.__mouseLastButton = -1;
  289. this.__mouseLastAction = "";
  290. this.__mouseButtons = [];
  291. this.__keyboardEnabled = false;
  292. this.__mouseEnabled = false;
  293. var buttonID = (function(e){
  294. var btn = e.button;
  295. if ((this.__ieMouseMode && btn === 1) || (!this.__ieMouseMode && btn === 0)){
  296. btn = 0;
  297. } else if ((this.__ieMouseMode && e.button === 4) || (!this.__ieMouseMode && e.button === 1)){
  298. btn = 1;
  299. }
  300. return btn;
  301. }).bind(this);
  302. var addMouseButton = (function(btn){
  303. if (this.__mouseButtons.findIndex(b=>b[0]===btn) < 0){
  304. this.__mouseButtons.push([btn, Math.floor(Date.now())]);
  305. return true;
  306. }
  307. return false;
  308. }).bind(this);
  309. var removeMouseButton = (function(btn){
  310. var idx = this.__mouseButtons.findIndex(b=>b[0]===btn);
  311. var diff = -1;
  312. if (idx >= 0){
  313. diff = Math.floor(Date.now()) - this.__mouseButtons[idx][1];
  314. this.__mouseButtons.splice(idx, 1);
  315. }
  316. return diff;
  317. }).bind(this);
  318. // ---------------------------------------------------------------------
  319. // Handling keyboard events.
  320. this.enableKeyboardInput = (function(){
  321. var handle_keydown = (function(e){
  322. if (AddToKeymap(e.keyCode, "keydown")){
  323. var ename = KeymapEventName();
  324. var edata = {
  325. source: this,
  326. iscombo: (ename.indexOf("+") >= 0),
  327. keys: ename,
  328. keycode:e.keyCode,
  329. keyname:CodeToKeyName(e.keyCode),
  330. action:"keydown"
  331. }
  332. this.__emitter.emit(ename, edata);
  333. this.__emitter.emit("keydown", edata);
  334. }
  335. }).bind(this);
  336. var handle_keyup = (function(e){
  337. var timediff = RemoveFromKeymap(e.keyCode, "keyup");
  338. if (timediff < 0){
  339. console.log("WARNING: Failed to find keycode '" + e.keyCode + "' in the Key Map.");
  340. } else {
  341. var ename = KeymapEventName();
  342. var edata = {
  343. source: this,
  344. iscombo: (ename.indexOf("+") >= 0),
  345. keys: ename,
  346. keycode: e.keyCode,
  347. keyname: CodeToKeyName(e.keyCode),
  348. action:"keyup"
  349. }
  350. if (timediff <= KEYPRESS_DELAY && KEYMAP["currentcodes"].length <= 0){
  351. this.__emitter.emit("keypress", edata);
  352. }
  353. this.__emitter.emit("keyup", edata);
  354. }
  355. }).bind(this);
  356. return (function(enable){
  357. enable = (enable !== false);
  358. // NOTE: There shouldn't be any harm if the user repeatedly enables or disables keyboard.
  359. if (enable){
  360. this.__keyboardEnabled = true;
  361. window.addEventListener("keydown", handle_keydown, false);
  362. window.addEventListener("keyup", handle_keyup, false);
  363. } else {
  364. this.__keyboardEnabled = false;
  365. window.removeEventListener("keydown", handle_keydown);
  366. window.removeEventListener("keyup", handle_keyup);
  367. }
  368. }).bind(this);
  369. }).apply(this);
  370. // ---------------------------------------------------------------------------------------
  371. // Handling mouse events.
  372. var MouseButtonsEventName = (function(){
  373. var e = "";
  374. for (var i=0; i < this.__mouseButtons.length; i++){
  375. e += (e !== "") ? "+" : "";
  376. switch (this.__mouseButtons[i][0]){
  377. case 0:
  378. e += "mouseleft";
  379. break;
  380. case 1:
  381. e += "mouseright";
  382. break;
  383. case 2:
  384. e += "mousemiddle";
  385. break;
  386. default:
  387. e += "mousebtn" + this.__mouseButtons[i][0].toString();
  388. }
  389. }
  390. return e;
  391. }).bind(this);
  392. // This function will only return an event name if keyboard
  393. var MouseEventName = (function(addon){
  394. var ename = KeymapEventName();
  395. var mname = MouseButtonsEventName();
  396. if (mname !== "")
  397. ename += ((ename !== "") ? "+" : "") + mname;
  398. if (typeof(addon) === "string")
  399. ename += ((ename !== "") ? "+" : "") + addon;
  400. return ename;
  401. }).bind(this);
  402. this.enableMouseInput = (function(){
  403. var mousePosition = (function(e){
  404. var pos = {
  405. lastX: (this.__mousePosition !== null) ? this.__mousePosition.x : null,
  406. lastY: (this.__mousePosition !== null) ? this.__mousePosition.y : null,
  407. x: e.clientX,
  408. y: e.clientY,
  409. inbounds: true
  410. }
  411. if (this.__mouseTarget !== null){
  412. var rect = this.__mouseTarget.getBoundingClientRect();
  413. pos.x -= rect.left;
  414. pos.y -= rect.top;
  415. pos.inbounds = (pos.x >= 0 && pos.x < rect.width && pos.y >= 0 && pos.y < rect.height);
  416. }
  417. pos.x = Math.floor(pos.x);
  418. pos.y = Math.floor(pos.y);
  419. return pos;
  420. }).bind(this);
  421. var handle_mousemove = (function(e){
  422. var pos = mousePosition(e);
  423. if (pos.inbounds){
  424. if (this.__preventDefaults){
  425. e.preventDefault();
  426. if (e.stopPropagation)
  427. e.stopPropagation();
  428. e.cancelBubble = true;
  429. }
  430. this.__mousePosition = pos;
  431. this.__mouseLastAction = "mousemove";
  432. var ename = MouseEventName("mousemove");
  433. var data = {
  434. source: this,
  435. lastX: pos.lastX,
  436. lastY: pos.lastY,
  437. x: pos.x,
  438. y: pos.y,
  439. button: this.__mouseLastButton,
  440. delta: 0,
  441. action: "mousemove"
  442. };
  443. if (ename !== "" && ename !== "mousemove")
  444. this.__emitter.emit(ename, data);
  445. this.__emitter.emit("mousemove", data);
  446. }
  447. return false;
  448. }).bind(this);
  449. var handle_mousedown = (function(e){
  450. var button = buttonID(e);
  451. var pos = mousePosition(e);
  452. if (pos.inbounds){
  453. if (this.__preventDefaults){
  454. e.preventDefault();
  455. if (e.stopPropagation)
  456. e.stopPropagation();
  457. e.cancelBubble = true;
  458. }
  459. if (addMouseButton(button)){
  460. var ename = MouseEventName();
  461. var data = {
  462. source: this,
  463. lastX: pos.lastX,
  464. lastY: pos.lastY,
  465. x: pos.x,
  466. y: pos.y,
  467. button: button,
  468. delta: 0,
  469. action: "mousedown"
  470. };
  471. this.__mousePosition = pos;
  472. this.__mouseLastButton = button;
  473. this.__mouseLastAction = "mousedown";
  474. if (ename !== "")
  475. this.__emitter.emit(ename, data);
  476. this.__emitter.emit("mousedown", data);
  477. }
  478. }
  479. return false;
  480. }).bind(this);
  481. var handle_mouseup = (function(e){
  482. var button = buttonID(e);
  483. var pos = mousePosition(e);
  484. // NOTE: I still want to check for button removal, even before testing if an event should
  485. // fire, so that I don't have any phantom buttons listed as "pressed" in the mouseButtons list.
  486. var diff = removeMouseButton(button);
  487. if (pos.inbounds){
  488. if (this.__preventDefaults){
  489. e.preventDefault();
  490. if (e.stopPropagation)
  491. e.stopPropagation();
  492. e.cancelBubble = true;
  493. }
  494. if (diff >= 0){
  495. this.__mousePosition = pos;
  496. this.__mouseLastButton = button;
  497. this.__mouseLastAction = "mouseup";
  498. var data = {
  499. source: this,
  500. lastX: pos.lastX,
  501. lastY: pos.lastY,
  502. x: pos.x,
  503. y: pos.y,
  504. button: button,
  505. delta: 0,
  506. action: "mouseup"
  507. }
  508. this.__emitter.emit("mouseup", data);
  509. if (diff <= MOUSECLICK_DELAY && this.__mouseButtons.length <= 0){
  510. this.__emitter.emit("mouseclick", data);
  511. }
  512. }
  513. }
  514. return false;
  515. }).bind(this);
  516. var handle_mousewheel = (function(e){
  517. var pos = mousePosition(e);
  518. if (pos.inbounds === true){
  519. if (this.__preventDefaults)
  520. e.preventDefault();
  521. var ename = MouseEventName("wheel");
  522. var data = {
  523. source: this,
  524. lastX: pos.lastX,
  525. lastY: pos.lastY,
  526. x: pos.x,
  527. y: pos.y,
  528. button: this.__mouseLastButton,
  529. delta: Math.sign(e.deltaY),
  530. action: "wheel"
  531. };
  532. if (ename !== "wheel")
  533. this.__emitter.emit(ename, data);
  534. if (data.delta < 0)
  535. this.__emitter.emit("wheeldown", data);
  536. if (data.delta > 0)
  537. this.__emitter.emit("wheelup", data);
  538. this.__emitter.emit("wheel", data);
  539. }
  540. }).bind(this);
  541. // This event is purely for preventing Default behaviors on mouse events we're not using.
  542. var handle_mouseprevdef = (function(e){
  543. var pos = mousePosition(e);;
  544. if (this.__preventDefaults && (pos === null || pos.inbounds)){
  545. e.preventDefault();
  546. if (e.stopPropagation)
  547. e.stopPropagation();
  548. e.cancelBubble = true;
  549. }
  550. return false;
  551. }).bind(this);
  552. return (function(enable){
  553. enable = (enable !== false);
  554. // NOTE: There shouldn't be any harm if the user repeatedly enables or disables mouse.
  555. if (enable){
  556. this.__mouseEnabled = true;
  557. window.addEventListener("mousemove", handle_mousemove);
  558. window.addEventListener("mousedown", handle_mousedown);
  559. window.addEventListener("mouseup", handle_mouseup);
  560. window.addEventListener("mousewheel", handle_mousewheel); // For older browsers?
  561. window.addEventListener("wheel", handle_mousewheel);
  562. window.addEventListener("click", handle_mouseprevdef);
  563. window.addEventListener("dblclick", handle_mouseprevdef);
  564. window.addEventListener("contextmenu", handle_mouseprevdef);
  565. } else {
  566. this.__mouseEnabled = false;
  567. window.removeEventListener("mousemove", handle_mousemove);
  568. window.removeEventListener("mousedown", handle_mousedown);
  569. window.removeEventListener("mouseup", handle_mouseup);
  570. window.removeEventListener("mousewheel", handle_mousewheel); // For older browsers?
  571. window.removeEventListener("wheel", handle_mousewheel);
  572. window.removeEventListener("click", handle_mouseprevdef);
  573. window.removeEventListener("dblclick", handle_mouseprevdef);
  574. window.removeEventListener("contextmenu", handle_mouseprevdef);
  575. }
  576. }).bind(this);
  577. }).apply(this);
  578. this.enableKeyboardInput();
  579. this.enableMouseInput();
  580. }
  581. get mouseInputEnabled(){return this.__mouseEnabled;}
  582. get keyboardInputEnabled(){return this.__keyboardEnabled;}
  583. get lastkey(){
  584. if (KEYMAP["lastcode"] !== null){
  585. if (KEYMAP["lastcode"] in Object.keys(KEYBYCODE)){
  586. return KEYBYCODE[KEYMAP["lastcode"]];
  587. }
  588. return "" + KEYMAP["lastcode"];
  589. }
  590. return "0";
  591. }
  592. get lastkeyaction(){
  593. return KEYMAP["lastaction"];
  594. }
  595. get currentKeys(){
  596. return KeymapEventName();
  597. }
  598. get currentKeyCodes(){
  599. return KEYMAP["currentcodes"].map(e=>e[0]);
  600. }
  601. get lastMouseAction(){
  602. return this.__mouseLastAction;
  603. }
  604. get lastMouseButton(){
  605. return this.__mouseLastButton;
  606. }
  607. get lastMousePosition(){
  608. if (this.__mousePosition === null || this.__mousePosition.lastX === null)
  609. return null;
  610. return {
  611. x: this.__mousePosition.lastX,
  612. y: this.__mousePosition.lastY
  613. };
  614. }
  615. get currentMousePosition(){
  616. if (this.__mousePosition === null)
  617. return null;
  618. return {
  619. x: this.__mousePosition.x,
  620. y: this.__mousePosition.y
  621. };
  622. }
  623. get preventDefaults(){return this.__preventDefaults;}
  624. set preventDefaults(p){
  625. this.__preventDefaults = (p === true);
  626. }
  627. get ieMouseMode(){return this.__ieMouseMode;}
  628. set ieMouseMode(m){this.__ieMouseMode = (m === true);}
  629. get mouseTargetElement(){return this.__mouseTarget;}
  630. set mouseTargetElement(el){
  631. if (el === null || Utils.isElement(el)){
  632. this.__mouseTarget = el;
  633. } else {
  634. throw new TypeError("Expected Mouse Target Element to be null or an HTMLElement object.");
  635. }
  636. }
  637. isKeyDown(key){
  638. if (typeof(key) === 'string'){
  639. key = KeyNameToCode(key);
  640. }
  641. for (var i=0; i < KEYMAP["currentcodes"].length; i++){
  642. if (KEYMAP["currentcodes"][i][0] === key){
  643. return true;
  644. }
  645. }
  646. return false;
  647. }
  648. listen(ename, func, owner=null, once=false){
  649. if (([
  650. "keyup",
  651. "keydown",
  652. "keypress",
  653. "mousemove",
  654. "mousedown",
  655. "mouseup",
  656. "mouseclick",
  657. "wheel",
  658. "wheelup",
  659. "wheeldown"
  660. ]).indexOf(ename) >= 0){
  661. this.__emitter.listen(ename, func, owner, once);
  662. } else {
  663. ename = ReorderEventName(ename);
  664. if (ename === ""){
  665. throw new ValueError("Failed to parse key or key combination.");
  666. }
  667. this.__emitter.listen(ename, func, owner, once);
  668. }
  669. return this;
  670. }
  671. unlisten(ename, func, owner=null){
  672. if (([
  673. "keyup",
  674. "keydown",
  675. "keypress",
  676. "mousemove",
  677. "mousedown",
  678. "mouseup",
  679. "mouseclick",
  680. "wheel",
  681. "wheelup",
  682. "wheeldown"
  683. ]).indexOf(ename) >= 0){
  684. this.__emitter.unlisten(ename, func, owner);
  685. } else {
  686. ename = ReorderEventName(ename);
  687. if (ename !== "")
  688. this.__emitter.unlisten(ename, func, owner);
  689. }
  690. return this;
  691. }
  692. }