howto recognize the Shift and Alt keys when /pressed\

Gary Kline kline at thought.org
Wed Oct 23 23:40:23 UTC 2013


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

> An _excellent_ keyboard which shouldn't be that expensive
> is the IBM "Model M" (and similarly constructed ones, e. g.
> by BOSCOM). They have a "mechanical click" due to the spring
> mechanism in each key.


	OT, but both times my daughter spilled the water she was drinking
	into the model-m.   < shrug >

> I remember that some terminals had a built-in "beep" (more
> like a click sound) that could be activated for key presses;
> I think the DEC vt100 had that feature. A possible idea would
> be to add the clicking routine (either directed at the PC
> speaker attached to the mainboard, or if needed, aimed at
> the sound card / DSP module) as a part of the terminal emu-
> lator itself: When it receives a keypress, emit the sound.
> Sadly I'm not familiar enough on how this works on FreeBSD,
> if the "level is low enough" to find that functionality in
> the terminal emulator, or if it would really be easier to
> search for that functionality in the keyboard driver because
> the terminal emulator already contains "too much abstraction".
> 
	I bot my 3rd [or 4th] small/compact kybd about two months ago.
	I still have  to press some keys withh my nose, but not that
	often.  the docs say that F3 decreases the sound, F4 increases.  
	F2 reads "Silence!" beneath in blue. the vendor never replied 
	to my email; besides, I want my klik prog to work foe every 
	version of *nix.

> 
> > 	I just *barely* understand this python code that the guy has in
> > 	"xlib.py", 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'
> 
> Hmmm... I did hope that getattr() would be something present
> on the system (a C library function or part of ncurses), but
> it's a Python function. :-(


	yeah, and besides, I want this to work for every computer
	that uses the intel architecture.  SO, can any assembler
	language hacker tell me how to write the code when I press
	Alt, Ctrl, Shift [Left and Right], and "Caps Lock" keys??

	my c = getch() isnt doing anything with the modifier keys.
	*this* may be why xset fails.  there may have been no generic
	way of getting xset working as broadly as it had to, ?, so
	the keyclick stuff wasnt touched.
	
> 
> Still: Those KEY_ variables are definitions from ncurses found
> in /usr/include/curses.h and they partially rely on terminfo
> (again, "higher level" terminal emulation stuff). There are
> many interesting entries, but Shift as a single key does not
> seem to be present (because, as I already mentioned, it is a
> modifier key that adds nothing to the input buffer).
> 
> Compare:
> 
> #define KEY_LEFT        0404            /* left-arrow key */
> 
> And:
> 
> #define KEY_SLEFT       0611            /* shifted left-arrow key */
> 
> I would assume that the above Python code has something to
> do with those naming conventions in ncurses... still I don't
> understand how Caps Lock would be captured that way... The
> XK_ prefix seems to suggest that those are X defintions for
> keys...
> 
> The KEY_ISO_LEVEL3_SHIFT sounds familiar, it's what many
> non-US countries call "Alt Gr" (or "Alt Graph") to add an
> extra level of key symbols for national characters or
> the "differently placed" curly braces and brackets, the |
> character or \ and the like.

	FWIW: I've got the arrow keys working.  page up/down, home, 
	end too.
> 
> 
> 
> > 	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??
> 
> That's easy.
> 
> Create a file ~/.xmodmaprc with the following content:
> 
> ! 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
> 
> Then add the command
> 
> 	xmodmap ~/.xmodmaprc
> 
> to ~/.xinitrc or ~/.xsession (depending on how you start X).


	I think that was a dead-end....

> 
> I'm using a similar approach myself to make the additional
> keys of the Sun USB Type 7 keyboard usable in X: They are
> assigned key symbols (usually F-something) so WindowMaker
> can pick them up for window management functions or starting
> programs (e. g. the volume keys lower or raise the audio
> volume or mute the headphones, the "moon key" quits the
> session / logout, Ctrl+Alt+Moon shuts down the system).
> All I did was first use "sev" to find out the key codes of
> the non-functional keys, then assign them an arbitrarily
> chosen name via xmodmap, and finally use the "Capture"
> function of the WindowMaker preferences utility to make
> them actually do something.
> 
> But note! If you redefine modifier keys to be "further
> function keys", expect to lose their modifier functionality!
> This could render them useless. So make sure you can revert
> your setting (e. g. have an external shell access that
> won't be affected) to comment out the xmodmaprc command in
> the X startup file if needed!
> 
	
	right.  I got too deep in the weeds trying code that was 
	too far out.  I'll spare everybody.  the last assembler I 
	wrote was for the PDP-8!  IF I can use the 64bit intel 
	assembler to grab the keys I want and return to the rest 
	of my C/ncurses prog, that might work.

	anybody know if this makes any sense?

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

-- 
 Gary Kline  kline at thought.org  http://www.thought.org  Public Service Unix
             Twenty-seven years of service to the Unix community.
                            http://www.thought.org/HOPE




More information about the freebsd-questions mailing list