How to perform a control click?

  • Thread starter hurricane_number_one
  • Start date
H

hurricane_number_one

I tried this but it doesn't work

keybd_event(VK_CONTROL, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0)

Any idea how to do this?
 
R

rowe_newsgroups

I tried this but it doesn't work

keybd_event(VK_CONTROL, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0)

Any idea how to do this?

Are you trying to click one of your applications controls or something
else?

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/
 
P

Phill W.

I tried this but it doesn't work

keybd_event(VK_CONTROL, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0)

If it's a control in your own application, use

[<control>].PerformClick()

It has all the same restrictions as clicking it interactively - the
control has to be visible and enabled (as do all of its parent controls).

If it's a /different/ application, are you running Vista?
That puts some fairly rigid barriers between types of application,
preventing them from doing just this sort of thing.
Any idea how to do this?

No, but then I'm not familiar with these particular functions.
Take a step back; what is the end /result/ you're trying to achieve?

HTH,
Phill W.
 
H

hurricane_number_one

It's another program, this acts like a remote access app. I have no
problem with the clicks, but adding any modifiers don't do anything.
It must be possible, otherwise how would programs like VNC do it?

I tried this but it doesn't work
keybd_event(VK_CONTROL, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0)

If it's a control in your own application, use

[<control>].PerformClick()

It has all the same restrictions as clicking it interactively - the
control has to be visible and enabled (as do all of its parent controls).

If it's a /different/ application, are you running Vista?
That puts some fairly rigid barriers between types of application,
preventing them from doing just this sort of thing.
Any idea how to do this?

No, but then I'm not familiar with these particular functions.
Take a step back; what is the end /result/ you're trying to achieve?

HTH,
    Phill  W.
 
K

kimiraikkonen

It's another program, this acts like a remote access app. I have no
problem with the clicks, but adding any modifiers don't do anything.
It must be possible, otherwise how would programs like VNC do it?

If it's a control in your own application, use
[<control>].PerformClick()

It has all the same restrictions as clicking it interactively - the
control has to be visible and enabled (as do all of its parent controls).
If it's a /different/ application, are you running Vista?
That puts some fairly rigid barriers between types of application,
preventing them from doing just this sort of thing.
No, but then I'm not familiar with these particular functions.
Take a step back; what is the end /result/ you're trying to achieve?
HTH,
    Phill  W.

Hi,
If your VNC program accepts an action with modifier key combination
when it's first activated (got focus), just like on normal usage, you
can automate it using SendKeys.Send method based on that approach:

For example, send a CTRL+UP message
' First activate the VNC application
' You can pass its process ID
' or its title string
AppActivate("Welcome to VNC")

' Send CTRL+UP using CTRL modifier
SendKeys.Send("^{UP}")

....where caret (^) is your modifier, in that case, control key.

For more keys:
http://msdn.microsoft.com/en-us/library/8c6yea83(VS.85).aspx

Hope that approach makes some sense,

Onur Güzel
 
H

hurricane_number_one

I can do keys with modifiers. I'm looking to do a mouse click with
modifiers.


It's another program, this acts like a remote access app. I have no
problem with the clicks, but adding any modifiers don't do anything.
It must be possible, otherwise how would programs like VNC do it?
On Nov 19, 8:25 am, "Phill W." <[email protected]>
wrote:
(e-mail address removed) wrote:
I tried this but it doesn't work
keybd_event(VK_CONTROL, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0)
If it's a control in your own application, use
[<control>].PerformClick()
It has all the same restrictions as clicking it interactively - the
control has to be visible and enabled (as do all of its parent controls).
If it's a /different/ application, are you running Vista?
That puts some fairly rigid barriers between types of application,
preventing them from doing just this sort of thing.
Any idea how to do this?
No, but then I'm not familiar with these particular functions.
Take a step back; what is the end /result/ you're trying to achieve?
HTH,
    Phill  W.

Hi,
If your VNC program accepts an action with modifier key combination
when it's first activated (got focus), just like on normal usage, you
can automate it using SendKeys.Send method based on that approach:

For example, send a CTRL+UP message
' First activate the VNC application
' You can pass its process ID
' or its title string
AppActivate("Welcome to VNC")

' Send CTRL+UP using CTRL modifier
SendKeys.Send("^{UP}")

...where caret (^) is your modifier, in that case, control key.

For more keys:http://msdn.microsoft.com/en-us/library/8c6yea83(VS.85).aspx

Hope that approach makes some sense,

Onur Güzel
 
A

Andrew Morton

H

hurricane_number_one

Turns out, my code actually does work, just not in Firefox, which is
the program I was testing it with and the one I was hopefully aiming
to get this working for. I tried this in other browsers and it works
fine. I also tried your suggestion, and it performs a doubleclick but
doesn't do anything different than before. Any idea why this wouldn't
work in Firefox only?
Thanks.
 
A

Andrew Morton

Turns out, my code actually does work, just not in Firefox, which is
the program I was testing it with and the one I was hopefully aiming
to get this working for. I tried this in other browsers and it works
fine. I also tried your suggestion, and it performs a doubleclick but
doesn't do anything different than before. Any idea why this wouldn't
work in Firefox only?

It could be that FF thinks something else is in focus (like a blank area).
What if you manually click on the element in question before running your
code?

Andrew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top