Advertisement
Guest User

Virtual Key Functions

a guest
Sep 22nd, 2010
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.72 KB | None | 0 0
  1.  
  2. // File Name: vk_keys.inc
  3.  
  4. {
  5. FUNCTIONS INCLUDED:
  6.  
  7. - getKeyState
  8. Type: GET
  9. Description: Get a virtual key state.
  10.  
  11. - setKeyState
  12. Type: SET
  13. Description: Set a virtual key state.
  14.  
  15. - getAsyncKeyState
  16. Type: GET
  17. Description: Get a virtual key state after a previous call to the function.
  18.  
  19. - getKeyPressed
  20. Type: GET
  21. Description: Get the current virtual key pressed.
  22.  
  23. - isKeyPressed
  24. Type: GET
  25. Description: Check for virtual key pressed.
  26.  
  27. - isKeyAlreadyPressed
  28. Type: GET
  29. Description: Check if a virtual key has been already pressed.
  30.  
  31. - isKeyUnPressed
  32. Type: GET
  33. Description: Check if a virtual key has been already pressed.
  34.  
  35. - isKeyStillPressed
  36. Type: GET
  37. Description: Check if a virtual key is still pressed after some seconds.
  38.  
  39. - isAnyKeyPressed
  40. Type: GET
  41. Description: Check for any virtual key pressed.
  42. }
  43.  
  44. :getKeyState
  45. {
  46. Parameters:
  47. Passed:
  48. 0@ - virtual key
  49. Result:
  50. 3@ - virtual key state
  51.  
  52. Example:
  53. 0AB1: call_scm_func @getKeyState 1 key 0x30 store_to 1@
  54. }
  55. if
  56. 0AA2: 1@ = load_library "user32.dll"
  57. then
  58. if
  59. 0AA4: 2@ = get_proc_address "GetKeyState" library 1@
  60. then
  61. 0AA7: call_function 2@ num_params 1 pop 0 key 0@ state_to 3@
  62. end
  63. 0AA3: free_library 1@
  64. end
  65. 0AB2: ret 1 3@
  66.  
  67. :setKeyState
  68. {
  69. Parameters:
  70. Passed:
  71. 0@ - virtual key
  72. Result:
  73. none
  74.  
  75. Example:
  76. 0AB1: call_scm_func @setKeyState 2 key 0x30 enabled 1
  77. }
  78. if
  79. 0AA2: 2@ = load_library "user32.dll"
  80. then
  81. if
  82. 0AA4: 3@ = get_proc_address "keybd_event" library 2@
  83. then
  84. 4@ = False
  85. 0AB1: call_scm_func @getKeyState 1 key 0@ store_to 5@
  86. if and
  87. 1@ == 1
  88. 5@ == 0
  89. then
  90. 4@ = True
  91. else
  92. if and
  93. 1@ == 0
  94. 5@ == 1
  95. then
  96. 4@ = True
  97. end
  98. end
  99. if
  100. 4@ == True
  101. then
  102. 0AA5: call 3@ num_params 4 pop 0 dwExtraInfo 0 dwFlags 0x0 bScan 0 bVk 0@ // press key
  103. 0AA5: call 3@ num_params 4 pop 0 dwExtraInfo 0 dwFlags 0x2 bScan 0 bVk 0@ // release key
  104. end
  105. end
  106. 0AA3: free_library 2@
  107. end
  108. 0AB2: ret 0
  109.  
  110. :getAsyncKeyState
  111. {
  112. Parameters:
  113. Passed:
  114. 0@ - virtual key
  115. Result:
  116. 3@ - virtual key state
  117.  
  118. Example:
  119. 0AB1: call_scm_func @geAsynctKeyState 1 key 0x30 store_to 1@
  120. }
  121. if
  122. 0AA2: 1@ = load_library "user32.dll"
  123. then
  124. if
  125. 0AA4: 2@ = get_proc_address "GetAsyncKeyState" library 1@
  126. then
  127. 0AA7: call_function 2@ num_params 1 pop 0 key 0@ state_to 3@
  128. end
  129. 0AA3: free_library 1@
  130. end
  131. 0AB2: ret 1 3@
  132.  
  133. :getKeyPressed
  134. {
  135. Parameters:
  136. Passed:
  137. none
  138. Result:
  139. 0@ - pressed key
  140.  
  141. Example:
  142. 0AB1: call_scm_func @getKeyPressed 0 store_to 1@
  143. }
  144. for 0@ = 0x1 to 0xFE
  145. if
  146. 0AB1: call_scm_func @isKeyPressed 1 key 0@
  147. then
  148. 0485: return_true
  149. 0AB2: ret 1 0@
  150. end
  151. end
  152. 059A: return_false
  153. 0AB2: ret 1 0
  154.  
  155. :isKeyPressed
  156. {
  157. Parameters:
  158. Passed:
  159. 0@ - virtual key
  160. Result:
  161. none
  162.  
  163. Example:
  164. 0AB1: call_scm_func @isKeyPressed 1 key 0x30
  165. }
  166. 0AB1: call_scm_func @getKeyState 1 key 0@ store_to 1@
  167. if and
  168. 1@ <> 0
  169. 1@ <> 1
  170. then
  171. 0485: return_true
  172. else
  173. 059A: return_false
  174. end
  175. 0AB2: ret 0
  176.  
  177. :isKeyAlreadyPressed
  178. {
  179. Parameters:
  180. Passed:
  181. 0@ - virtual key
  182. Result:
  183. none
  184.  
  185. Example:
  186. 0AB1: call_scm_func @isKeyAlreadyPressed 1 key 0x30
  187. }
  188. 0AB1: call_scm_func @getKeyState 1 key 0@ store_to 1@
  189. if
  190. 1@ == 1
  191. then
  192. 0485: return_true
  193. else
  194. 059A: return_false
  195. end
  196. 0AB2: ret 0
  197.  
  198. :isKeyUnPressed
  199. {
  200. Parameters:
  201. Passed:
  202. 0@ - virtual key
  203. Result:
  204. none
  205.  
  206. Example:
  207. 0AB1: call_scm_func @isKeyUnPressed 1 key 0x30
  208. }
  209. 0AB1: call_scm_func @getKeyState 1 key 0@ store_to 1@
  210. if
  211. 1@ == 0
  212. then
  213. 0485: return_true
  214. else
  215. 059A: return_false
  216. end
  217. 0AB2: ret 0
  218.  
  219. :isKeyStillPressed
  220. {
  221. Parameters:
  222. Passed:
  223. 0@ - virtual key
  224. Result:
  225. none
  226.  
  227. Example:
  228. 0AB1: call_scm_func @isKeyStillPressed 1 key 0x30
  229. }
  230. if
  231. 0AB1: call_scm_func @isKeyPressed 1 key 0@
  232. then
  233. 0AB1: call_scm_func @getAsyncKeyState 1 key 0@ store_to 1@
  234. if
  235. 32@ > 750
  236. then
  237. if
  238. 1@ == -32767
  239. then
  240. 0485: return_true
  241. else
  242. 059A: return_false
  243. 32@ = 0
  244. end
  245. end
  246. else
  247. 059A: return_false
  248. 32@ = 0
  249. end
  250. 0AB2: ret 0
  251.  
  252. :isAnyKeyPressed
  253. {
  254. Parameters:
  255. Passed:
  256. none
  257. Result:
  258. none
  259.  
  260. Example:
  261. 0AB1: call_scm_func @isAnyKeyPressed 0
  262. }
  263. if
  264. 0AB1: call_scm_func @getKeyPressed 0 store_to 0@
  265. then
  266. 0485: return_true
  267. else
  268. 059A: return_false
  269. end
  270. 0AB2: ret 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement