AutoHotkey Community

It is currently May 27th, 2012, 1:21 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: August 18th, 2008, 1:04 am 
Offline

Joined: August 16th, 2008, 11:08 pm
Posts: 40
I wrote a simple script:
Code:
#IfWinActive,1058539: MetaTrader
Numpad0::
   ControlClick,Button8,1058539: MetaTrader  ; this line fails sometimes
   #Persistent
   ToolTip, hotkey pressed... ,500,200  ; but this line works EVERYTIME
   SetTimer, RemoveToolTip, 3000
   return

   RemoveToolTip:
   SetTimer, RemoveToolTip, Off
   ToolTip
   return
Return



Please look at notes in the script. "Button8" is the classNN of that button.
Any idea?

Thanks.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 18th, 2008, 5:27 am 
Offline

Joined: June 26th, 2008, 3:58 am
Posts: 56
Try this. I have no idea if it will work, I just cleaned up the syntax and formatting
Code:
#IfWinActive,1058539: MetaTrader

Numpad0::
   ControlClick,Button8,1058539: MetaTrader  ; this line fails sometimes
   ToolTip, hotkey pressed... ,500,200  ; but this line works EVERYTIME
   SetTimer, RemoveToolTip, -3000
   return

RemoveToolTip:
   ToolTip
   return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 18th, 2008, 9:24 am 
Offline

Joined: April 18th, 2008, 7:57 am
Posts: 1390
Location: The Interwebs
Try changing the line to:
Code:
ControlClick,Button8,1058539: MetaTrader,,,,D ;sends a mouse down event
Sleep 100 ;change around a bit, it is milliseconds between down and up
ControlClick,Button8,1058539: MetaTrader,,,,U ;sends a mouse down event

The problem might be that AHK is sending the click too fast, so sometimes it doesn't receive it. This will fix it, if that is the problem.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 18th, 2008, 10:17 am 
Quote:
SetControlDelay
--------------------------------------------------------------------------------
Sets the delay that will occur after each control-modifying command.

SetControlDelay, Delay

8)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 18th, 2008, 10:28 am 
Offline

Joined: April 18th, 2008, 7:57 am
Posts: 1390
Location: The Interwebs
Whoops—got this confused with a MouseMoveDrag command I was giving help with. Thanks for pointing that out, Bobo².


By the way, to make what Bobo² put a little clearer, make your code look like this:
Code:
#IfWinActive,1058539: MetaTrader

Numpad0::
   SetControlDelay, -1 ;first try out -1, then I would suggest 50
   ControlClick,Button8,1058539: MetaTrader  ; this line fails sometimes
   ToolTip, hotkey pressed... ,500,200  ; but this line works EVERYTIME
   SetTimer, RemoveToolTip, -3000
   return

RemoveToolTip:
   ToolTip
   return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 18th, 2008, 11:52 am 
Offline

Joined: June 16th, 2008, 12:26 pm
Posts: 82
Location: Pittsburgh, Pennsylvania, USA
I too have found ControlClick to be unreliable. Instead, I use ControlSend with a space.
Try:
Code:
ControlSend, Button8, {Space}, 1058539: MetaTrader


Hasn't failed me yet.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 18th, 2008, 12:42 pm 
Offline

Joined: August 16th, 2008, 11:08 pm
Posts: 40
Thanks. It's better....


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 19th, 2008, 11:34 am 
trenton_xavier..

Why do you use the {SPACE} in the example you gave?

Regards


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 19th, 2008, 12:26 pm 
Offline

Joined: June 16th, 2008, 12:26 pm
Posts: 82
Location: Pittsburgh, Pennsylvania, USA
Because if you use {enter} it will activate the default button in the control.

Try it. Open any gui... say right click on the taskbar and go to Properties. Now tab to any of the controls, lets say "Show the Clock" checkbox. If you send or press Enter, it actually sends it to the OK button on the bottom, because thats the default button for that group. Now if you use space, it toggles that check box.

Get it?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 19th, 2008, 2:30 pm 
Offline

Joined: July 21st, 2008, 4:16 pm
Posts: 726
Location: Calgary, AB, Canada
Same way I use it. Only difference is I always use it in a loop that checks if the window still exists, just to make sure it works. Even ControlSend using space can be fickle at times.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 20th, 2008, 2:25 am 
Offline

Joined: August 16th, 2008, 11:08 pm
Posts: 40
Thanks guys, I learned a lot from this.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: August 19th, 2011, 3:34 am 
Offline

Joined: March 3rd, 2005, 5:43 am
Posts: 62
Basically, it's just a Loop that sends a Control Click
and waits 100ms to see if the Window becomes active
that a successful ControlClick is supposed to produce.
If ControlClick was successful, a "Break" is executed
to exit the Loop and the script continues. If the active
Window has not changed to the one solicited by the
ControlClick, it's assumed that the ControlClick command
wasn't recognized and the Loop repeats sending it again.
This has worked successfully for me. It's not a fix for
unreliable ControlClick operations, but it is a workaround.

Code:
SetControlDelay, 100
id := WinExist("A")
Loop, 10
{
; You will need to change the x & y Screen Locations for Your Control

ControlClick, x1128 y815, ahk_id %id%,,,, Pos

sleep, 100

; You will also need to provide the Windows Title in %NextDialog%
; It should be the Window Title of the active Window that the
; ControlClick Operation above is supposed to produce.

IfWinActive, %NextDialog%
   break
}

; Script Continues
; ..
; ...
; ....
; .....
; etc


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, chaosad, oldbrother and 18 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group