From owner-freebsd-questions Tue Oct 31 14:56:11 2000 Delivered-To: freebsd-questions@freebsd.org Received: from guru.mired.org (okc-27-149-77.mmcable.com [24.27.149.77]) by hub.freebsd.org (Postfix) with SMTP id 4520D37B4C5 for ; Tue, 31 Oct 2000 14:56:08 -0800 (PST) Received: (qmail 5488 invoked by uid 100); 31 Oct 2000 22:56:07 -0000 From: Mike Meyer MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <14847.19975.697534.830730@guru.mired.org> Date: Tue, 31 Oct 2000 16:56:07 -0600 (CST) To: "frank xu" Cc: questions@freebsd.org Subject: Re: obtain keyboard stat In-Reply-To: <257105@toto.iv> X-Mailer: VM 6.75 under 21.1 (patch 10) "Capitol Reef" XEmacs Lucid X-face: "5Mnwy%?j>IIV\)A=):rjWL~NB2aH[}Yq8Z=u~vJ`"(,&SiLvbbz2W`;h9L,Yg`+vb1>RG% *h+%X^n0EZd>TM8_IB;a8F?(Fb"lw'IgCoyM.[Lg#r\ Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG frank xu types: > Hi, > How can I obtain shift,alt and ctrl key state using curses library under > FreeBSD? Enable mouse events, and ask the user to click a mouse button and read them from the mouse event (see the curs_mouse man page). Of course, that doesn't work if the user doesn't have a mouse. Which is pretty much true for any solution. Curses talks to *terminals*, which send (and receive) characters. Those keys are used by some terminals to help construct the characters you read with wgetch. The terminal your user is on may not have some (or any) of those keys. For instance, using SSH on a Palm pilot I have no keys; I send a Control-C by stroking ^ C and hitting the "send" button. So what you have to do is use wgetch to read the character, then examine the character to see what is and isn't on. The ctype man page lists functions you can use to do that (assuming you're writing in C). The curs_getch man page is also of interest, as it lists things that getch can return that represent various non-ascii keys on the keyboard. Finally, alt is usually the high bit (0x80), but not always. If on, you may need to mask it off and the try the ctype tests for the others.