Page 1 of 1
getch()
Posted: Thu Mar 06, 2003 11:14 am
by _adeel
hi
i m using this code for my getch function
Code: Select all
unsigned char agetch(){
unsigned int c=0x00;
while(c==0x00){
c=inportb(0x60);
}
return c;
}
but its not working
could some one show me how it can work
thanx for ur help
Re:getch()
Posted: Thu Mar 06, 2003 11:28 am
by richie
Hello!
It's the old problem: inportb(0x60) returns the
scancode and not the ASCII-Value of the pressed key. You have to translate the scancode to the ASCII-Value.
See:
http://www.mega-tokyo.com/forum/index.php?board=1;action=display;threadid=3065
There was already a big discussion about getting input.
Re:getch()
Posted: Fri Mar 07, 2003 9:04 am
by Krisu
There is keyboard scancodes for finnish keyboard:
http://koti.mbnet.fi/kotiweb/Keyboard.txt
Re:getch()
Posted: Fri Mar 07, 2003 12:30 pm
by Slasher
Is this really a good getch() function? the reason i ask is because this bypasses the keyboard driver!
And you will not be able to implement ungetch()!!?
so what of
unsigned char getch()
{
if(keypressed==TRUE) /* set in keyboard driver when a key is presses and read*/
send message(keyboard driver, get key);
return get key;
}
Re:getch()
Posted: Fri Mar 07, 2003 2:01 pm
by Whatever5k
Yep, the getch() function provided by _adeel isn't a good and common one as it uses polling.
I'd just do:
Code: Select all
extern kbd_queue *key_buffer;
int getch(void)
{
return (get_next_key_from_buffer(key_buffer));
}
On every key interrupt, the ASCII key is stored in key_buffer, a getch() will just return the first character.