Guest User

Keys

a guest
Nov 23rd, 2015
832
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // SilvKeys.js
  3. // Version: 1.00
  4. // License: Credit me: http://creativecommons.org/licenses/by/4.0/
  5. // Special thanks to Zalerinian & Iavra
  6. //=============================================================================
  7. /*:
  8.  * @plugindesc v1.00 Silv KeyMapper <SilvKeys>
  9.  * @author Silver
  10.  *
  11.  * @help
  12.  * Example usage:
  13.  * var myKey = Silv.Keys.fromStringParam('pageup');
  14.  * Silv.Minimap.ScrollKey = Silv.Keys.fromStringParam(Silv.Parameters['home']);
  15.  * Note: string-value is NOT case-sensitive
  16. */
  17.  
  18. var Silv = Silv || {};
  19. Silv.Plugins = Silv.Plugins || {};
  20. Silv.Plugins.Keys = 1.00;
  21. Silv.Keys = Silv.Keys || {};
  22.  
  23. Silv.Keys.MappingInv =
  24. {
  25.     'backspace':8,
  26.     'tab':9,
  27.     'enter':13,
  28.     'shift':16,
  29.     'control':17,
  30.     'alt':18,
  31.     'pause':19,
  32.     'capslock':20,
  33.     'escape':27,
  34.     'space':32,
  35.     'pageup':33,
  36.     'pagedown':34,
  37.     'end':35,
  38.     'home':36,
  39.     'left':37,
  40.     'up':38,
  41.     'right':39,
  42.     'down':40,
  43.     'insert':45,
  44.     'delete':46,
  45.    
  46.     '0':48,
  47.     '1':49,
  48.     '2':50,
  49.     '3':51,
  50.     '4':52,
  51.     '5':53,
  52.     '6':54,
  53.     '7':55,
  54.     '8':56,
  55.     '9':57,
  56.    
  57.     'a':65,
  58.     'b':66,
  59.     'c':67,
  60.     'd':68,
  61.     'e':69,
  62.     'f':70,
  63.     'g':71,
  64.     'h':72,
  65.     'i':73,
  66.     'j':74,
  67.     'k':75,
  68.     'l':76,
  69.     'm':77,
  70.     'n':78,
  71.     'o':79,
  72.     'p':80,
  73.     'q':81,
  74.     'r':82,
  75.     's':83,
  76.     't':84,
  77.     'u':85,
  78.     'v':86,
  79.     'w':87,
  80.     'x':88,
  81.     'y':89,
  82.     'z':90,
  83.    
  84.     'windows_left':91,
  85.     'windows_right':92,
  86.     'media':93,
  87.    
  88.     'numpad0':96,
  89.     'numpad1':97,
  90.     'numpad2':98,
  91.     'numpad3':99,
  92.     'numpad4':100,
  93.     'numpad5':101,
  94.     'numpad6':102,
  95.     'numpad7':103,
  96.     'numpad8':104,
  97.     'numpad9':105,
  98.    
  99.     '*':106,
  100.     '+':107,
  101.     '-':109, // same as 189
  102.     '.':110,
  103.     '/':111,
  104.    
  105.     'f1':112,
  106.     'f2':113,
  107.     'f3':114,
  108.     'f4':115,
  109.     'f5':116,
  110.     'f6':117,
  111.     'f7':118,
  112.     'f8':119,
  113.     'f19':120,
  114.     'f10':121,
  115.     'f11':122,
  116.     'f12':123,
  117.    
  118.     'numlock':144,
  119.     'num_lock':144,
  120.     'scrolllock':145,
  121.     'scroll_lock':145,
  122.     ';':186,
  123.     'semicolon':186,
  124.     'semi_colon':186,
  125.     '=':187,
  126.     'equal':187,
  127.     'equal_sign':187,
  128.     ',':188,
  129.     'comma':188,
  130.     //'-':189, // duplicate of 109
  131.     '.':190,
  132.     'dot':190,
  133.     'decimal':190,
  134.     'decimal_point':190,
  135.     'decimal_dot':190,
  136.     '/':191,
  137.     'forwardslash':191,
  138.     'forward_slash':191,
  139.     'grave_accent':192,
  140.     'graveaccent':192,
  141.     '[':219,
  142.     'openbracket':219,
  143.     'open_bracket':219,
  144.     'backslash':220,
  145.     ']':221,
  146.     'closebracket':221,
  147.     'close_bracket':221,
  148.     'single_quote':222
  149. };
  150. //Input.keyMapper[36] = 'home sweet home'; // DEBUG
  151. //Input.keyMapper[121] = 'f10'; // DEBUG
  152. //Input.keyMapper[187] = 'gregnergnreiogneiogneoi'; // DEBUG, yes even this works!
  153. Silv.Keys.fromStringParam = function(str)
  154. {
  155.     str = str.toLowerCase();
  156.     var keyCode = Silv.Keys.MappingInv[str];
  157.     if (keyCode === undefined) { throw 'No key found for: ' + str; }
  158.     if (Input.keyMapper[keyCode] === undefined) { Input.keyMapper[keyCode] = str; }
  159.     return Input.keyMapper[keyCode];
  160. }
RAW Paste Data