howto recognize the Shift and Alt keys when /pressed\

Gary Kline kline at
Tue Oct 22 19:18:19 UTC 2013

Organization: Thought Unlimited.  Public service Unix since 1986.
Of_Interest: With 27 years  of service  to the  Unix  community.

On Tue, Oct 22, 2013 at 12:59:01PM +0200, Polytropon wrote:
> 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).

	getting dow to the keyboard driver level is what I was going to
	do--actually, what I did do way, way back.  there was a crash that
	cost me a month+  worth of work and I bought a "clicky" keyboard
	for $80.  I would up buying two of them and both got  ruined!

	you are right on the money that I can do nothing directly with 
	the shift, the caps-lock, [[nd alt, and other of the "modifier" 
	keys ]].  

	I just *barely* understand this python code that the guy has in
	"", but I see what he's done (I think) to grab onto the 
	modifyer keys::

  def _setup_lookup(self):
    """Setup the key lookups."""
    for name in dir(XK):
      if name[:3] == "XK_":
        code = getattr(XK, name)
        self.keycode_to_symbol[code] = 'KEY_' + name[3:].upper()
    self.keycode_to_symbol[65027] = 'KEY_ISO_LEVEL3_SHIFT'
    self.keycode_to_symbol[269025062] = 'KEY_BACK'
    self.keycode_to_symbol[269025063] = 'KEY_FORWARD'
    self.keycode_to_symbol[16777215] = 'KEY_CAPS_LOCK'
    self.keycode_to_symbol[269025067] = 'KEY_WAKEUP'

	I'll have to look into his code further to see where he's got
	the ints from. "65027", "29...62", etc.  I'm not going to ask him 
	because he was a bit steamed about my asking him for the key-click
	code.  ---long story-short, this is how I'm going to have to do it
	to grab the modifiers... .  

	{more backstory, a bit OT: in school, I hated curses.  ken arnold
	invented the stuff in 1978 or 1979; ken was lightyears ahead of me
	since he was messing with computers as a teenager.  }

> 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. :-)

	Hmmm!  interesting.  do you see any way that I could set up an 
	xmod when the computer first boots and the assign the modifiers
	to some never-used keys, then make those keys click, or am I
	off in the weeds??


> -- 
> Polytropon
> Magdeburg, Germany
> Happy FreeBSD user since 4.0
> Andra moi ennepe, Mousa, ...
> _______________________________________________
> freebsd-questions at mailing list
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe at"

 Gary Kline  kline at  Public Service Unix
             Twenty-seven years of service to the Unix community.

More information about the freebsd-questions mailing list