News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

WM_LBUTTONDOWN & virtual keypresses

Started by Rainstorm, March 26, 2009, 03:57:19 AM

Previous topic - Next topic

Rainstorm

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

sinsi

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

Light travels faster than sound, that's why some people seem bright until you hear them.

Rainstorm

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


   -


sinsi

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.
Light travels faster than sound, that's why some people seem bright until you hear them.