linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Curses and key-up information
@ 2003-01-06 14:29 Steve Goodwin
  2003-01-06 16:00 ` Glynn Clements
  0 siblings, 1 reply; 6+ messages in thread
From: Steve Goodwin @ 2003-01-06 14:29 UTC (permalink / raw)
  To: linux-c-programming

Hi all,

I'm writing to write a little curses maze game that involves a lot of key
handling, and the most obvious way to handle the control is with a
IsKeyDown(char key) type-function. Alas, curses doesn't appear to have one
and was wondering is anyone else has found a way around this problem (either
within curses, or using ioctl/poll or similar).

I have a (rather poor) solution whereas all keys are read on a zero timeout
and fast repeat, but the situation: 'z' key down, 'k' key down, will not
pick up the 'k' for more than 1 frame which is not enough :(

Steev



The information in this Internet Email is confidential and is intended
solely for the addressee. Access, copying or re-use of information in it by
anyone else is unauthorised. Please immediately notify the sender if you are
not the intended recipient and have received this mail. 
Any views or opinions presented are solely those of the author and do not
necessarily represent those of Bits Corp plc or any of its affiliates. 

Tel. +44 (0)20 8282 7200 
Fax. +44 (0)20 8450 9966

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Curses and key-up information
  2003-01-06 14:29 Curses and key-up information Steve Goodwin
@ 2003-01-06 16:00 ` Glynn Clements
  2003-01-07  7:08   ` Jan-Benedict Glaw
  0 siblings, 1 reply; 6+ messages in thread
From: Glynn Clements @ 2003-01-06 16:00 UTC (permalink / raw)
  To: Steve Goodwin; +Cc: linux-c-programming


Steve Goodwin wrote:

> I'm writing to write a little curses maze game that involves a lot of key
> handling, and the most obvious way to handle the control is with a
> IsKeyDown(char key) type-function. Alas, curses doesn't appear to have one
> and was wondering is anyone else has found a way around this problem (either
> within curses, or using ioctl/poll or similar).

It can't be done. The process only receives notification of key
presses; there is no way to discover when a key is released.

Bear in mind that Unix terminal I/O was designed for terminals (vt100
etc) rather than a keyboard which is attached directly. Terminals
(whether hardware terminals such as the vt100, emulators such as
xterm, the linux console, telnet etc) simply don't send anything when
a key is released, so there's no way to detect it.

-- 
Glynn Clements <glynn.clements@virgin.net>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Curses and key-up information
  2003-01-06 16:00 ` Glynn Clements
@ 2003-01-07  7:08   ` Jan-Benedict Glaw
  0 siblings, 0 replies; 6+ messages in thread
From: Jan-Benedict Glaw @ 2003-01-07  7:08 UTC (permalink / raw)
  To: linux-c-programming

[-- Attachment #1: Type: text/plain, Size: 1876 bytes --]

On Mon, 2003-01-06 16:00:39 +0000, Glynn Clements <glynn.clements@virgin.net>
wrote in message <15897.43047.454804.466506@cerise.nosuchdomain.co.uk>:
> > I'm writing to write a little curses maze game that involves a lot of key
> > handling, and the most obvious way to handle the control is with a
> > IsKeyDown(char key) type-function. Alas, curses doesn't appear to have one
> > and was wondering is anyone else has found a way around this problem (either
> > within curses, or using ioctl/poll or similar).
> 
> It can't be done. The process only receives notification of key
> presses; there is no way to discover when a key is released.

Well, in some special cases, you _can_ get key-up information as well as
key-down notofications. However, this is hackish...

> Bear in mind that Unix terminal I/O was designed for terminals (vt100
> etc) rather than a keyboard which is attached directly. Terminals
> (whether hardware terminals such as the vt100, emulators such as
> xterm, the linux console, telnet etc) simply don't send anything when
> a key is released, so there's no way to detect it.

Some time ago, we had almost the same topic. IIRC I've had posted some
code snipplets at that time.

Basically, as long as you use your console as a real terminal (probably
using some helper library as (n)curses/termcap etc), you don't get
key-{up|down} information, but only "key Y was hit". However, in special
cases (switching console into raw mode), you'll get all information (if
available...), as for example X11 indeed does use any information
available.

MfG, JBG

-- 
   Jan-Benedict Glaw       jbglaw@lug-owl.de    . +49-172-7608481
   "Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur
    fuer einen Freien Staat voll Freier Bürger" | im Internet!
   Shell Script APT-Proxy: http://lug-owl.de/~jbglaw/software/ap2/

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: Curses and key-up information
@ 2003-01-07 11:49 Steve Goodwin
  2003-01-17  0:17 ` +RudyMartin
  0 siblings, 1 reply; 6+ messages in thread
