Jump to content
  • Advertisement
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
jmp .exit_kchk
mov ax,0;
pop bp
_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 this post

Link to post
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 this post

Link to post
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.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!