The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Rainstorm on March 26, 2009, 03:57:19 AM

Title: WM_LBUTTONDOWN & virtual keypresses
Post by: Rainstorm on March 26, 2009, 03:57:19 AM
hi,
don't know why. but can't get the ctrl , shift  keypresses to work in the WM_LBUTTONDOWN msg, I have similar code for the WM_LBUTTONUP msg & it all works proper there

this code doesn't work
     .elseif uMsg == WM_LBUTTONDOWN
                   
          movzx ecx, word ptr [lParam]              ; x coordinate
          movzx edx, word ptr [lParam+2]            ; y coordiate

        ;  fn MessageBox, 0, ustr$(ecx), "x coordinate", MB_OK

          .if wParam == MK_SHIFT
              fn MessageBox, 0, "shift key down", "Keys", MB_OK
          .endif

          xor eax, eax
          ret


this worksas expected. . .

.elseif uMsg == WM_LBUTTONUP
          mov ecx, MK_CONTROL
          or ecx, MK_SHIFT

          .if wParam == ecx
             fn MessageBox, 0, "shift and ctrl pressed", "K e y s", MB_OK
          .endif
          xor eax, eax
          ret
Title: Re: WM_LBUTTONDOWN & virtual keypresses
Post by: sinsi on March 26, 2009, 04:09:38 AM
wParam is a bitmask, so more than one bit could be set.

  mov eax,wParam
  and eax,MK_SHIFT or MK_CONTROL
  cmp eax,MK_SHIFT
  jz shift_pressed
  cmp eax,MK_CONTROL
  jz control_pressed
  cmp eax,MK_SHIFT or MK_CONTROL
  jz both_pressed

Title: Re: WM_LBUTTONDOWN & virtual keypresses
Post by: Rainstorm on March 26, 2009, 04:36:57 AM
thanks.
just realised its because MK_LBUTTON is also set in the case of the buttondown msg, but is not set in the buttonup msg, that's why it works in the buttonup only. I modified my code for WM_LBUTTONDOWN to this, & it works right now.
.elseif uMsg == WM_LBUTTONDOWN
          .if wParam == MK_SHIFT or MK_LBUTTON
              fn MessageBox, 0, "shift key down", "Keys", MB_OK
          .endif
          xor eax, eax
          ret


   -

Title: Re: WM_LBUTTONDOWN & virtual keypresses
Post by: sinsi on March 26, 2009, 04:51:49 AM
Don't forget that there could be others -
MK_CONTROL,MK_LBUTTON,MK_MBUTTON,MK_RBUTTON,MK_SHIFT,MK_XBUTTON1,MK_XBUTTON2
You're better off using TEST (or even BT) to 'isolate' the separate bits in wParam.