From: Steve Goodwin @ 2003-01-07 11:49 UTC (permalink / raw)
  To: linux-c-programming

Thanks for that. A (deeper) trawl provided a post from 6/8/02 (thread: Re:
question about gcc and keyboard hadling) with some source code - will try it
l8r when I'm at a Linux box.

Steev




The information in this Internet Email is confidential and is intended
solely for the addressee. Access, copying or re-use of information in it by
anyone else is unauthorised. Please immediately notify the sender if you are
not the intended recipient and have received this mail. 
Any views or opinions presented are solely those of the author and do not
necessarily represent those of Bits Corp plc or any of its affiliates. 

Tel. +44 (0)20 8282 7200 
Fax. +44 (0)20 8450 9966

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Curses and key-up information
  2003-01-07 11:49 Steve Goodwin
@ 2003-01-17  0:17 ` +RudyMartin
  2003-01-17 11:21   ` Jan-Benedict Glaw
  0 siblings, 1 reply; 6+ messages in thread
From: +RudyMartin @ 2003-01-17  0:17 UTC (permalink / raw)
  To: linux-c-programming


perhaps its my lack of experience in linux programming but I tried the
referred source code and it didnt worked

also, the ioctrl documentation says the keyboard access is done trhough the
tty driver but i wanted a direct keyboard access, like VMware under X

since im doing a Brief emulation I was forced to remap some default keys. :(
(btw the text editor is currently at 5% of completion but its working pretty
good, if anyone wants a copy of the sources just let me know)

good luck


----- Original Message -----
From: "Steve Goodwin" <SteveG@bitscorp.com>
To: <linux-c-programming@vger.kernel.org>
Sent: Tuesday, January 07, 2003 8:49 AM
Subject: RE: Curses and key-up information


> Thanks for that. A (deeper) trawl provided a post from 6/8/02 (thread: Re:
> question about gcc and keyboard hadling) with some source code - will try
it
> l8r when I'm at a Linux box.
>
> Steev
>
>
>
>
> The information in this Internet Email is confidential and is intended
> solely for the addressee. Access, copying or re-use of information in it
by
> anyone else is unauthorised. Please immediately notify the sender if you
are
> not the intended recipient and have received this mail.
> Any views or opinions presented are solely those of the author and do not
> necessarily represent those of Bits Corp plc or any of its affiliates.
>
> Tel. +44 (0)20 8282 7200
> Fax. +44 (0)20 8450 9966
> -
> To unsubscribe from this list: send the line "unsubscribe
linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.443 / Virus Database: 248 - Release Date: 10/01/03


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Curses and key-up information
  2003-01-17  0:17 ` +RudyMartin
@ 2003-01-17 11:21   ` Jan-Benedict Glaw
  0 siblings, 0 replies; 6+ messages in thread
From: Jan-Benedict Glaw @ 2003-01-17 11:21 UTC (permalink / raw)
  To: linux-c-programming

[-- Attachment #1: Type: text/plain, Size: 1281 bytes --]

On Thu, 2003-01-16 21:17:36 -0300, +RudyMartin <rmb@coopenet.com.ar>
wrote in message <001d01c2bdbd$d746b880$28d831c8@oemcomputer>:
> 
> perhaps its my lack of experience in linux programming but I tried the
> referred source code and it didnt worked

Then you probably did something wrong:-)

> also, the ioctrl documentation says the keyboard access is done trhough the
> tty driver but i wanted a direct keyboard access, like VMware under X

Well, if you do direct I/O the the keyboard controller, you face a
number of problems:

	1. Your code is not portable, in no way. Not even between
	different architectures running Linux
	2. You face races between your code and the in-kernel code which
	will cause spurious errors

> since im doing a Brief emulation I was forced to remap some default keys. :(
> (btw the text editor is currently at 5% of completion but its working pretty
> good, if anyone wants a copy of the sources just let me know)

That's not good at all:-(

MfG, JBG

-- 
   Jan-Benedict Glaw       jbglaw@lug-owl.de    . +49-172-7608481
   "Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur
    fuer einen Freien Staat voll Freier Bürger" | im Internet!
   Shell Script APT-Proxy: http://lug-owl.de/~jbglaw/software/ap2/

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-01-17 11:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-01-06 14:29 Curses and key-up information Steve Goodwin
2003-01-06 16:00 ` Glynn Clements
2003-01-07  7:08   ` Jan-Benedict Glaw
  -- strict thread matches above, loose matches on Subject: below --
2003-01-07 11:49 Steve Goodwin
2003-01-17  0:17 ` +RudyMartin
2003-01-17 11:21   ` Jan-Benedict Glaw

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).