flat assembler
Message board for the users of flat assembler.
Index
> Windows > keyboard hook |
Author |
|
coconut 03 Jun 2004, 08:14
example on a system wide keyboard hook, allowing you to disable keys and such. msdn docs say hook procs must be in a dll, works here in the exe itself with no problems on win2k. in this example the right and left windows logo keys are disabled
|
|||||||||||
03 Jun 2004, 08:14 |
|
decard 03 Jun 2004, 11:11
Was it supposed to run in Win98? It doesn't...
|
|||
03 Jun 2004, 11:11 |
|
coconut 03 Jun 2004, 14:36
oh i see it now..
Quote:
try using WH_KEYBOARD on 95/98, tho it may not capture all the same keys |
|||
03 Jun 2004, 14:36 |
|
inskipp 03 Jun 2004, 15:10
Exported functions:
MakeHook(hwnd) UnHook() A hooked (witch MakeHook) function window receives WM_KEY message every time a key is depressed. wParam contains ASCII code. I wrote this a long time ago, so it may be buggy, but I think some parts may be useful. [code]format PE GUI DLL entry DLL_init include '%fasminc%\win32a.inc' WM_KEY=WM_USER+100d section '.code' code readable executable shareable proc DLL_init,hinstDLL,fdwReason,lpvReserved enter cmp [fdwReason],DLL_PROCESS_DETACH je .cleanup mov eax,[hinstDLL] mov [hModule],eax mov eax,1 ; successful initialization .ex: return .cleanup: call UnHook jmp .ex endp proc MakeHook,hwnd ;returns 0 when error enter mov eax,[hwnd] mov [hHookedWnd],eax invoke SetWindowsHookEx,WH_KEYBOARD,HookProc,[hModule],0 mov [hHook],eax return endp align 4 UnHook: invoke UnhookWindowsHookEx,[hHook] ret proc HookProc,code,wParam,lParam KeyState rb 256 cBufor rb 4 enter push ebx invoke CallNextHookEx,[hHook],[code],[wParam],[lParam] push eax ;save return vaulue cmp [code],HC_ACTION jne .skip test [lParam],80000000h ;is key being released jnz .skip lea ebx,[KeyState] invoke GetKeyboardState,ebx movzx eax,byte[lParam+2] ;scan code lea ecx,[cBufor] invoke ToAscii,[wParam],eax,ebx,ecx,0 test eax,eax jz .skip push eax ;push character count movzx eax,[cBufor] invoke PostMessage,[hHookedWnd],WM_KEY,eax,0 pop eax ;pop character count cmp al,2 jz .skip movzx eax,[cBufor+1] invoke PostMessage,[hHookedWnd],WM_KEY,eax,0 .skip: pop eax ;restore ruturn value pop ebx return endp section '.data' data readable writeable shareable hModule dd ? hHook dd ? hHookedWnd dd ? section '.idata' import data readable writeable library user,'USER32.DLL' import user,\ SetWindowsHookEx,'SetWindowsHookExA',\ UnhookWindowsHookEx,'UnhookWindowsHookEx',\ CallNextHookEx,'CallNextHookEx',\ PostMessage,'PostMessageA',\ ToAscii,'ToAscii',\ GetKeyboardState,'GetKeyboardState' section '.edata' export data readable export 'KEY.DLL',\ ;dll name MakeHook,'MakeHook',\ UnHook,'UnHook' section '.reloc' fixups data readable discardable[/code] |
|||
03 Jun 2004, 15:10 |
|
asmdemon 26 Jul 2004, 00:49
Quote: msdn docs say hook procs must be in a dll the reason for using a dll is due to it's ability to be accessed many times by many programs in a multitasking environment. Though, a dll is not required. _________________ It is better to be on the right side of the devil than in his path. |
|||
26 Jul 2004, 00:49 |
|
f0dder 26 Jul 2004, 03:10
The reason most global hooks must be in DLLs is simple - the hooks need to execute in the context of multiple processes, and thus the OS has to inject hook DLLs into those process address spaces.
It's pretty easy to determine if a global hook needs to be put in a DLL or not - try keeping it in your app, and install the hook. If the system comes crashing down, you need to put it in a DLL |
|||
26 Jul 2004, 03:10 |
|
coconut 26 Jul 2004, 03:26
works fine on 2k/xp in this example, no dll used
|
|||
26 Jul 2004, 03:26 |
|
f0dder 26 Jul 2004, 03:46
PlatformSDK has this to say:
Quote:
...so it sounds like, officially too, no DLL is needed for this hook. |
|||
26 Jul 2004, 03:46 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.