howto recognize the Shift and Alt keys when /pressed\

Polytropon freebsd at
Thu Oct 24 00:11:49 UTC 2013

On Wed, 23 Oct 2013 16:38:05 +0000, Gary Kline wrote:
> 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 >

If it's just water, it should be no problem. There are
three screws (6-edge 6.5mm, if I remember correctly)
that you need to remove to open the keyboard. It then
easily dissolves. The keycaps and their sockets can
also be removed. Furthermore, the "spring mat" and the
contact mats can be removed. All of them are easy to
try and re-assemble.

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

Those keys can act in two ways:

Way 1 works on the fewest occassions. It's independent from
software and regulates the volume just as comparable keys
adjust brightness or contrast. There is no need for a driver
or vendor-supplied program to make them work.

Way 2 is to rely on a proprietary driver that's only available
for some outdated "Windows" which picks up the keycodes sent
by the "overlay function" of the PF keys, and _that_ program
causes the desired action. Sadly you find this on most "modern"

I have a Lenovo laptop with blue colored "overlay" functions
for many keys. For example, the cursor keys have an "overlay"
as "media keys" (play, pause, rewind and so on). When they
are pressed with the Fn key, they emit a totally different
keycode. This code itself doesn't cause anything to happen.
But as it is a normal key code, it can be captured and used
for any desired action. On the other hand, it has also a key
(I think Fn+Home) for the "IntelliLight" (if I remember the
name correctly). That key combination switches on a light at
the top of the screen that illuminates the keyboard. It does
not send any keycode and _always_ works - without any inter-
action with software, it even works in the BIOS setup.

If your program needs to work on all Unix variants _and_ on
Linux, you should make sure you rely on a sound output system
that is present on all of them (requires 3rd party library).
The same will probably be true for accessing the keyboard in
a "low level" manner, but I'm almost sure this works very
different in Linux and the BSDs...

> 	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??

You don't need to step down _that_ far. C is sufficient. But
you need to get your hands dirty in hardware-related system
source code, for example the keyboard input driver (one level
above atkbd and ukbd, one level below terminal I/O).

> 	my c = getch() isnt doing anything with the modifier keys.

Of course not. It simply reads from the keyboard input buffer
(which is a _character buffer_), and the modifier keys don't
add anything to that buffer.

> 	*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.

What are you using xset for? I know there's "xset c 100", but
I never saw that working...

> 	FWIW: I've got the arrow keys working.  page up/down, home, 
> 	end too.

Those have equivalents in ncurses and also send data to the
keyboard buffer (usually a two byte sequence or escape codes).

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

As I said, it would "practically disable" those keys, and
it doesn't look like that would be intended. :-)

> 	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?

No need to re-invent the wheel here. Just "attach to" the
responsible components of the OS mentioned above. In C. :-)

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

More information about the freebsd-questions mailing list