I want to lock keyboard under Windows 95 or 98, anyone know I can to do ? Thx !
Posted on 2001-03-14 02:20:00 by EAGLE Art
This is not a beginners question, it will be quite complicated as you will have to hook the keayboard and not pass on any messages the proc recieves would be my approach
Posted on 2001-03-14 02:53:00 by George
George, can you elaborate more? I also want to know how. I know how to do the hook. But I don't know how I can prevent the keyboard message going to the system? Thanks!!!!!
Posted on 2001-03-14 06:40:00 by zhanghz
no, thats very simple, just use: keyoff_str db "rundll32.exe keyboard,disable",0 invoke WinExec,addr keyoff_str,SW_HIDE i haven't tryed out that with "enable" yet but i think this possible.
Posted on 2001-03-14 08:40:00 by drcmda
to disable CTRL+ALT+DEL, ALT+TAB, CTRL+ESC, etc..: invoke SystemParametersInfo, SPI_SCREENSAVERRUNNING, 1, 0, 0 or to renable: invoke SystemParametersInfo, SPI_SCREENSAVERRUNNING, 0, 0, 0 to disable all keys you could try drcmda's way.. or you could use the following code I coded a long time ago :

DisableKeyboard PROC uses eax ;disable keyboard
LOCAL mod,vk:DWORD

invoke SystemParametersInfo, SPI_SCREENSAVERRUNNING, 1, 0, 0 ;disable system keys (win98 only)

mov mod, 0

LoopModifiers:
mov vk, 5 ;1-4 are mouse buttons

LoopRegHotKey:
mov eax, mod
imul eax, 0100h
add eax, 1000
add eax, vk
invoke RegisterHotKey, NULL, eax, mod, vk
inc vk
cmp vk, 0FFh
jb LoopRegHotKey

inc mod ;next modifier combination
cmp mod, 16
jb LoopModifiers

ret
DisableKeyboard ENDP

;------------

EnableKeyboard PROC uses eax ;enable keyboard
LOCAL mod,vk:DWORD

invoke SystemParametersInfo, SPI_SCREENSAVERRUNNING, 0, 0, 0 ;enable system keys

mov mod, 0

LoopModifiersOFF:
mov vk, 5 ;1-4 are mouse buttons

LoopRegHotKeyOFF:
mov eax, mod
imul eax, 0100h
add eax, 1000
add eax, vk
invoke UnregisterHotKey, NULL, eax
inc vk
cmp vk, 0FFh
jb LoopRegHotKeyOFF

inc mod ;next modifier combo
cmp mod, 16
jb LoopModifiersOFF

ret
EnableKeyboard ENDP
It registers all hotkeys that are available (with all modifier combinations like ALT+CTRL, etc), not to most optimized code, but should work.. This message was edited by savage, on 3/14/2001 1:20:22 PM
Posted on 2001-03-14 12:18:00 by savage
Ok Thanx for your answer, I tried the last code but don't function, it's possible to have in 100% ASM. EAGLE Art
Posted on 2001-03-15 02:34:00 by EAGLE Art
you've just to close the handle zero with the interrupt 21h with file fonctions. pass 0 as an argument. A+
Posted on 2001-03-16 11:38:00 by DaTaHuNTeR
keyboard uses irq1 and irq1 is mapped to int 51h under win9x. so you could either modify the 51th gate of the idt or disable irq1 (this would disable the mouse as well if it is connected to a ps2 port). hope this helps.
Posted on 2001-03-17 03:48:00 by hadez
Thanx you for your help, Have any example or code in ASM to demonstrate your procedures ?
Posted on 2001-03-17 04:27:00 by EAGLE Art
i don't have much time, so i'll make it quick here (sorry). if you have any questions, just ask again disabling irq1: - read port 21h (Interrupt Request Register of PIC 1) - set bit 1 in the byte you just read (this disables IRQ 1) - write this byte back to port 21h mov dx, 21h in al, dx or al, 02h out dx, al modifying the idt: - modify gate 51h - each gate is 8 bytes (2 DWORDs) long - read IDTR using sidt (this retreives IDT base address) - add 51h * 08h + 04h to the base address - low word of handler address is contained 4 bytes below - high word of handler address is contained 2 bytes higher - modify them to your own handler address - segment is contained 2 bytes below - change this one to your cs segment i have no more time, sorry. if you want source for the idt thing, just gimme a tell. Hope that helps.
Posted on 2001-03-17 13:41:00 by hadez
2 drcmda: no, this rundll32 call with keyboard,enable doesn't work unfortunately. 2 hadez: i'm also looking for a code to disable the keyboard temporaly, but i don't understand what you've written in your last posting. would you please post in an easy to understand code how to disable and then enable the keyboard again? does it also work on win nt? cya
Posted on 2001-03-18 06:53:00 by [SaFc0n]
first of all, i forgot to mention that you have to have ring 0 privileges to access port 21h. you can get ring 0 privileges by modifying the idt. for more information about that look at this site: http://phantom.urbis.net.il/bphantom/Win32_CPL0.html both possibilities (disabling irq1 and modifying the idt) do NOT work under nt cause you have no access to the idt, so you can't get ring 0 privileges. I'll try to explain the code a bit more precisely: mov dx, 21h ; prepare to write to port 21h in al, dx ; read a byte from the port and save it in al or al, 02h ; set bit 1 of the byte we just read out dx, al ; write the modified byte back to port 21h First of all you have to read the IRR of PIC1 from port 21h. The IRR tells the PIC (Programmable Interrupt Controller) which interrupts to enable and which to disable. Bit 0 of the IRR is used for IRQ0, Bit 1 for IRQ1 and so on...If a bit is set, the IRQ is DISABLED (masked). So if for example Bit 0 is set, IRQ0 is disabled. If Bit 1 is 0 (not set), IRQ1 is ENABLED. An example for the whole IRR: Content of IRR (binary): Bit: 76543210 <--- Bit positions Value: 11010001 <--- Content of IRR In this example IRQ0, IRQ4, IRQ6 and IRQ7 would be disabled cause the Bits 0, 4, 6 and 7 are set. IRQ1, 2, 3 and 5 would be enabled cause the Bits 1, 2, 3 and 5 are 0. Usually all bits should be 0 (all IRQs would be enabled). For more information about Hardware Interrupts, try this: http://www.beyondlogic.org/interrupts/interupt.htm Ok, so we just read the IRR. Now we set Bit 1 to DISABLE IRQ1 (IRQ1 is used by the keyboard controller). If we write the modified byte back to Port 21h, we'll change the content of the IRR and IRQ1 will be disabled. Hope that helps :)
Posted on 2001-03-18 12:22:00 by hadez