[comp.lang.pascal] Keyboard lights

rsandfor@oucsace.cs.ohiou.edu (Robert Sandford) (11/16/90)

on or off. It seems to work only on 101 keyboards though. Others
it will just set either the num lock on or off but the light will
not change. If anyone knows how to make the lights flash please E-mail
the info, I probably need to reset something, because when I put the 
capson and capsoff i can't get it to flash on and off. So any ideas on how
i would aprreciate it.
 
PROGRAM Key_lights;
USES CRT;

VAR s:string;

PROCEDURE CapsOn;
BEGIN
  Mem[$40:$17]:=mem[$40:$17] OR $40
END;

PROCEDURE CapsOff;
BEGIN
  Mem[$40:$17]:=mem[$40:$17] AND $BF
END;

PROCEDURE NumOn;
BEGIN
  Mem[$40:$17]:=mem[$40:$17] OR $20
END;

PROCEDURE NumOff;
BEGIN
  Mem[$40:$17]:=mem[$40:$17] AND $DF
END;

PROCEDURE ScrollOn;
BEGIN
  Mem[$40:$17]:=mem[$40:$17] OR $10
END;

PROCEDURE ScrollOff;
BEGIN
  Mem[$40:$17]:=mem[$40:$17] AND $EF
END;

BEGIN
  CapsOn;
  Scrollon;
  Numon;
END.

zhou@brazil.psych.purdue.edu (Albert Zhou) (11/16/90)

It is said that it's not always safe to write things to BIOS data area, althoughyou can always read information from it. In this case I wonder if it is safe   
to write on this area in order to change key status.

tswingle@oucsace.cs.OHIOU.EDU (Tom Swingle) (11/16/90)

In article <11485@j.cc.purdue.edu> zhou@brazil.psych.purdue.edu (Albert Zhou) writes:
>It is said that it's not always safe to write things to BIOS data area, althoughyou can always read information from it. In this case I wonder if it is safe   
>to write on this area in order to change key status.

I've read a lot of Pascal books that have code like this to modify keyboard
status bytes, and none of them have ever mentioned this as being dangerous.
This may not be true of everything, though, but keyboard status seems like a
harmless enough thing to modify, although it can get annoying when the lights
on the keyboard get out of synch with the status in memory.
-- 
#include <signature.h>

eli@aspasia.gang.umass.edu (Eli Brandt) (11/17/90)

In article <2526@oucsace.cs.OHIOU.EDU> rsandfor@oucsace.cs.ohiou.edu (Robert Sandford) writes:
>on or off. It seems to work only on 101 keyboards though. Others
>it will just set either the num lock on or off but the light will
>not change. If anyone knows how to make the lights flash please E-mail
>the info, I probably need to reset something, because when I put the 
>capson and capsoff i can't get it to flash on and off. So any ideas on how
>i would aprreciate it.
> 
>PROGRAM Key_lights;
>USES CRT;
>
>VAR s:string;
>
>PROCEDURE CapsOn;
>BEGIN
>  Mem[$40:$17]:=mem[$40:$17] OR $40
>END;
>
>PROCEDURE CapsOff;
>BEGIN
>  Mem[$40:$17]:=mem[$40:$17] AND $BF
>END;
>
>PROCEDURE NumOn;
>BEGIN
>  Mem[$40:$17]:=mem[$40:$17] OR $20
>END;
>
>PROCEDURE NumOff;
>BEGIN
>  Mem[$40:$17]:=mem[$40:$17] AND $DF
>END;
>
>PROCEDURE ScrollOn;
>BEGIN
>  Mem[$40:$17]:=mem[$40:$17] OR $10
>END;
>
>PROCEDURE ScrollOff;
>BEGIN
>  Mem[$40:$17]:=mem[$40:$17] AND $EF
>END;
>
>BEGIN
>  CapsOn;
>  Scrollon;
>  Numon;
>END.

On my keyboard, at least (an IBM "enhanced" eight-pounder), there are two
different sets of bits.  There is the one you're using, which flips
both the keyboard state and the LED, and there's another which flips just
the LED's.  If you use the second one it's very easy to get the true
state out of sync with the indicator light, which can be annoying.  The
problem is that many "compatible" BIOS's/keyboards don't seem to implement
this properly.  Try playing around with the other byte, which I think is
located at $84.  (For God's sake don't just write to that location without
seeing what it is; I've probably got it wrong)

Eli

dave@tygra.ddmi.com (David Conrad) (11/18/90)

[Oops, deleted attribution.  Sorry.]
)
)On my keyboard, at least (an IBM "enhanced" eight-pounder), there are two
)different sets of bits.  There is the one you're using, which flips
)both the keyboard state and the LED, and there's another which flips just
)the LED's.  If you use the second one it's very easy to get the true
)state out of sync with the indicator light, which can be annoying.  The
)problem is that many "compatible" BIOS's/keyboards don't seem to implement
)this properly.  Try playing around with the other byte, which I think is
)located at $84.  (For God's sake don't just write to that location without
)seeing what it is; I've probably got it wrong)
)
)Eli

$40:$84 (1 byte): The number of rows on the screen - 1.
$40:$17 (1 byte): Keyboard shift states:
     Bit    Meaning
   76543210 (1 = active; 0 = inactive)
   -------- --------------------------
   x....... Insert State
   .x...... Caps Lock
   ..x..... Num Lock
   ...x.... Scroll Lock
   ....x... 1 = Alt pressed
   .....x.. 1 = Ctrl pressed
   ......x. 1 = Left Shift pressed
   .......x 1 = Right Shift pressed
$40:$18 (1 byte): Extended keyboard shift states
     Bit    Meaning
   76543210 (1 = pressed)
   -------- --------------------------
   x....... Ins pressed
   .x...... Caps Lock pressed
   ..x..... Num Lock pressed
   ...x.... Scroll Lock pressed
   ....x... Hold state active (Ctrl-Num Lock or Pause)
   .....x.. Sys Req key pressed
   ......x. Left Alt key pressed
   .......x Left Ctrl key pressed
pressed means actually being held down
[in]active means current toggle state
"...it is potentially very disruptive to change any of the key-is-pressed
bits (bits 0 through 3 of byte 0040:0017H or any bits in byte 0040:0018H)."
-- The *New* Peter Norton Programmer's Guide to The IBM PC & PS/2;
Peter Norton, Richard Wilton; Microsoft Press; ISBN 1-55615-131-4.
--
David R. Conrad
dave@tygra.ddmi.com
This article is in the public domain.
-- 
=  CAT-TALK Conferencing Network, Prototype Computer Conferencing System  =
-  1-800-825-3069, 300/1200/2400/9600 baud, 8/N/1. New users use 'new'    - 
=  as a login id.    <<Redistribution to GEnie PROHIBITED!!!>>>           =
E-MAIL Address: dave@ThunderCat.COM