12 Replies - 7334 Views - Last Post: 07 January 2011 - 05:48 AM Rate Topic: -----

#1 Guest_khwathie*


Reputation:

VB6 Left Mouse Click

Posted 06 January 2011 - 01:43 AM

Good day,

How do I click the radio button programmatically without clicking the physical mouse? My intention is that, the application should do that automatically without me touching anything.

So can any body give some suggestion regarding this?

Your help will be highly appreciated

Regards,
Is This A Good Question/Topic? 0

Replies To: VB6 Left Mouse Click

#2 sas1ni69  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 85
  • View blog
  • Posts: 431
  • Joined: 04-December 08

Re: VB6 Left Mouse Click

Posted 06 January 2011 - 03:11 AM

Do you mean that you want the value to change when you click on something else? What are you trying to accomplish exactly?

Maybe you can try
option1.value = 0
when you click another button. You can set it from the code.
Was This Post Helpful? 0
  • +
  • -

#3 Guest_khwathie*


Reputation:

Re: VB6 Left Mouse Click

Posted 06 January 2011 - 04:54 AM

I don't want to change any value.

I have 2 radio buttons , one selected by default and one not. The one selected by default is the one I which am interested in. All I want to do is the activate " Mouse Left click" programatically without pressing any mouse button by my fingers.

So how can i do it?

I have tried this code but it's not working
</Public Sub LeftClick()
' SetCursorPos(500, 500)
LeftDown()
System.Threading.Thread.Sleep(100)
LeftUp()
End Sub

Public Sub LeftDown()
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
End Sub

Public Sub LeftUp()
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
End Sub>

and on the declaration I have put this code

</Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4>

Please assist.
Was This Post Helpful? 0

#4 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 299
  • View blog
  • Posts: 1,768
  • Joined: 26-March 09

Re: VB6 Left Mouse Click

Posted 06 January 2011 - 06:45 AM

You might want to ask a mod to move this post to the .NET forum as it doesn't appear to be VB6.

You may get more success there.
Was This Post Helpful? 0
  • +
  • -

#5 sas1ni69  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 85
  • View blog
  • Posts: 431
  • Joined: 04-December 08

Re: VB6 Left Mouse Click

Posted 06 January 2011 - 07:07 AM

What version of VB are you using? I think maj3091 is right.
Was This Post Helpful? 0
  • +
  • -

#6 Guest_khwathie*


Reputation:

Re: VB6 Left Mouse Click

Posted 07 January 2011 - 12:15 AM

I am sorry, it's my mistake. I have pasted the wrong code, just that I am trying to find a solution on both VB6 and .net. I am calling VB6 application from .NET so if I find a solution in either one of them I will be grateful.

Thanks,
Was This Post Helpful? 0

#7 Guest_khwathie*


Reputation:

Re: VB6 Left Mouse Click

Posted 07 January 2011 - 12:15 AM

I am sorry, it's my mistake. I have pasted the wrong code, just that I am trying to find a solution on both VB6 and .net. I am calling VB6 application from .NET so if I find a solution in either one of them I will be grateful.

Thanks,
Was This Post Helpful? 0

#8 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: VB6 Left Mouse Click

Posted 07 January 2011 - 02:34 AM

Ok, whatever vb version do you use, you have to be clear what you want. If you want to simulate left click, it's just an event call, but a left click may be pushed anywhere on your form. If you a left click on radio button, that means sas1ni69 gave you the answer. You don't have to simulate every step, it's enough to manipulate the objects by your code.
This are the value which your program starts with
 
optionButton1.Value = true
optionButton2.Value = false



So, make the next test to see what happens. Put a button on your form, on click event, put the following code
    System.Threading.Thread.Sleep(100)
    optionButton1.Value = false 
    optionButton2.Value = true


Run the project and click on the button. The radio buttons should change their values programatically.

Ionut

This post has been edited by Ionut: 07 January 2011 - 02:36 AM

Was This Post Helpful? 0
  • +
  • -

#9 Guest_khwathie*


Reputation:

Re: VB6 Left Mouse Click

Posted 07 January 2011 - 02:51 AM

I understand what you are saying but all I want to do is to simulate mouse left click programatically without me touching the mouse.

As soon as I open the form with 2 Radio buttons on it, the application must click the 1st radio button automatically and that's can only be done by clicking on the mouse.

or is there any other way of doing it by using the Keyboard?
Was This Post Helpful? 0

#10 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 299
  • View blog
  • Posts: 1,768
  • Joined: 26-March 09

Re: VB6 Left Mouse Click

Posted 07 January 2011 - 04:10 AM

Your question is still really confusing and you've been given some valid answers already, but you still say it's not what you want.

OK, a couple of questions.

Are you using a control array of option buttons?
What code do you have in the Option_Click event that you need to execute?

The example below assumes you're using a control array of 2 option buttons indexed 0 to 1 named optButton.

You can call the click event in code by optButton_Click(index) where index is the button you want to simulate clicking on.

You should be aware, that calling the click event in code, does not appear to change the value state of the button, so if 0 is shown as selected and you call click event on 1, it will still show 0 as selected, so you need to handle that in the click event code itself.
Was This Post Helpful? 0
  • +
  • -

#11 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,606
  • Joined: 17-April 07

Re: VB6 Left Mouse Click

Posted 07 January 2011 - 04:48 AM

yes there's a way
after the form is visible
set the focus to the optionbutton and then
and then send the rightwindowkey down that's all
here is a link, how to use the right window key Send Key list

This post has been edited by thava: 07 January 2011 - 04:49 AM

Was This Post Helpful? 0
  • +
  • -

#12 Guest_khwathie*


Reputation:

Re: VB6 Left Mouse Click

Posted 07 January 2011 - 05:28 AM

The optionButton is already set to default, the only thing left is to click on it using a code.

I did tried this code but it is not working.

send ("{RWIN}"). Or is there anything I've done wrong?
Was This Post Helpful? 0

#13 Guest_khwathie*


Reputation:

Re: VB6 Left Mouse Click

Posted 07 January 2011 - 05:48 AM

Yes, I am using a control array of option buttons.

Here is the code I have:
</Private Sub optControl_Click(nIndex As Integer)
On Error GoTo EHfrmImport_optControl_Click
Dim fEnable As Boolean
Dim nCnt As Integer
If Not fOptionclicked Then Exit Sub
Select Case nIndex
Case 0
fEnable = False
send ("{RWIN}")
Case 1
fEnable = True
End Select
For nCnt = 0 To 5
optRejReason(nCnt).Enabled = fEnable
optRejReason(nCnt).Value = False
Next nCnt
fraReject.Enabled = fEnable
If nIndex = 0 Then CreateBatchReadFile
fOptionclicked = False

Exit Sub
EHfrmImport_optControl_Click:
frmUserLogin.ThrowException Err.Number, "frmImport.optControl_Click()"
Resume
End Sub>
Was This Post Helpful? 0

Page 1 of 1