Message from discussion
Get Key Function?
Path: g2news2.google.com!news4.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: Clive Page <use...@page2.eu>
Newsgroups: comp.lang.fortran
Subject: Re: Get Key Function?
Date: Sun, 3 May 2009 10:52:20 +0100
Organization: home
Lines: 45
Message-ID: <kYFQftBUlW$JJw7q@page.demon.co.uk>
References: <edf0a73b-ff05-4849-90f6-2aa93445d388@v35g2000pro.googlegroups.com>
<87zldw6ajc.fsf@roark.xbeta.org>
Reply-To: use...@page2.eu
Mime-Version: 1.0
Content-Type: text/plain;charset=us-ascii;format=flowed
X-Trace: individual.net x6Vpr8FIb5ccch1hD/AZggC6mjOyyZDW+kHYKRQ0uT8KhCz/8r
X-Orig-Path: page2.eu!usenet
Cancel-Lock: sha1:+EmMga+FS4sZSxa3hTy43TbUCbU=
User-Agent: Turnpike/6.07-M (<JPumxV1hGhefXN7tiXnze3N1tV>)
In message <87zldw6ajc....@roark.xbeta.org>, Jason Blevins
<jrble...@sdf.lonestar.org> writes
>it mentions reading single keystrokes. Unfortunately, it says there
>isn't a portable way to do this in Fortran, but he offers a C function
>with some instructions on how to call it from Fortran:
>http://www.star.le.ac.uk/~cgp/sys_keyin.c
As noted earlier, this works on some Unix-like systems including Linux,
but not on Windows.
>I would imagine there is a way to do this in Fortran 2003 using
>stream input from stdin, but I couldn't get anything working.
>Maybe someone else knows...
>
>If you don't mind using something non-standard, I know that
>GFortran has an FGET extension for this. It's likely that
>G95 has a similar extension.
>
>http://gcc.gnu.org/onlinedocs/gcc-4.4.0/gfortran/FGET.html
I've tried this too, but can't get it to read single keystrokes - the
keystroke read still needs a RETURN at the end.
On Windows the nearest I've been able to find uses a function in the
GrWin library, which can be downloaded from:
http://spdg1.sci.shizuoka.ac.jp/grwinlib/english/
This contains a function kbgetch(n) which returns the integer code of
the next single keystroke. Normally n=0 but if n=1 then the character
is echoed to stdout.
This can be linked using g95 or gfortran on Windows-XP using a command
like this:
>g95 testkbd.f90 -Wl,--subsystem,console -lGrWin -mwindows -lg2c
I have no idea what the switch "-Wl,--subsystem,console" is doing, it is
just a bit of magic I found in the GrWin files. If anyone understands
it, please post.
It is, as you say, a pity that this cannot be done in a way that is
portable across operating systems.
--
Clive Page