Microsoft Code for Keyboard Input interpretation

Hello, at the moment my program is extracting keyboard data through accessing the virtual key states. However, it is not performing as I intended because the data I receive from the console does not concur with the actions the user performed.

E.G. When I type, it comes out like this.
what I get with my program: WWhhhheeen III typeeee, iiit ccoommes oout lllikkke thhhhiiis

I would like to see a sample source code of how other programs deal with this type of problem. please and thank you.


TLDR: so basically Id like to know how other programs know how to interpret keyboard input, so that when I type I dont get multiple inputs of the same key press
Last edited on
edit: how do I make my program perform a function only when keystate changes, from 0-1, or vise versa, and not just solely when its of one or the other value
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#include <windows.h>

int main ( void )
{
short esc = 0;

while ( !esc ) {
esc = GetAsyncKeyState ( VK_ESCAPE );

if ( GetAsyncKeyState ( VK_UP ) & SHRT_MAX )
puts ( "Up arrow is pressed" );
else if ( GetAsyncKeyState ( VK_DOWN ) & SHRT_MAX )
puts ( "Down arrow is pressed" );
else if ( GetAsyncKeyState ( VK_LEFT ) & SHRT_MAX )
puts ( "Left arrow is pressed" );
else if ( GetAsyncKeyState ( VK_RIGHT ) & SHRT_MAX )
puts ( "Right arrow is pressed" );
}

return EXIT_SUCCESS;
}




This code solved the problem for me, for anyone having same problem as me
Topic archived. No new replies allowed.