I'm trying to intercept keyboard messages of a Richedit 2.0 control.
The problem is that when some key is held down and another key is pressed, the WM_KEYDOWN message for only the first key is received by the subclass procedure. For example if I press something like "Shift+Insert", the WM_KEYDOWN message is received for Shift but not for Insert. Spy++ however shows that all the messages for Shift and Insert have been posted.
Could I be doing something wrong here?
Quote from: xmetal on February 08, 2008, 08:16:44 PM
Could I be doing something wrong here?
Yeah, you forgot that you are intercepting "Shift+Insert" with an accelerator.
Hello,
Two steps to do this without any accelerator table
1) the messages of the control must go to your own proc
Quote
INVOKE SetWindowLong, Hedit, GWL_WNDPROC, EventEdit
mov lpEdit, eax
2)
The new proc must return to the old proc
For combined key as alt+...,shift+.... you receive only a message (in a very limited time) when the key go down and a message when the key go up.This mean that you must remember this key is down.If another key is down,see if a shift,alt or control is down (state in memory) to know the number of key down.
sample:
.data
ShiftState DD 0
ControlState DD 0
MenuState DD 0
Quote
EventEdit PROC uses esi edi ebx HeditRetour:DWORD, uMsg, wParam, lParam
Local phrase[MAX_PATH]:BYTE,KeyState[256]
ZEROLOCALES KeyState
.if uMsg == WM_KEYDOWN
.if wParam == VK_SHIFT
mov ShiftState,VK_SHIFT
.elseif wParam == VK_LSHIFT
mov ShiftState,VK_LSHIFT
.elseif wParam == VK_RSHIFT
mov ShiftState,VK_RSHIFT
.elseif wParam == VK_CONTROL
mov ControlState,VK_CONTROL
.elseif wParam == VK_RCONTROL
mov ControlState,VK_RCONTROL
.elseif wParam == VK_LCONTROL
mov ControlState,VK_LCONTROL
.elseif wParam == VK_MENU
mov MenuState,VK_MENU
.elseif wParam == VK_LMENU
mov MenuState,VK_LMENU
.elseif wParam == VK_RMENU
mov MenuState,VK_RMENU
.endif
.if RadioButton == 1
invoke GetKeyNameText,lParam,addr phrase,sizeof phrase
lea eax,phrase
invoke SendDlgItemMessage,HclavBox,IDC_EXPLORATEUREDIT1,WM_SETTEXT,0,addr phrase
.elseif RadioButton == 2
mov eax,lParam
and eax,infoclav.ScanCode
shr eax,16
lea ebx,TabClav
cherche:
.if dword ptr [ebx] != 0 && dword ptr [ebx+4] != 0
mov eax,[ebx]
.if eax == wParam
add ebx,4
invoke lstrcpy,addr phrase,ebx
invoke SendDlgItemMessage,HclavBox,IDC_EXPLORATEUREDIT1,WM_SETTEXT,0,addr phrase
.else
add ebx,4
@@:
.if byte ptr [ebx] != 0
inc ebx
jmp @B
.endif
inc ebx
jmp cherche
.endif
.endif
.elseif RadioButton == 3
comment µ
invoke GetKeyboardState,addr KeyState
invoke ToAscii,wParam,lParam,addr KeyState,addr phrase,MenuState
.if eax == 1 || eax == 2 ;VK_PRIOR
invoke SendDlgItemMessage,HclavBox,IDC_EXPLORATEUREDIT1,WM_SETTEXT,0,addr phrase
.endif
µ
.endif
.if RadioButton != 3
return 0
.endif
.elseif uMsg == WM_KEYUP
.if wParam == VK_SHIFT
mov ShiftState,0
.elseif wParam == VK_LSHIFT
mov ShiftState,0
.elseif wParam == VK_RSHIFT
mov ShiftState,0
.elseif wParam == VK_CONTROL
mov ControlState,0
.elseif wParam == VK_RCONTROL
mov ControlState,0
.elseif wParam == VK_LCONTROL
mov ControlState,0
.elseif wParam == VK_MENU
mov MenuState,0
.elseif wParam == VK_LMENU
mov MenuState,0
.elseif wParam == VK_RMENU
mov MenuState,0
.endif
.if RadioButton != 3
return 0
.endif
.elseif uMsg == WM_CHAR
.if RadioButton != 3
return 0
.endif
.endif
INVOKE CallWindowProc, lpEdit, HeditRetour, uMsg, wParam, lParam
ret
EventEdit ENDP