Results 1 to 17 of 17

Thread: simulating a mouse click

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    I got this code:


    Code:
    Declare Function SetCursorPosition& Lib "user32" _
    (ByVal x as long, ByVal y as long
    
    
    
    
    Private Sub cmdMove_Click
    SetCursor Pos 0,0
    what that code does is puts the mouse at the position of 0,0


    now lets say that when the user presses that button, I want the mouse to smoothly go over the the start Button

    and then click it

    I can figure out the coordinates for the start button, but how do I hake it go smoothly, and then click? please help


    thanks in advance

  2. #2
    Guest
    Code:
    Declare Function SetCursorPos Lib "user32" (ByVal x _
    As Long, ByVal y As Long) As Long
    Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    
    Type POINTAPI
        x As Long
        y As Long
    End Type
    
    Private Sub Command1_Click()
    Dim P As POINTAPI
    Dim t&, k$, y
    For y = 0 To 500
    Do: DoEvents
    t& = SetCursorPos(300, y) 'SetCursorPos (x,y)
    k$ = GetCursorPos(P)
    Loop Until k$
    Next
    End Sub
    Hope that helps.


  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    but it doesn't click, I need it to click
    NXSupport - Your one-stop source for computer help

  4. #4
    Guest
    Here, use this code to popup the start menu instead, just put it at the end of that code.

    Code:
    Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lparam As Long) As Long
    
    Public Const WM_LBUTTONDOWN = &H201
    Public Const WM_LBUTTONUP = &H202
    
    Public Sub Win98_ClickStart()
    Dim lngshell As Long, lngstartbut As Long
    Let lngshell& = FindWindow("Shell_TrayWnd", vbNullString)
    Let lngstartbut& = FindWindowEx(lngshell&, 0, "Button", vbNullString)
    Call PostMessage(lngstartbut&, WM_LBUTTONDOWN, 0&, 0&)
    Call PostMessage(lngstartbut&, WM_LBUTTONUP, 0&, 0&)
    End Sub

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    yea, but after the start menu I want it to be able to goto
    Contorl Panel, and then goto Add/Remove software, then etc... I think that simulating a mouse click would be the best way to do this
    NXSupport - Your one-stop source for computer help

  6. #6
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    I don think so, navigating thru the Start menu is VERY easy by using the send keys command.
    When you have the start menu open, move the cursor to Settings then onto control panel and SendKey("C") C=whatever letter is underlined in "Control Panel"


    Gl,
    D!m

    PS. But i wouldn't ming knowing how to simulate a click

    [Edited by Dim on 07-30-2000 at 01:39 AM]
    Dim

  7. #7
    New Member
    Join Date
    Jul 2000
    Location
    São Paulo/Brazil
    Posts
    13

    Simulate a click

    Well, to simulate a click on a object is very easy.

    You need to use the SendMessage and send a message BM_SETSTATE to a handle. Here comes the problem that is the handle of the object that is the Start Menu (this I don't know).

    This is the code:

    Private Declare Function SendMessage Lib "user32" _
    Alias "SendMessageA" _
    (ByVal hwnd As Long, ByVal wMsg As Long, _
    ByVal wParam As Long, lParam As Any) As Long

    Private Sub Command1_Click()
    Call SendMessage(Me.Command2.hWnd, BM_SETSTATE, 1, ByVal 0&)
    End Sub

    Private Sub Command2_Click()
    Debug.Print "I was just clicked"
    End Sub

    -- end of code --

    But, if I understand what you need to do, is better to you use the commands from Windows:

    rundll32.exe shell32.dll,Control_RunDLL appwiz.cpl,,1
    rundll32.exe shell32.dll,Control_RunDLL sysdm.cpl,,0

    The first is for the Add/Remove Program and the second is for the System Icon.

    If you want, I have a demo project that I get on anywhere on internet that show all these Windows commands.

  8. #8
    New Member
    Join Date
    Jul 2000
    Location
    São Paulo/Brazil
    Posts
    13
    I only forget to declare the const BM_SETSTATE.

    Private Const BM_SETSTATE = &HF3

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    From what I understood, when someone clicks the button, the printer prints, "I was just clicked"

    maybe I'm wrong, becuase I didn't try it, or does it click at where the mouse cursur is set?
    NXSupport - Your one-stop source for computer help

  10. #10
    New Member
    Join Date
    Jul 2000
    Location
    São Paulo/Brazil
    Posts
    13
    The example of the message that I post is for when you have the handle of an object and you want to simulate a click on it.

    In this example, every time that you click on Command1, a message will be sent to the Command2 making a simulating of a click and, to show that it works, it will print a message in the Imediate Window.

    It will not work on the way you are trying to do 'cause it need of a handle.

    But, really try to run this command from the run dialog box on windows and you will see what comes:

    rundll32.exe shell32.dll,Control_RunDLL appwiz.cpl,,1

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    ok, what I'm trying to is make a tutorial program, and it shows you how to do it. I know its possilbe becuase in MS OFFICE when search for help, there is always a button taht says "Show me how" then Microsoft moves the mouse and click and shows you how to do it...


    So I know that its possible

    but then again Ms Office was made in VC++
    and after all Microsoft owns the mouse, and can
    control it in any way shape or form.

    I was also thinking of using Send Keys, to goto the start menu, control panel, etc. and just sorta moving the mouse at where the click thing should be, and then use send keys...

    I was also going to show them how to change there screen reselution through the Display thing in Controlo Panel, but ever video card has its own tabs and stuff so it will be kinda hard...

    If not I can give them a simple text with images thing

    hope that clears things up a bit


    if you have any idea how I can do this, please feel free to post them.
    NXSupport - Your one-stop source for computer help

  12. #12
    New Member
    Join Date
    Jan 1999
    Location
    UK
    Posts
    4

    Exclamation Use Lotus Screencam instead

    If you want to make a tutorial, get hold of Lotus Screen Cam. Ok it's old and they haven't made a new version lately, but it will record the on-screen actions and has the advantage that when the user plays them back they're watching a recording, it's not actually "doing it".

    It's like recording an AVI of what you are doing on screen, but you get much smaller files, you can save as an EXE too.

  13. #13
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Just click you say? You move the cursor with setcursorpos and then use mousedown and mouseup.
    Code:
    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)
    
    Sub MouseDown(Optional Left As Boolean = True, Optional Right As Boolean, Optional Middle As Boolean, Optional Click As Boolean)
        mouse_event -Left * 2 - Right * 8 - Middle * 32, 0&, 0&, 0&, 0&
        If Click Then mouse_event -Left * 4 - Right * 16 - Middle * 64, 0, 0, 0, 0
    End Sub
    Sub MouseUp(Optional Left As Boolean = True, Optional Right As Boolean, Optional Middle As Boolean)
        mouse_event -Left * 4 - Right * 16 - Middle * 64, 0, 0, 0, 0
    End Sub
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  14. #14

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    1 more question, in my code, how do I refer to the mouse thing?
    NXSupport - Your one-stop source for computer help

  15. #15
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    You mean how to use it?

    For a simple left click its;
    Code:
    MouseDown
    MouseUp
    By putting the optional booleans on you could specify which buttons you click
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  16. #16

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    ok, thanks, my head is a liitle slow today
    NXSupport - Your one-stop source for computer help

  17. #17

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    thanks alot, it works
    NXSupport - Your one-stop source for computer help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width