主题:关于键盘钩子的问题
HookProc proc _dwCode,_wParam,_lParam
local @szKeyState[256]:byte
invoke CallNextHookEx,hHook,_dwCode,_wParam,_lParam
invoke GetKeyboardState,addr @szKeyState
invoke GetKeyState,VK_SHIFT
mov @szKeyState + VK_SHIFT,al
mov ecx,_lParam
shr ecx,16
invoke ToAscii,_wParam,ecx,addr @szKeyState,addr szAscii,0
mov byte ptr szAscii [eax],0
invoke SendMessage,hWnd,dwMessage,dword ptr szAscii,NULL
xor eax,eax
ret
HookProc endp
这段代码是一个键盘钩子的回调函数。ToAscii这个API返回的是拷贝到szAscii的字符个数szAscii是这样定义的
szAscii db 4 dup (?)
意思就是说是4个字节 如果ToAscii拷贝了一个字符 那么
mov byte ptr szAscii [eax],0这句就是这样在拷贝的字符后面一个字节加一个0
比如拷贝的是A 那么就是 szAscii[0]='A' szAscii[1]=0了吧 后面两个字节也是0 对吧
那么这句invoke SendMessage,hWnd,dwMessage,dword ptr szAscii,NULL
发送一个用户定义的消息到窗口过程 附加参数是szAscii强制转换为dword类型
在窗口过程里面接受到的参数hWnd,wMsg,wParam,lParam分别是 hWnd,dwMessage,szAscii的4个字节,0 这4个参数。在这个程序处理dwMessage消息里面有这样一句,
mov eax,wParam ;这里是szAscii的4个字节的数据
.if al == 0dh ;这里判断是否为回车符
就是这里不明白。al不是eax最后面的8个字节吗 A这个字符不是放在eax的高8位里面的吗,怎么回在al里面判断是否有回车符呢?
local @szKeyState[256]:byte
invoke CallNextHookEx,hHook,_dwCode,_wParam,_lParam
invoke GetKeyboardState,addr @szKeyState
invoke GetKeyState,VK_SHIFT
mov @szKeyState + VK_SHIFT,al
mov ecx,_lParam
shr ecx,16
invoke ToAscii,_wParam,ecx,addr @szKeyState,addr szAscii,0
mov byte ptr szAscii [eax],0
invoke SendMessage,hWnd,dwMessage,dword ptr szAscii,NULL
xor eax,eax
ret
HookProc endp
这段代码是一个键盘钩子的回调函数。ToAscii这个API返回的是拷贝到szAscii的字符个数szAscii是这样定义的
szAscii db 4 dup (?)
意思就是说是4个字节 如果ToAscii拷贝了一个字符 那么
mov byte ptr szAscii [eax],0这句就是这样在拷贝的字符后面一个字节加一个0
比如拷贝的是A 那么就是 szAscii[0]='A' szAscii[1]=0了吧 后面两个字节也是0 对吧
那么这句invoke SendMessage,hWnd,dwMessage,dword ptr szAscii,NULL
发送一个用户定义的消息到窗口过程 附加参数是szAscii强制转换为dword类型
在窗口过程里面接受到的参数hWnd,wMsg,wParam,lParam分别是 hWnd,dwMessage,szAscii的4个字节,0 这4个参数。在这个程序处理dwMessage消息里面有这样一句,
mov eax,wParam ;这里是szAscii的4个字节的数据
.if al == 0dh ;这里判断是否为回车符
就是这里不明白。al不是eax最后面的8个字节吗 A这个字符不是放在eax的高8位里面的吗,怎么回在al里面判断是否有回车符呢?