Re: SWI-Prolog get_single_char
- From: Jan Wielemaker <jan@xxxxxxxxxxxxxxxxxxx>
- Date: 04 Jul 2006 11:48:48 GMT
On 2006-07-04, Andreas Kochenburger <akk@xxxxxxxxxx> wrote:
On 30 Jun 2006 07:39:46 GMT, Jan Wielemaker <jan@xxxxxxxxxxxxxxxxxxx>
wrote:
I am using V. 5.6.12 on Windows and want to catch user keyboard events.
However get_single_char does not what it should do: a) it is echoed to the
terminal and b) it waits for the <return> key.
It only works fine in plwin.exe. If you know how to get it working in
plcon.exe, tell me. Otherwise use plwin.exe or install Linux :-)
Nice ;-)
Out of curiosity I had a look at the source file console.c and my
guess is that the little buggy is in the queue management, but
console.c is way too long for me to tamper around with.
Thats a bit vague to go searching :-)
I once developed a small Forth system that runs fine in Linux and in
Windows consoles. The common keyboard interface is as simple as:
Thanks. This is only one of the issues though. The other is to
get the message loop going for the graphics to work while we wait
for keyboard input, get Unicode I/O to work and get completion and
line-editing to work. If someone has code to do all that, please
drop me a line.
Cheers --- Jan
/* -------------------------------------------------------------------.
Terminal raw mode setup
*/
#if _OSTYPE >= 3
struct termios newtset, oldtset; /* terminal settings */
static int pending = -1; /* holds character */
#endif
void SaveTerminal()
{
#if _OSTYPE >= 3
tcgetattr(STDIN_FILENO, &oldtset);
#endif
}
void SetTerminal()
{
#if _OSTYPE >= 3
newtset = oldtset;
newtset.c_lflag &= ~(ECHO | ICANON);
newtset.c_iflag &= ~ICRNL;
newtset.c_cc[VTIME] = 0;
newtset.c_cc[VMIN] = 0;
tcsetattr(STDIN_FILENO, TCSANOW, &newtset);
#else
setmode(STDIN_FILENO, O_BINARY);
#endif
}
void RestoreTerminal()
{
#if _OSTYPE >= 3
tcsetattr(STDIN_FILENO, TCSANOW, &oldtset);
#else
setmode(STDIN_FILENO, O_TEXT);
#endif
}
int WaitKey(void) /* return true when keyboard event is in queue */
{
#if _OSTYPE >= 3
char key;
if (pending == -1)
{ if (0 == read(STDIN_FILENO, &key, 1)) return(0);
if (key == 127) key = '\b';
pending = key; }
return(-1);
#else
return(kbhit());
#endif
}
char GetKey(void) /* get or wait for next keyboard event */
{
#if _OSTYPE >= 3
char key;
if (pending == -1)
do
usleep(50000); /* for Linux ok, but for Minix? */
while (WaitKey() == 0);
key = pending, pending = -1;
return(key);
#else
return((char)getch());
#endif
}
Andreas
-------
Et ceterum censeo, TV esse delendam.
- References:
- Re: SWI-Prolog get_single_char
- From: Andreas Kochenburger
- Re: SWI-Prolog get_single_char
- Prev by Date: Re: SWI-Prolog get_single_char
- Next by Date: How can I assert information acquired via Natural Language input from user?
- Previous by thread: Re: SWI-Prolog get_single_char
- Next by thread: How can I assert information acquired via Natural Language input from user?
- Index(es):
Relevant Pages
|
|