1. Keyboard status function
- Posted by Marcel Kollenaar <M.Kollenaar at SLO.NL> May 01, 1997
- 675 views
To all Readers, I needed a status indicator if the 'Insert' key was active. I couldn't remember if our machine code Guru Jacques D. (positive) already coded this and hadn't the time to ask for it. After short searching in an old DOS programming book I found this. I put it on the list maybe someone else might need it. The function reads the status byte of the keyboard by int16h on location 0040:0017h. (or 0000:0417h) Have a nice day, Marcel Kollenaar --Start code include machine.e constant SHIFT_RIGHT = 1, SHIFT_LEFT = 2, CONTROL = 4, ALT = 8, SCROLL_LOCK = 16, NUM_LOCK = 32, CAPS_LOCK = 64, INSERT = 128 function kb_stat(atom mask) -- Uses DOS INT #16, service #02 to read the status of the keyboard -- Returns 1 if mask is in use else 0. -- BIT KEY MASK -- 0 right shift key 1 -- 1 left shift key 2 -- 2 Ctrl 4 -- 3 Alt 8 -- 4 Scroll lock 16 -- 5 Num lock 32 -- 6 Caps lock 64 -- 7 Insert 128 sequence reg_list reg_list = repeat(0,10) reg_list[REG_AX] = #0200 reg_list = dos_interrupt(#16,reg_list) -- -- Because AH has still the function value #02, subtract AX with -- #0200. After al not necessary! -- return and_bits(reg_list[REG_AX]-#0200,mask) and mask end function if kb_stat(INSERT) then puts(1,"Insert key: ON\n") else puts(1,"Insert key: OFF\n") end if if kb_stat(CAPS_LOCK) then puts(1,"Caps Lock key: ON\n") else puts(1,"Caps Lock key: OFF\n") end if -- Code ends here