Advertisement
MRDANEEYUL

key to name, name to key

Aug 18th, 2020 (edited)
431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.34 KB | None | 0 0
  1. #macro gp_lstick_up [gp_axislv, -0.1]
  2. #macro gp_lstick_down [gp_axislv, 0.1]
  3. #macro gp_lstick_left [gp_axislh, -0.1]
  4. #macro gp_lstick_right [gp_axislh, 0.1]
  5.  
  6. #macro gp_rstick_up [gp_axisrv, -0.1]
  7. #macro gp_rstick_down [gp_axisrv, 0.1]
  8. #macro gp_rstick_left [gp_axisrh, -0.1]
  9. #macro gp_rstick_right [gp_axisrh, 0.1]
  10.  
  11. /// @description Returns the string name for a GameMaker native key index
  12. /// @param _key
  13. function key_to_name(argument0) {
  14.  
  15. var _key = argument0;
  16. if (_key == "") return "";
  17.  
  18. #region gamepad sticks
  19.  
  20. if (is_array(_key))
  21. {
  22. if (_key[0] == gp_axislv && sign(_key[1]) == -1)
  23. return "LEFT_STICK_UP";
  24. if (_key[0] == gp_axislv && sign(_key[1]) == 1)
  25. return "LEFT_STICK_DOWN";
  26. if (_key[0] == gp_axislh && sign(_key[1]) == -1)
  27. return "LEFT_STICK_LEFT";
  28. if (_key[0] == gp_axislh && sign(_key[1]) == 1)
  29. return "LEFT_STICK_RIGHT";
  30. if (_key[0] == gp_axisrv && sign(_key[1]) == -1)
  31. return "RIGHT_STICK_UP";
  32. if (_key[0] == gp_axisrv && sign(_key[1]) == 1)
  33. return "RIGHT_STICK_DOWN";
  34. if (_key[0] == gp_axisrh && sign(_key[1]) == -1)
  35. return "RIGHT_STICK_LEFT";
  36. if (_key[0] == gp_axisrh && sign(_key[1]) == 1)
  37. return "RIGHT_STICK_RIGHT";
  38. }
  39.  
  40. #endregion gamepad sticks
  41.  
  42. #region A-Z 0-9
  43.  
  44. if ( _key >= ord("A") ) && ( _key <= ord("Z") )
  45. {
  46. var _string = chr( _key );
  47. if ( string_length( _string ) == 1 ) return _string;
  48. }
  49. else if ( _key >= ord("0") ) && ( _key <= ord("9") )
  50. {
  51. var _string = chr( _key );
  52. if ( string_length( _string ) == 1 ) return _string;
  53. }
  54.  
  55. #endregion A-Z 0-9
  56.  
  57. #region Key and button constants
  58.  
  59. switch( _key )
  60. {
  61. case vk_escape: return "ESC"; break;
  62. case vk_shift: return "SHIFT"; break;
  63. case vk_enter: return "ENTER"; break;
  64. case vk_control: return "CTRL"; break;
  65. case vk_alt: return "ALT"; break;
  66. case vk_tab: return "TAB"; break;
  67. case vk_backspace: return "BACK"; break;
  68. case vk_space: return "SPACE"; break;
  69.  
  70. case vk_delete: return "DEL"; break;
  71. case vk_insert: return "INS"; break;
  72. case vk_end: return "END"; break;
  73. case vk_home: return "HOME"; break;
  74. case vk_pagedown: return "PG DN"; break;
  75. case vk_pageup: return "PG UP"; break;
  76.  
  77. case vk_up: return "UP"; break;
  78. case vk_down: return "DOWN"; break;
  79. case vk_left: return "LEFT"; break;
  80. case vk_right: return "RIGHT"; break;
  81.  
  82. case vk_numpad0: return "NUM 0"; break;
  83. case vk_numpad1: return "NUM 1"; break;
  84. case vk_numpad2: return "NUM 2"; break;
  85. case vk_numpad3: return "NUM 3"; break;
  86. case vk_numpad4: return "NUM 4"; break;
  87. case vk_numpad5: return "NUM 5"; break;
  88. case vk_numpad6: return "NUM 6"; break;
  89. case vk_numpad7: return "NUM 7"; break;
  90. case vk_numpad8: return "NUM 8"; break;
  91. case vk_numpad9: return "NUM 9"; break;
  92.  
  93. case vk_add: return "NUM +"; break;
  94. case vk_subtract: return "NUM -"; break;
  95. case vk_divide: return "NUM /"; break;
  96. case vk_multiply: return "NUM *"; break;
  97.  
  98. case gp_padu: return "DPAD_UP"; break;
  99. case gp_padd: return "DPAD_DOWN"; break;
  100. case gp_padl: return "DPAD_LEFT"; break;
  101. case gp_padr: return "DPAD_RIGHT"; break;
  102. case gp_face1: return "FACE1"; break;
  103. case gp_face2: return "FACE2"; break;
  104. case gp_face3: return "FACE3"; break;
  105. case gp_face4: return "FACE4"; break;
  106. case gp_shoulderl: return "LEFT_SHOULDER"; break;
  107. case gp_shoulderlb: return "LEFT_TRIGGER"; break;
  108. case gp_shoulderr: return "RIGHT_SHOULDER"; break;
  109. case gp_shoulderrb: return "RIGHT_TRIGGER"; break;
  110. case gp_start: return "START"; break;
  111. case gp_select: return "SELECT"; break;
  112. case gp_stickl: return "LEFT_STICK_BUTTON"; break;
  113. case gp_stickr: return "RIGHT_STICK_BUTTON"; break;
  114.  
  115. default: return ""; break;
  116. }
  117.  
  118. #endregion Key and button constants
  119.  
  120.  
  121. }
  122. /// @description Returns the GameMaker native key index for a string name
  123. /// @param name
  124. function name_to_key(argument0) {
  125.  
  126. var _string = string_upper( argument0 );
  127. if ( string_length( _string ) == 1 )
  128. {
  129. var _ord = ord( _string );
  130. if ( _ord >= 33 ) && ( _ord <= 126 ) return _ord else return undefined;
  131. }
  132.  
  133. switch( _string )
  134. {
  135. case "ESCAPE": return vk_escape; break;
  136. case "ESC": return vk_escape; break;
  137. case "SHIFT": return vk_shift; break;
  138. case "RETURN": return vk_enter; break;
  139. case "ENTER": return vk_enter; break;
  140. case "CONTROL": return vk_control; break;
  141. case "CTRL": return vk_control; break;
  142. case "ALT": return vk_alt; break;
  143. case "TAB": return vk_tab; break;
  144. case "BACK": return vk_backspace; break;
  145. case "BACKSPACE": return vk_backspace; break;
  146. case "SPACE": return vk_space; break;
  147.  
  148. case "LEFT ALT": return vk_lalt; break;
  149. case "LEFT CONTROL": return vk_lcontrol; break;
  150. case "LEFT CTRL": return vk_lcontrol; break;
  151. case "LEFT SHIFT": return vk_lshift; break;
  152. case "RIGHT ALT": return vk_ralt; break;
  153. case "RIGHT CONTROL": return vk_rcontrol; break;
  154. case "RIGHT CTRL": return vk_rcontrol; break;
  155. case "RIGHT SHIFT": return vk_rshift; break;
  156.  
  157. case "DEL": return vk_delete; break;
  158. case "DELETE": return vk_delete; break;
  159. case "INS": return vk_insert; break;
  160. case "INSERT": return vk_insert; break;
  161. case "END": return vk_end; break;
  162. case "HOME": return vk_home; break;
  163. case "PG DN": return vk_pagedown; break;
  164. case "PAGE DOWN": return vk_pagedown; break;
  165. case "PG UP": return vk_pageup; break;
  166. case "PAGE UP": return vk_pageup; break;
  167.  
  168. case "UP": return vk_up; break;
  169. case "DOWN": return vk_down; break;
  170. case "LEFT": return vk_left; break;
  171. case "RIGHT": return vk_right; break;
  172.  
  173. case "NUMPAD0": return vk_numpad0; break;
  174. case "NUMPAD1": return vk_numpad1; break;
  175. case "NUMPAD2": return vk_numpad2; break;
  176. case "NUMPAD3": return vk_numpad3; break;
  177. case "NUMPAD4": return vk_numpad4; break;
  178. case "NUMPAD5": return vk_numpad5; break;
  179. case "NUMPAD6": return vk_numpad6; break;
  180. case "NUMPAD7": return vk_numpad7; break;
  181. case "NUMPAD8": return vk_numpad8; break;
  182. case "NUMPAD9": return vk_numpad9; break;
  183.  
  184. case "NUM 0": return vk_numpad0; break;
  185. case "NUM 1": return vk_numpad1; break;
  186. case "NUM 2": return vk_numpad2; break;
  187. case "NUM 3": return vk_numpad3; break;
  188. case "NUM 4": return vk_numpad4; break;
  189. case "NUM 5": return vk_numpad5; break;
  190. case "NUM 6": return vk_numpad6; break;
  191. case "NUM 7": return vk_numpad7; break;
  192. case "NUM 8": return vk_numpad8; break;
  193. case "NUM 9": return vk_numpad9; break;
  194.  
  195. case "NUM +": return vk_add; break;
  196. case "NUMPAD+": return vk_add; break;
  197. case "NUMPAD ADD": return vk_add; break;
  198. case "NUMPAD PLUS": return vk_add; break;
  199.  
  200. case "NUM -": return vk_subtract; break;
  201. case "NUMPAD-": return vk_subtract; break;
  202. case "NUMPAD SUBTRACT": return vk_subtract; break;
  203. case "NUMPAD MINUS": return vk_subtract; break;
  204.  
  205. case "NUM /": return vk_divide; break;
  206. case "NUMPAD/": return vk_divide; break;
  207. case "NUMPAD DIVIDE": return vk_divide; break;
  208.  
  209. case "NUM *": return vk_multiply; break;
  210. case "NUMPAD*": return vk_multiply; break;
  211. case "NUMPAD MULTIPLY": return vk_multiply; break;
  212.  
  213. case "DPAD_UP": return gp_padu; break;
  214. case "DPAD_DOWN": return gp_padd; break;
  215. case "DPAD_LEFT": return gp_padl; break;
  216. case "DPAD_RIGHT": return gp_padr; break;
  217. case "LEFT_STICK_UP": return gp_lstick_up; break;
  218. case "LEFT_STICK_DOWN": return gp_lstick_down; break;
  219. case "LEFT_STICK_LEFT": return gp_lstick_left; break;
  220. case "LEFT_STICK_RIGHT": return gp_lstick_right; break;
  221. case "RIGHT_STICK_UP": return gp_rstick_up; break;
  222. case "RIGHT_STICK_DOWN": return gp_rstick_down; break;
  223. case "RIGHT_STICK_LEFT": return gp_rstick_left; break;
  224. case "RIGHT_STICK_RIGHT": return gp_rstick_right; break;
  225. case "FACE1": return gp_face1; break;
  226. case "FACE2": return gp_face2; break;
  227. case "FACE3": return gp_face3; break;
  228. case "FACE4": return gp_face4; break;
  229. case "LEFT_SHOULDER": return gp_shoulderl; break;
  230. case "LEFT_TRIGGER": return gp_shoulderlb; break;
  231. case "RIGHT_SHOULDER": return gp_shoulderr; break;
  232. case "RIGHT_TRIGGER": return gp_shoulderrb; break;
  233. case "START": return gp_start; break;
  234. case "SELECT": return gp_select; break;
  235. case "LEFT_STICK_BUTTON": return gp_stickl; break;
  236. case "RIGHT_STICK_BUTTON": return gp_stickr; break;
  237.  
  238. default: return ""; break;
  239. }
  240.  
  241.  
  242. }
  243.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement