News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

KEYBOARD HOOK numlock problem

Started by korte, November 09, 2007, 11:05:56 AM

Previous topic - Next topic

korte

I prepare a program, which switches it on, NUMLOCK button.
Keyboard hookl I ban it the another pressing.
The program works half.
Turns it on the numlock LED.
Catches the button presses and bans it.
But not well, because the state of the LED does not change simply, but onto the function the program is not with an effect.



.386
.model flat, stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

KeyBoardProc proto :DWORD, :WPARAM, :LPARAM

.data
hHook dd 0
mutex db "Global\pdgkhook",0
keys db 256 dup (0)
msg MSG <>


.code

main:
invoke CreateMutexA,0,0,ADDR mutex
invoke GetLastError
.if  eax!=ERROR_ALREADY_EXISTS

invoke GetKeyboardState, addr keys
.if byte ptr [keys+VK_NUMLOCK]==0
invoke keybd_event, VK_NUMLOCK, 45h, KEYEVENTF_EXTENDEDKEY , 0
        invoke keybd_event, VK_NUMLOCK, 45h, KEYEVENTF_EXTENDEDKEY + KEYEVENTF_KEYUP, 0
.endif

invoke  GetModuleHandleA, NULL

invoke SetWindowsHookExA, WH_KEYBOARD_LL, ADDR KeyBoardProc, eax, 0
mov [hHook], eax

invoke GetMessageA, ADDR msg, NULL, NULL, NULL
invoke UnhookWindowsHookEx, hHook
.endif
invoke ExitProcess, 0h

KeyBoardProc PROC nCode:DWORD, wParam:DWORD, lParam:DWORD

mov esi, [lParam]
lodsd
.if al==VK_NUMLOCK

.else
invoke CallNextHookEx, hHook, nCode, wParam, lParam
.endif
ret

KeyBoardProc ENDP

end main



programista.hu/numlock.zip


bozo

sorry, i misunderstood your posting, my mistake.