nanogui: Thread: Really raw keyboard?


[<<] [<] Page 1 of 1 [>] [>>]
Subject: Really raw keyboard?
From: Tomasz Motylewski ####@####.####
Date: 20 Feb 2001 14:10:21 -0000
Message-Id: <Pine.LNX.3.96.1010220135218.6906B-100000@linserv.intern.bfad.de>

Hello,

Is there any possibility to switch OFF the autorepetition mode in the
keyboard driver in nano-X (Linux)?

In our application we need to detect whether more than one keys are
pressed at once.

Best regards,
--
Tomasz Motylewski

Subject: Re: Really raw keyboard?
From: Jordan Crouse ####@####.####
Date: 20 Feb 2001 15:11:19 -0000
Message-Id: <3A928A2A.7B3EDF37@censoft.com>

So generally, what you are saying is that you want to detect when
certain buttons are pressed and released, correct?  If you examine it
closely, thats exactly how Microwindows works.  The server can handle
key down and key up events (repetition is handled by multiple events as
read from the keyboard driver).  

So your nano-X application simply needs to look for the
GR_EVENT_TYPE_KEY_DOWN and GR_EVENT_TYPE_KEY_UP events and adjust a
bitmask accordingly.  Here is what I would do:

#define KEY_A  0x01
#define KEY_B  0x02
#define KEY_C  0x04

unsigned char bitmask = 0;

/* SET UP YOUR WINDOW UP HERE */

while(1)
{
	GR_EVENT event;
	GrGetNextEvent(&event);

	switch(event.type)
	{
	 	case GR_EVENT_TYPE_KEY_DOWN:
			if (event.keystroke.ch == 'A') bitmask |= KEY_A;
			/* Other keys handled in the same way */
		break;
	
		case GR_EVENT_TYPE_KEY_UP:
			if (event.keystroke.ch == 'A') bitmask &= ~KEY_A;
			/* Other keys handled in the same way */
		break;
	}	
}	

Then, you would simply need to examine the value of the bitmask to find
out which keys are down. 

Happy hacking! 

Tomasz Motylewski wrote:
> 
> Hello,
> 
> Is there any possibility to switch OFF the autorepetition mode in the
> keyboard driver in nano-X (Linux)?
> 
> In our application we need to detect whether more than one keys are
> pressed at once.
> 
> Best regards,
> --
> Tomasz Motylewski
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ####@####.####
> For additional commands, e-mail: ####@####.####
Subject: Re: Really raw keyboard?
From: Tomasz Motylewski ####@####.####
Date: 20 Feb 2001 15:31:17 -0000
Message-Id: <Pine.LNX.3.96.1010220162138.6906D-100000@linserv.intern.bfad.de>

On Tue, 20 Feb 2001, Jordan Crouse wrote:

> So generally, what you are saying is that you want to detect when
> certain buttons are pressed and released, correct?  If you examine it
> closely, thats exactly how Microwindows works.  The server can handle
> key down and key up events (repetition is handled by multiple events as
> read from the keyboard driver).  

OK, I know. But the problem is that I do not want this repetition! At the
moment I am handling it in the following way: if KEY_UP is immediately
followed by KEY_DOWN then I ignore it. It requires using
GrGetNextEventTimout and resetting the status of all keys if timeout is
received. I was just wondering it there is a cleaner solutiuon (X11 and
Linux console).

Thank you for so immediate answer :-)

--
Tomek

Subject: Re: Really raw keyboard?
From: Jordan Crouse ####@####.####
Date: 20 Feb 2001 16:01:09 -0000
Message-Id: <3A9295D8.89AE5356@censoft.com>

So you are saying that repetition is reported by the microwindows driver
as a number of KEY_UPs followed by an immediate KEY_DOWN?  Further
examination of the Microwindows driver shows that it simply passes what
the kernel driver reports.  Thus I would have to assume that this
functionality lies with the kernel.  I don't know if the user can
control the repetiton through the TTY  ioctl, but somehwere I thought
that I heard that was possible.  Anyone out there with more TTY
experience care to comment?

omasz Motylewski wrote:
> 
> On Tue, 20 Feb 2001, Jordan Crouse wrote:
> 
> > So generally, what you are saying is that you want to detect when
> > certain buttons are pressed and released, correct?  If you examine it
> > closely, thats exactly how Microwindows works.  The server can handle
> > key down and key up events (repetition is handled by multiple events as
> > read from the keyboard driver).
> 
> OK, I know. But the problem is that I do not want this repetition! At the
> moment I am handling it in the following way: if KEY_UP is immediately
> followed by KEY_DOWN then I ignore it. It requires using
> GrGetNextEventTimout and resetting the status of all keys if timeout is
> received. I was just wondering it there is a cleaner solutiuon (X11 and
> Linux console).
> 
> Thank you for so immediate answer :-)
> 
> --
> Tomek
Subject: Re: Really raw keyboard?
From: "Greg Haerr" ####@####.####
Date: 20 Feb 2001 16:07:17 -0000
Message-Id: <007a01c09b57$9b9ea7a0$15320cd0@gregh>

: Is there any possibility to switch OFF the autorepetition mode in the
: keyboard driver in nano-X (Linux)?
: 
: In our application we need to detect whether more than one keys are
: pressed at once.

A far easier mechanism than what Jordan described will work:
Just change the drivers/kbd_ttyscan.c driver to ignore repeat
keypresses that don't change the keyboard state.  If you look
at kbd_ttyscan.c, line 347, you will find an #if 0.  Change it to
#if 1 and you're in business.

    if (key_state[mwkey] == pressed)
        return;

This code will toss all repeat keystrokes for the same
key.

A quick way of reading the keystate completely will be to
pass the key_state array back to the application.  You'll have
to add another API for this, but that will remove having to have
your application process all this stuff all over again.


Regards,

Greg

Subject: Re: Really raw keyboard?
From: "Greg Haerr" ####@####.####
Date: 20 Feb 2001 16:38:58 -0000
Message-Id: <010401c09b5c$09252660$15320cd0@gregh>

 : I don't know if the user can
: control the repetiton through the TTY  ioctl, but somehwere I thought
: that I heard that was possible.  Anyone out there with more TTY
: experience care to comment?

The 8048 chip in the keyboard controls the keyboard 
repeat.  It can be programmed to not repeat, I don't know whether
this is supported in a kernel ioctl.

Microwindows w/the new scancode driver listens to all scancodes
recieved, and then builds it's own state table, based on the scancode
or unicode value received.  Repeat keys just happen to be keydowns
that occur without intervening keyups.  I decided, for the first cut,
to pass all keystrokes up, but left in the #if 0 for people who
don't want repeat.  (I wanted repeat, however, so that I could play
Doom! that I ported to Microwindows... After all, the reason I 
wrote the scancode driver was to play Doom, now that I think
about it ;-/

Regards,

Greg


[<<] [<] Page 1 of 1 [>] [>>]


Powered by ezmlm-browse 0.20.