Results 1 to 8 of 8

Thread: [RESOLVED] emulate Mouse Click

  1. #1

    Thread Starter
    Lively Member Hojo's Avatar
    Join Date
    Jul 2005
    Location
    Brisbane, Australia
    Posts
    119

    Resolved [RESOLVED] emulate Mouse Click

    Hello All,

    Is there a way to code a mouse click. That is provoke the events that happen when you click on a control with out physically clicking on it.

    I have a toggle button that can be "toggled" by the user and the button indents when "on" and is proud when "off".

    If i code for the button to be pressed "togglebutton1_click()" then code executes but the button doesnt change its physical State.

    Thanks everyone

    Hojo
    Last edited by Hojo; Aug 9th, 2005 at 06:11 PM.
    Despite body and mind, my youth will never die!

    Everytime I learn something new it pushes some old stuff out of my brain!

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: emulate Mouse Click

    You can use a checkbox, set to graphical mode, that looks like a command button, but can be toggled.

  3. #3

    Thread Starter
    Lively Member Hojo's Avatar
    Join Date
    Jul 2005
    Location
    Brisbane, Australia
    Posts
    119

    Re: emulate Mouse Click

    David,

    I have a toggle button but want it to toggle without clicking on it with the mouse

    Hojo
    Despite body and mind, my youth will never die!

    Everytime I learn something new it pushes some old stuff out of my brain!

  4. #4

    Thread Starter
    Lively Member Hojo's Avatar
    Join Date
    Jul 2005
    Location
    Brisbane, Australia
    Posts
    119

    Re: emulate Mouse Click

    I'm thinking setting focus to control then somthing LIKE SendKeys but sending the left mouse button.

    eg.
    VB Code:
    1. Togglebutton1.setFocus
    2. Sendkeys (leftmousebutton) ' Whatever that would be

    Does this seem possible to anyone

    Hojo
    Despite body and mind, my youth will never die!

    Everytime I learn something new it pushes some old stuff out of my brain!

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: emulate Mouse Click

    Add a checkbox, and set its style to Graphical. Then add this to where you want to toggle it. (I am using a command button)

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.   Check1.Value = 1 - Check1.Value
    5. End Sub

  6. #6
    Fanatic Member
    Join Date
    Sep 2002
    Location
    Lexington, SC
    Posts
    586

    Re: emulate Mouse Click

    If you really want to emulate a mouse click...

    Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)

    See
    http://www.mentalis.org/apilist/mouse_event.shtml
    For further details and an example.

  7. #7

    Thread Starter
    Lively Member Hojo's Avatar
    Join Date
    Jul 2005
    Location
    Brisbane, Australia
    Posts
    119

    Re: emulate Mouse Click

    Thankyou David & Steven

    Sorry David, I didn't totally get what you were saying the first time but this works like a charm. Except i'll be using

    VB Code:
    1. Check1.value = 0 ' for off
    2.  
    3. 'Or
    4.  
    5. Check1.value = 1 ' for on
    Because that works better logically for this specific program.

    Thankyou also Steven for the simplicity of this program i won't used your method but its good to know for the future.

    Thanks again guys.

    Cheers Hojo
    Despite body and mind, my youth will never die!

    Everytime I learn something new it pushes some old stuff out of my brain!

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: [RESOLVED] emulate Mouse Click

    It's an old formula

    1 - 1 = 0
    1 - 0 = 1

    so

    1 - x = NOT X

    You can't use NOT Check.value as a checkbox can be -1, 0, or 1

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