howto recognize the Shift and Alt keys when /pressed\

Polytropon freebsd at edvax.de
Tue Oct 22 10:59:11 UTC 2013


On Mon, 21 Oct 2013 16:49:26 +0000, Gary Kline wrote:
> 	since im using curses/ncurses, I just use getch(0.  I.e., 
> 
> 		c = getch(); 
> 
> 	which works fine for everything except the modifier keys like ahift
> 	and alt and ctl.  if there is another way within X11, let's hear
> 	it!

In this case I have to remain silent. As far as I know,
there is no way to capture modifier keys with this means
as _individual_ key presses.

In case you really want to implement that functionality,
you'll have to "go down a few levels" and hook directly
into the keyboard driver which, unlike the ncurses library
that is tied to the console driver, is able to recognize
modifier keys as individual keys. In "upper levels", this
information is fully lost (press and release Shift key) or
combined with other information (press Shift key, press
letter 'k', release both, a capital 'K' will be written
to the keyboard buffer that terminal-based applications
can then read).

The only way I'd see would be to assign a totally different
keysym to the modifier keys, but that again would prevent
them from working as they are intended.

Here's an example for a ~/.modmaprc that would map the
modifier keys to additional PF keys (PF25 to PF33).

	! left control
	keycode 37 = F25
	! left meta
	keycode 115 = F26
	! left alt
	keycode 67 = F27
	! left shift
	keycode 50 = F28
	! caps lock
	keycode 66 = F29
	! right shift
	keycode 64 = F30
	! right alt, alt gr
	keycode 113 = F31
	! right meta
	keycode 116 = F32
	! compose
	keycode 117 = F33

Note that I've generated this example from a Sun USB Type 7
keyboard with has Meta keys, a Compose key, but no right
Control key, so I can't check that. The keycodes can be
easily obtained with "xev".

Also consider Num Lock: It's not a modifier key, but does
not emit anything into the keyboard buffer. It's key code
in X is 77. :-)




-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...


More information about the freebsd-questions mailing list