#Amiga kbhit() & getch()
5 messages in this thread
getch()
I am trying to port one of my C++ programs to Amiga GNU C++ 2.5.8.
The problem is the program was originally developed under MSDos and makes use
of calls to 'kbhit()' and 'getch()'. These functions apparently do not exist
in the Unix world, but must surely exist as ROM or System Kernal calls. (I
hope…). As a C++ programmer who daily works with embedded systems, I'm not
afraid to work down at the 'nuts and bolts' level of a system, so long as I
have some idea what I'm doing there.
The functions:
kbhit() – return non-zero if a character has been pressed by
the user. Operates in NON-BUFFERED mode, which means I
dont want to wait for a carriage-return.
getch() – return the char value from the keyboard fifo without
console/crt echo. Operates in NON-BUFFERED mode, which
means I dont want to wait for a carriage-return.
If anyone knows how to access equivelent information from the Amiga system,
please enlighten me.
Thanks,
Ron Flory,
Kechi Kansas
If you are willing to work with a window and IDCMP you can request
keyboard events to be sent to your window. Do you have the Amiga ROM
Kernal Manuals? They explain this sort of thing very well. There is no
direct equivalent to kbhit, but if you try and read a message from your
IDCMP port and there isn't one there, there aren't any outstanding
keyboard events for your window.
In the Unix world if you want to do this sort of thing you have to change
the setup of the port and the file. You do this using two function calls,
ioctl and fcntl (I think you also have to use read instead of getch).
ioctl can switch off buffering and local echo, and fcntl can put a file
into "non-waiting" mode. If GNU has Unix compatible versions of these
functions you may be able to use them. If you want any more information on
these I can look them up at work.
Peter Wade
Autopiloting from London, England
Hi Ron –
SAS/C provides a getch() function, but not a kbhit() function. Since the
Amiga input.device handles all input, there is no way to really tell if/when
the user actually hit a key, but really you shouldn't need to know that; all
you really want to know is whether or not input is available for you to read
on stdin (I assume). The console.device has the ability to do all of this.
It will be documented in either the Rom Kernel Manual or in the Bantam
AmigaDOS book, or possibly in both. Ralph Babel's book "The Amiga Guru Book"
is also an excellent reference – I'd get it in place of the Bantam book.
–Doug
thanx, I'vr never heard of the 'guru' book, but I guess I ought to go ahead and
get those Kernal Manuals after all.
I just need to know if ANY keyboard input is pending. Is SAS C worth the
money; I'm a C++ person, and they really charge a premium for the C++ package.
I've heard a lot of folks say they love the compiler, but are they talkin'
about the C++ version ??
thanks for the feedback; please reply if anything else comes to mind…
ron.