how to take input of arrow keys in c(currently using codeblocks)

HI there

I have been working on developing a puzzle game in c.
In order to do so , ill be needing to take input of arrow keys.
Please suggest a suitable function to input arrow keys.

Ive found one which is given below.

include<dos.h>
sgetkey()
{
union REGS i,o;
while(!kbhit());
i.ah.h=0;
int86(22,&i,&o);
return(o.h.ah);
}
but it keeps on showing

error:storage size of i is unknown.
error:storage size of o is unknown.

I want to make this in codeblocks. So please share a suitable solution.

right, if available, you can just straight up use conio.h, it has kbhit and getch
e.g

#include <conio.h>

const int key_up = 72
const int key_down = 80
const int key_left = 75
const int key_right = 77

int main()
{
	bool loop = true;
	while( loop )
	{
		if ( kbhit() )
		{
			char c = getch();
			switch( c )
			{
			case key_up :
				loop = false;
				break;
			case key_down :
				loop = false;
				break;
			case key_left :
				loop = false;
				break;
			case key_right :
				loop = false;
				break;
			}
		}
	}
}

or if conio.h is not available, you can just use some lbraries out there, SFML works for me as you can just use parts of it.
sfml-dev.org sure, it is C++ library, but there is an official C binding for it

1 Like