Hi,

I found Ctrl2cap.vxd from sysinternal. If I placed it in [386enh] it run well, but if i want to active it by W32DeviceIoControl it made my system down.

Need some explain!

here my code:
====================
.386p

include vmm.inc
include vwin32.inc
include vkd.inc

DECLARE_VIRTUAL_DEVICE MSPICKPR, 1, 0, MSPICKPR_Control, UNDEFINED_DEVICE_ID, UNDEFINED_INIT_ORDER

; scancode definitions
SCANESCAPE equ 0E0h
CAPSLOCK equ 3Ah
LEFTCTRL equ 1Dh
ACCENTGRAVE equ 1Eh
ESCAPEKEY equ 01h
LEFTSHIFT equ 2Ah
RIGHTSHIFT equ 36h
PRINTSCREEN equ 2Ah
PRINTSCREEN1 equ 37h

; up/down bit value
UP equ 0
DOWN equ 1

;============================================================================
; P U B L I C D A T A
;============================================================================

VXD_LOCKED_DATA_SEG

; Previous routine on keyboard hook
Keyboard_Proc dd 0

; what should the print-key be mapped to? (0 means no swap)
SwtchPrnKey dd 0

; should escape and accent grave be switched?
SwtchEscapeAccent dd 0

; what is the shift state?
LeftShiftState dd 0
RightShiftState dd 0

; what is the printscreen state?
PrintScreenState dd 0

; precode data for force-key
ForcePreByte db 0E0h, 0

; have we gotten a precode, yet?
PreCode db 0

VXD_LOCKED_DATA_ENDS


Begin_control_dispatch MSPICKPR
Control_Dispatch W32_DeviceIoControl, OnDeviceIoControl
End_control_dispatch MSPICKPR


VxD_PAGEABLE_CODE_SEG
BeginProc MyHook, Hook_Proc Keyboard_Proc

; get the scancode

mov dl, cl
and dl, 7Fh

; Trace_Out "Key: #CL"

;----------------------------------------------------------------------
;
; PRINTSCREEN HANDLER
;
;----------------------------------------------------------------------
; first, see if we even care

cmp SwtchPrnKey, 0
jz checklshift

; have we received the pre-scan code (0xE0)?

cmp PreCode, 0
jz checkprecode
mov PreCode, 0

; is this key a printscreen?

cmp dl, PRINTSCREEN
jnz checkprintkey1

; got a printscreen, so swap it

and cl, 80h
or cl, byte ptr SwtchPrnKey
test cl, 80h
jz printscreendown
mov PrintScreenState, UP
jmp chain

printscreendown:
mov PrintScreenState, DOWN
jmp chain

; we didn't get a printscreen, but see if this is the secondary
; scancode generated by printscreen, which we must swallow if we
; are swapping

checkprintkey1:

; if printscreen is down, we have to squash secondary print-screen

cmp PrintScreenState, DOWN
jnz forceprecode

; is it the secondary printscreen key?

cmp dl, PRINTSCREEN1
jnz forceprecode

; yep, swallow it

stc
ret

; okay, its another two-byte scancode that we should send in

forceprecode:
push ecx
push esi
mov ecx, 1
lea esi, ForcePreByte
VxDCall VKD_Force_Keys
pop esi
pop ecx
jmp chain

; see if this is the precode byte

checkprecode:
cmp cl, SCANESCAPE
jnz checklshift
mov PreCode, 1
stc ; swallow it so system ignores it until
ret ; we figure out what to do with it

;----------------------------------------------------------------------
;
; CODE TO KEEP TRACK OF SHIFT KEY STATE
;
;----------------------------------------------------------------------
; is the left-shift status changing?

checklshift:
cmp dl, LEFTSHIFT
jnz checkrshift
test cl, 80h
jz leftshiftdown
mov LeftShiftState, UP
jmp chain

leftshiftdown:
mov LeftShiftState, DOWN
jmp chain

; is the right-shift status changing?

checkrshift:
cmp dl, RIGHTSHIFT
jnz cap2ctrl
test cl, 80h
jz rightshiftdown
mov RightShiftState, UP
jmp chain

rightshiftdown:
mov RightShiftState, DOWN
jmp chain

;----------------------------------------------------------------------
;
; CAP2CTRL CODE
;
;----------------------------------------------------------------------
; switch caps-lock to control

cap2ctrl:
cmp dl, CAPSLOCK
jnz esc2accent
and cl, 80h
or cl, LEFTCTRL
jmp chain

;----------------------------------------------------------------------
;
; ESCAPE 2 ACCENT GRAVE CODE
;
;----------------------------------------------------------------------
; is the escape-accent grave switch option turned on?

esc2accent:
cmp SwtchEscapeAccent, 0
jz chain

; yes, see if the escape key has been pressed

escape:
cmp dl, ESCAPEKEY
jnz accent
cmp LeftShiftState, UP ; is shift key down?
jnz chain ; yep, don't switch tilde
cmp RightShiftState, UP
jnz chain
and cl, 80h
or cl, ACCENTGRAVE
jmp chain

; see if the accent key has been pressed (needs shift up)

accent:
cmp dl, ACCENTGRAVE
jnz chain
cmp LeftShiftState, UP ; is a shift key down?
jnz chain ; yep, they want tilde - no switch
cmp RightShiftState, UP
jnz chain
and cl, 80h
or cl, ESCAPEKEY
jmp chain

;----------------------------------------------------------------------
;
; FALL THROUGH TO PREVIOUS HANDLER
;
;----------------------------------------------------------------------
; call the previous hooker
chain:
; Trace_Out "---> #CL"
call Keyboard_Proc
clc ; let the key through
ret

EndProc MyHook

BeginProc OnDeviceIoControl
assume esi:ptr DIOCParams
.if .dwIoControlCode==DIOC_Open
xor eax,eax
.elseif .dwIoControlCode==1
GetVxDServiceOrdinal eax, VKD_Filter_Keyboard_Input
mov esi, offset32 MyHook
VMMCall Hook_Device_Service
mov Keyboard_Proc, esi
clc
.elseif .dwIoControlCode==2
GetVxDServiceOrdinal eax, VKD_Filter_Keyboard_Input
mov esi, offset32 MyHook
VMMCall UnHook_Device_Service
clc
.endif
ret
EndProc OnDeviceIoControl

VxD_PAGEABLE_CODE_ENDS

end

====================

I want to use this code to disable some key like Ctrl, Alt, Shift, F1, or some combine key like Alt-Z. If you have any ideas, please show it for me!

Thank you,
Bung
Posted on 2001-11-21 21:19:42 by bung