Why does this not work?? (mouseevent)
I wanted to make some sort of macro for mouse events en keyboard events,
but the mousedown event doesn't work,
Although the position of the mouse works perfectly!
Code:
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
Private Const CF_TEXT = 1
Const MOUSEEVENTF_LEFTDOWN = &H2
Const MOUSEEVENTF_LEFTUP = &H4
Const MOUSEEVENTF_RIGHTDOWN = &H8 ' right button down
Const MOUSEEVENTF_RIGHTUP = &H10 ' right button up
Const MOUSEEVENTF_MOVE = &H1 ' mouse move
Const WM_CHAR = &H102
Sub dodo()
SetCursorPos 85, 220
mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0
'mouse_event MOUSEEVENTF_RIGHTUP, 0&, 0&, cButt,dwEI
'mouse_event MOUSEEVENTF_RIGHTDOWN, 0&, 0&, cButt, dwEI
mouse_event MOUSEEVENTF_MOVE, 150, 130, 0, 0
mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
DoEvents
End Sub
Can someone guide me to the solution?
Re: Why does this not work?? (mouseevent)
The set pos I've used so I know that is right.
The mouse event is not however. I have a feeling that there is a button select section on either the keyboard scan api or on the set mouse pointer.
I am just going to look if I can find something on that.
Re: Why does this not work?? (mouseevent)
Well, I'm curious,
have you come up with something?
I have to do the same mouse-clicks over and over again.
I'm getting tired of it.
(by the way, I can't install a macro-maker program on my computer.
It's appguarded!)
Re: Why does this not work?? (mouseevent)
What are you trying to do??
Check back here in 30 mins - might have a link - just gonna read it to make sure its ok/useful
vb helper
hmmm looks like the mouse_event is called.. maybe you were close with your code :) good luck
Re: Why does this not work?? (mouseevent)
I got this:
(it's very much the same as the first one, but it still doesn't work)
Code:
Private Declare Sub mouse_event Lib "user32" ( _
ByVal dwFlags As Long, _
ByVal dx As Long, ByVal dy As Long, _
ByVal cButtons As Long, _
ByVal dwExtraInfo As Long)
Private Const MOUSEEVENTF_ABSOLUTE = &H8000 ' absolute move
Private Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
Private Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
Private Const MOUSEEVENTF_MIDDLEDOWN = &H20 ' middle button down
Private Const MOUSEEVENTF_MIDDLEUP = &H40 ' middle button up
Private Const MOUSEEVENTF_MOVE = &H1 ' mouse move
Private Const MOUSEEVENTF_RIGHTDOWN = &H8 ' right button down
Private Const MOUSEEVENTF_RIGHTUP = &H10 ' right button up
Sub Move()
mouse_event MOUSEEVENTF_MOVE Or MOUSEEVENTF_ABSOLUTE, 3550, 12000, 0, 0
mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0
mouse_event MOUSEEVENTF_MOVE Or MOUSEEVENTF_ABSOLUTE Or MOUSEEVENTF_RIGHTDOWN, 3550, 12000, 0, 0
mouse_event MOUSEEVENTF_MOVE Or MOUSEEVENTF_ABSOLUTE Or MOUSEEVENTF_RIGHTUP, 30020, 34650, 0, 0
DoEvents
End Sub
What I'm trying to do is this:
I have a powerpoint presentation with a minimized screen, wich activates a small form. When I press enter the Move-sub starts.
In the program running left to the form I have to draw a box with the right mousebutton.
I simulated this first with the mouse itsellf.
First I click right (to activate the program I draw the box in), then I draw the box with the right mousebutton.
But the code doesn't draw the box.
Try it yoursellf run the code with a word document on the left of the screen to see the selection...
I can't make the code draw.
Take this code to select in word:
Code:
Sub DrawBox()
mouse_event MOUSEEVENTF_MOVE Or MOUSEEVENTF_ABSOLUTE, 3550, 12000, 0, 0
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
mouse_event MOUSEEVENTF_MOVE Or MOUSEEVENTF_ABSOLUTE Or MOUSEEVENTF_LEFTDOWN, 3550, 12000, 0, 0
mouse_event MOUSEEVENTF_MOVE Or MOUSEEVENTF_ABSOLUTE Or MOUSEEVENTF_LEFTUP, 30020, 34650, 0, 0
DoEvents
End Sub
I don't get it