Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // File Name: vk_keys.inc
- {
- FUNCTIONS INCLUDED:
- - getKeyState
- Type: GET
- Description: Get a virtual key state.
- - setKeyState
- Type: SET
- Description: Set a virtual key state.
- - getAsyncKeyState
- Type: GET
- Description: Get a virtual key state after a previous call to the function.
- - getKeyPressed
- Type: GET
- Description: Get the current virtual key pressed.
- - isKeyPressed
- Type: GET
- Description: Check for virtual key pressed.
- - isKeyAlreadyPressed
- Type: GET
- Description: Check if a virtual key has been already pressed.
- - isKeyUnPressed
- Type: GET
- Description: Check if a virtual key has been already pressed.
- - isKeyStillPressed
- Type: GET
- Description: Check if a virtual key is still pressed after some seconds.
- - isAnyKeyPressed
- Type: GET
- Description: Check for any virtual key pressed.
- }
- :getKeyState
- {
- Parameters:
- Passed:
- 0@ - virtual key
- Result:
- 3@ - virtual key state
- Example:
- 0AB1: call_scm_func @getKeyState 1 key 0x30 store_to 1@
- }
- if
- 0AA2: 1@ = load_library "user32.dll"
- then
- if
- 0AA4: 2@ = get_proc_address "GetKeyState" library 1@
- then
- 0AA7: call_function 2@ num_params 1 pop 0 key 0@ state_to 3@
- end
- 0AA3: free_library 1@
- end
- 0AB2: ret 1 3@
- :setKeyState
- {
- Parameters:
- Passed:
- 0@ - virtual key
- Result:
- none
- Example:
- 0AB1: call_scm_func @setKeyState 2 key 0x30 enabled 1
- }
- if
- 0AA2: 2@ = load_library "user32.dll"
- then
- if
- 0AA4: 3@ = get_proc_address "keybd_event" library 2@
- then
- 4@ = False
- 0AB1: call_scm_func @getKeyState 1 key 0@ store_to 5@
- if and
- 1@ == 1
- 5@ == 0
- then
- 4@ = True
- else
- if and
- 1@ == 0
- 5@ == 1
- then
- 4@ = True
- end
- end
- if
- 4@ == True
- then
- 0AA5: call 3@ num_params 4 pop 0 dwExtraInfo 0 dwFlags 0x0 bScan 0 bVk 0@ // press key
- 0AA5: call 3@ num_params 4 pop 0 dwExtraInfo 0 dwFlags 0x2 bScan 0 bVk 0@ // release key
- end
- end
- 0AA3: free_library 2@
- end
- 0AB2: ret 0
- :getAsyncKeyState
- {
- Parameters:
- Passed:
- 0@ - virtual key
- Result:
- 3@ - virtual key state
- Example:
- 0AB1: call_scm_func @geAsynctKeyState 1 key 0x30 store_to 1@
- }
- if
- 0AA2: 1@ = load_library "user32.dll"
- then
- if
- 0AA4: 2@ = get_proc_address "GetAsyncKeyState" library 1@
- then
- 0AA7: call_function 2@ num_params 1 pop 0 key 0@ state_to 3@
- end
- 0AA3: free_library 1@
- end
- 0AB2: ret 1 3@
- :getKeyPressed
- {
- Parameters:
- Passed:
- none
- Result:
- 0@ - pressed key
- Example:
- 0AB1: call_scm_func @getKeyPressed 0 store_to 1@
- }
- for 0@ = 0x1 to 0xFE
- if
- 0AB1: call_scm_func @isKeyPressed 1 key 0@
- then
- 0485: return_true
- 0AB2: ret 1 0@
- end
- end
- 059A: return_false
- 0AB2: ret 1 0
- :isKeyPressed
- {
- Parameters:
- Passed:
- 0@ - virtual key
- Result:
- none
- Example:
- 0AB1: call_scm_func @isKeyPressed 1 key 0x30
- }
- 0AB1: call_scm_func @getKeyState 1 key 0@ store_to 1@
- if and
- 1@ <> 0
- 1@ <> 1
- then
- 0485: return_true
- else
- 059A: return_false
- end
- 0AB2: ret 0
- :isKeyAlreadyPressed
- {
- Parameters:
- Passed:
- 0@ - virtual key
- Result:
- none
- Example:
- 0AB1: call_scm_func @isKeyAlreadyPressed 1 key 0x30
- }
- 0AB1: call_scm_func @getKeyState 1 key 0@ store_to 1@
- if
- 1@ == 1
- then
- 0485: return_true
- else
- 059A: return_false
- end
- 0AB2: ret 0
- :isKeyUnPressed
- {
- Parameters:
- Passed:
- 0@ - virtual key
- Result:
- none
- Example:
- 0AB1: call_scm_func @isKeyUnPressed 1 key 0x30
- }
- 0AB1: call_scm_func @getKeyState 1 key 0@ store_to 1@
- if
- 1@ == 0
- then
- 0485: return_true
- else
- 059A: return_false
- end
- 0AB2: ret 0
- :isKeyStillPressed
- {
- Parameters:
- Passed:
- 0@ - virtual key
- Result:
- none
- Example:
- 0AB1: call_scm_func @isKeyStillPressed 1 key 0x30
- }
- if
- 0AB1: call_scm_func @isKeyPressed 1 key 0@
- then
- 0AB1: call_scm_func @getAsyncKeyState 1 key 0@ store_to 1@
- if
- 32@ > 750
- then
- if
- 1@ == -32767
- then
- 0485: return_true
- else
- 059A: return_false
- 32@ = 0
- end
- end
- else
- 059A: return_false
- 32@ = 0
- end
- 0AB2: ret 0
- :isAnyKeyPressed
- {
- Parameters:
- Passed:
- none
- Result:
- none
- Example:
- 0AB1: call_scm_func @isAnyKeyPressed 0
- }
- if
- 0AB1: call_scm_func @getKeyPressed 0 store_to 0@
- then
- 0485: return_true
- else
- 059A: return_false
- end
- 0AB2: ret 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement