PowerPoint (or Excel) VBA Capture Coordinates of Mouse Click -


some background:

the quick background in research stages of building add-in powerpoint. end goal develop cad dimensioning add-in expedite creating of engineering presentations. have lot of "powerpoint engineering" general sizes of components shown on simplified versions of said components created ppt shapes or screenshots of cad geometry itself. creating dimensions on , on tedious. each 1 consists of arrow, 2 lines, , text box dimension value.

here need help.

(if know how following in excel, work , work figure ppt equivalent later.)

in powerpoint slide, while in design mode (i.e. not slide show mode), want following workflow:

  1. in open userform, user clicks button called "start"
  2. the code starts listen left mouse click (lmc) out in field of slide (it should not respond lmc on actual userform, example if user needs drag userform out of way)
  3. upon lmc, coordinates of cursor recorded (x1,y1)
  4. repeat steps 2 & 3 record (x2, y2)
  5. do stuff these coordinates (e.g. draw dimension between 2 coordinates

i believe can handle of coding exception step 2, why here. having trouble finding starting point. specifically, need how listen lmc. in words, envision following:

while listening:   if lmc = true     stuff   end if end while  

but don't have knowledge code while listening part. need nudge in right direction.

my searches have landed me on mousedown event handler pages @ msdn, in testing, don't think need. seem though mousedown intended start routine when mouse down on commandbutton in userform self.

i have found post answer seemed imply not possible without going great lengths , code possible detrimental file itself: how record mouse clicks in excel vba?. (i have no problem going great lengths , putting in work, not if resulting code has high likelihood of doing damage post seems suggest.) (also, op downvoted no explanation, maybe can tell me why don't make same mistake.)

you can accomplish looking doing following (the bottom part may helpful you): first, declare following:

public declare function setcursorpos lib "user32" (byval x long, byval y long) long public declare sub mouse_event lib "user32" (byval dwflags long, byval dx long, byval dy long, byval cbuttons long, byval dwextrainfo long) public const mouseeventf_leftdown = &h2 public const mouseeventf_leftup = &h4 public const mouseeventf_rightdown long = &h8 public const mouseeventf_rightup long = &h10 

and following code snippets allow either click, double click, or right click:

private sub singleclick()   setcursorpos 100, 100 'x , y position   mouse_event mouseeventf_leftdown, 0, 0, 0, 0   mouse_event mouseeventf_leftup, 0, 0, 0, 0 end sub  private sub doubleclick()   'double click quick series of 2 clicks   setcursorpos 100, 100 'x , y position   mouse_event mouseeventf_leftdown, 0, 0, 0, 0   mouse_event mouseeventf_leftup, 0, 0, 0, 0   mouse_event mouseeventf_leftdown, 0, 0, 0, 0   mouse_event mouseeventf_leftup, 0, 0, 0, 0 end sub  private sub rightclick()   right click   setcursorpos 200, 200 'x , y position   mouse_event mouseeventf_rightdown, 0, 0, 0, 0   mouse_event mouseeventf_rightup, 0, 0, 0, 0 end sub 

all need change cursor position coordinates on screen. this, made new macro following code , assigned "ctrl+y" button. tell coordinates of current mouse location.

declare function getcursorpos lib "user32" (lppoint pointapi) long type pointapi     x long     y long end type  sub curosrxy_pixels()      dim lngstatus long     dim typwhere pointapi      lngstatus = getcursorpos(typwhere)     msgbox "x: " & typwhere.x & chr(13) & "y: " & typwhere.y, vbinformation, "pixels"  end sub 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -