Sign in to follow this  
Googler

GetAsyncKeyState equivalent in 80x86 Assembly

Recommended Posts

_the_phantom_    11250
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 this post


Link to post
Share on other sites
kordova    140
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this