The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: korte on November 09, 2007, 11:05:56 AM

Title: KEYBOARD HOOK numlock problem
Post by: korte on November 09, 2007, 11:05:56 AM
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 (http://programista.hu/numlock.zip)
Title: Re: KEYBOARD HOOK numlock problem
Post by: bozo on November 09, 2007, 07:18:05 PM
what about RegisterHotKey() (http://msdn2.microsoft.com/en-us/library/ms646309.aspx) ??
Title: Re: KEYBOARD HOOK numlock problem
Post by: bozo on November 09, 2007, 10:29:09 PM
sorry, i misunderstood your posting, my mistake.