getch()

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
_adeel

getch()

Post 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
richie

Re:getch()

Post 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.
Krisu

Re:getch()

Post by Krisu »

There is keyboard scancodes for finnish keyboard:
http://koti.mbnet.fi/kotiweb/Keyboard.txt
Slasher

Re:getch()

Post 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;
}
Whatever5k

Re:getch()

Post 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.
Post Reply