Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $.ready(function() {
  2.     function synthesizeEvent(type, keyCode) {
  3.             var e = new Event(type);
  4.             e.keyCode = keyCode;
  5.             document.dispatchEvent(e);
  6.     }
  7.  
  8.     function fakeKeypress(keyCode) {
  9.              synthesizeEvent('keydown', keyCode);
  10.              synthesizeEvent('keypress', keyCode);
  11.              setTimeout(function() {synthesizeEvent('keyup', keyCode); }, 30);
  12.     }
  13.  
  14.     $.extend($.keyboard.keyaction, {
  15.         coin:  function(base) { fakeKeypress(53); },
  16.         p1:    function(base) { fakeKeypress(49); },
  17.         p2:    function(base) { fakeKeypress(50); },
  18.         up:    function(base) { fakeKeypress(38); },
  19.         left:  function(base) { fakeKeypress(37); },
  20.         right: function(base) { fakeKeypress(39); },
  21.         down:  function(base) { fakeKeypress(40); }
  22.     });
  23.  
  24.     $('#keyboard').keyboard({
  25.         layout : 'custom',
  26.         restrictInput : false, // Prevent keys not in the displayed keyboard from being typed in
  27.         preventPaste : true,  // prevent ctrl-v and right click
  28.         autoAccept : true,
  29.         usePreview : false,
  30.         alwaysOpen : true,
  31.         useCombos : false,
  32.         customLayout: {
  33.             'default' : [
  34.                 '{coin}',
  35.                 '{p1}',
  36.                 '{p2}',
  37.                         '{up}',
  38.                         '{left} {right}',
  39.                         '{down}'
  40.             ]
  41.         },
  42.         display: {
  43.             'coin': 'INSERT COIN',
  44.             'p1': 'PLAYER 1',
  45.             'p2': 'PLAYER 2',
  46.                 'up': '\u2191',
  47.                 'left': '\u2190',
  48.                 'right': '\u2192',
  49.                 'down': '\u2193'
  50.         }
  51.     });
  52. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement