I’m attempting to utilize the GetAsyncKeyState function in Assembly language to detect the state of a keyboard key. Specifically, I want to print a message when the user presses the “W” key. However, I encountered an “undefined symbol” error when attempting to use the GetAsyncKeyState function.
I’ve ensured that I’ve correctly included the user32.lib library file, and I’m using the correct function name in my code. I even tried manually adding extern GetAsyncKeyState: PROC to declare the GetAsyncKeyState function, but the issue persists.
INCLUDE Irvine32.inc
INCLUDELIB user32.lib
.data
message db "user32.lib is working!", 0
msg db "You pressed 'W'", 0
.code
main proc
invoke MessageBoxA, 0, ADDR message, ADDR caption, MB_OK
call CheckForKey
main endp
CheckForKey PROC
mov eax, 'W'
call GetAsyncKeyState
test eax, eax
jz notPressed
mov edx, OFFSET msg
call WriteString
jmp endCheck
notPressed:
jmp endCheck
endCheck:
ret
CheckForKey ENDP
end main
I want to test if I can print a string when I press ‘W’ using GetAsyncKeyState, but I encountered this error when using GetAsyncKeyState.I’m wondering what might be causing this error and how to resolve it. Any assistance would be greatly appreciated!
陳冠霖 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.