GetAsyncKeyState equivalent in 80x86 Assembly

This topic is 4957 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Can someone post code on an Assembly equivalent of GetAsyncKeyState ? Thanks.

Share on other sites
this does something like that;

;******************************************************************************;* int get_key()                                                             *;*                                                                            *;* Reads the last key pressed from the keyboard and returns the ASCII code    *;******************************************************************************Public _get_key_get_key PROC Near	push	bp	MOV   AH, 01H                       ; Check for keypress	INT   16H                           ; Is a key waiting in the buffer?	JZ    .nodata                       ; No, then signal	MOV   AH, 00H                       ; Yes, so get the key	INT   16H	jmp	.exit_kchk.nodata:	mov	ax,0;.exit_kchk:	pop	bp	ret_get_key ENDP

2 notes:
1 - it was written by me at 3am back on 13th Dec99, it works but dont expect me to explain it [grin]
2 - the calling convention used is the C calling convection, so it shouldnt be a huge problem to link to it if needed
Code was designed to interface with an old borland C++ compiler (3.1 I think... maybe older, certainly dos based)

Share on other sites
Thanks a ton man. I'll let ya know if its working for me.

Share on other sites
Sweet, I just did a quick loop test to output the last key pressed and it looks like it does the trick. Thanks again.

Share on other sites
np, happy to help [smile]

Share on other sites
It may be worth noting that that may have the effect of pausing after the initial press of a key (at least that happened to me). Or, to elaborate, that if you should press and hold 'a', it will be pressed, it will "not" be pressed (it wont register as pressed - not in keyboard buffer for a few moments), then it will fire repeatedly with no issue. That's what happened to me so I had to change my approach for a realtime game.

• 11
• 20
• 12
• 10
• 38
• Forum Statistics

• Total Topics
631400
• Total Posts
2999862
×