AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

hotkey doesn't wait for click

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
bartp



Joined: 14 Feb 2008
Posts: 12

PostPosted: Wed May 21, 2008 12:56 pm    Post subject: hotkey doesn't wait for click Reply with quote

Hi!

In a particular window1 (not a ahk_gui) i want to check if a user clicks either button1 or button2. I found this script to do just that:

Code:

; this enables the hotkey - i.e. "begins waiting for LButton"
Hotkey, LButton, left_button, On

;...

left_button:  ; <-- this is a regular label
    MouseGetPos, , , mWin, mCont
    ; WinExist may be used to check that mWin is the correct window.
    if WinExist (mWin = "Window1") AND (mCont = "ATL:312324D815") ;assuming btnNew contains the button's ClassNN
    {
        MsgBox clicked the button.
    }
    else  ; let the user click stuff
    {
        Click down
        KeyWait, LButton
        Click up
    }
return

got this from this topic:

http://www.autohotkey.com/forum/viewtopic.php?t=26096&start=0&postdays=0&postorder=asc&highlight=check

This works, however when I want to do this in the middle of another script, it doesn't work anymore. It just fires the MsgBox, without having clicked the leftmousebutton.

This is my script:

Code:

Gui, +AlwaysOnTop
Gui, Font, S14 CDefault Bold, Verdana
Gui, Add, Edit, x6 y7 w150 h30 vOrdernr
Gui, Add, Button, default x166 y7 w100 h30 , GO!
;Generated using SmartGUI Creator 4.0
Gui, Show, x242 y127 h45 w270, Facturen afdrukken
WinSet, AlwaysOnTop, On, Facturen afdrukken
Return

F7::
IfWinExist, Facturen afdrukken
WinHide
Else
WinShow, Facturen afdrukken
return

ButtonGO!:
Gui, Submit, NoHide
WinWait, 921 Leveringen - Exact Globe - 253144:175:001 (Netherlands),
IfWinNotActive, 921 Leveringen - Exact Globe - 253144:175:001 (Netherlands), , WinActivate, 921 Leveringen - Exact Globe - 253144:175:001 (Netherlands),
WinWaitActive, 921 Leveringen - Exact Globe - 253144:175:001 (Netherlands),
ControlSetText, FipEdit6, %Ordernr%, 921 Leveringen - Exact Globe - 253144:175:001 (Netherlands)
Sleep, 100
ControlClick, &Actualiseren
Sleep, 800
PixelSearch, , ,258, 424, 293, 431, 0x000000, 3, Fast
if ErrorLevel
{
MsgBox, Order %Ordernr% is niet gevonden
exit
}
else
MouseClick, left, 414, 426
Sleep, 100
ControlClick, &Leveringen, 921 Leveringen - Exact Globe - 253144:175:001 (Netherlands)
Sleep, 500
IfWinExist, Vraag
ControlClick, &Ja, Vraag
Sleep, 100
WinWait, 921 Leveringen - Exact,
IfWinNotActive, 921 Leveringen - Exact, , WinActivate, 921 Leveringen - Exact,
WinWaitActive, 921 Leveringen - Exact,
Sleep, 3000

ControlGetText, test, FipEdit2, 921 Leveringen - Exact
Sleep, 100
ControlSetText, FipEdit2, , 921 Leveringen - Exact
Sleep, 100

; this enables the hotkey - i.e. "begins waiting for LButton"
Hotkey, IfWinActive, 921 Leveringen - Exact
Hotkey, LButton, left_button

left_button:  ; <-- this is a regular label
MouseGetPos, , , mWin, mCont
MsgBox, %mCont% ;for testing purposes

    ; WinExist may be used to check that mWin is the correct window.
    if mCont = "ATL:312324D815"  ; mCont = Annuleren
    {
        MsgBox You CLICKED Annuleren
    }
    else  ; let the user click stuff
    {
        Click down
        KeyWait, LButton
        Click up
     }

; rest of script....


Without clicking leftmousebutton it shows MsgBox %mCont%, where mCont is a variable of a control where i hover over with my mouse at that time. While it should show the msgbox when i clicked a control myself.

Can somebody help me please! Embarassed
Back to top
View user's profile Send private message
Extreminador



Joined: 05 May 2008
Posts: 22

PostPosted: Wed May 21, 2008 1:02 pm    Post subject: Reply with quote

Code:

; this enables the hotkey - i.e. "begins waiting for LButton"
Hotkey, LButton, left_button, On


The HotKey dosenīt wait for any thing , the only thing that HotKey does is:

Creates, modifies, enables, or disables a like is saying on help.

Id you want to wait for any key pressed you need to use the command KeyWait

Code:

KeyWait, LButton, D
Back to top
View user's profile Send private message
bartp



Joined: 14 Feb 2008
Posts: 12

PostPosted: Wed May 21, 2008 1:42 pm    Post subject: Reply with quote

ok, but problem is that the user may click anywhere anytime, but if he clicks that specific button in that specific window the script must continue else stop the script. In the first scipt it does that. i can click everywhere in the window and nothing happens, but if i click on the button it continues the script, just like i want to. But is does not do that in the second script. Confused
Back to top
View user's profile Send private message
Extreminador



Joined: 05 May 2008
Posts: 22

PostPosted: Wed May 21, 2008 2:11 pm    Post subject: Reply with quote

that is not any problem you need to use a if command.
Check the example that you have on the command GetKeyState.
Back to top
View user's profile Send private message
bartp



Joined: 14 Feb 2008
Posts: 12

PostPosted: Wed May 21, 2008 3:24 pm    Post subject: Reply with quote

you say that the Hotkey command does not wait for anything, but how do you explain that this does wait for the leftbutton to be clicked:
Code:

; this enables the hotkey - i.e. "begins waiting for LButton"
Hotkey, LButton, left_button, On


this works in the standalone script.

I'm not familiar with GetKeyState. But will check it out and search for examples in the forum
Back to top
View user's profile Send private message
Superfraggle



Joined: 02 Nov 2004
Posts: 970
Location: London, UK

PostPosted: Wed May 21, 2008 4:14 pm    Post subject: Reply with quote

Place a return after the hotkey command otherwise program flow will continue past the label and execute the command which would normally execute on the click.
_________________
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle
Back to top
View user's profile Send private message MSN Messenger
Extreminador



Joined: 05 May 2008
Posts: 22

PostPosted: Wed May 21, 2008 4:47 pm    Post subject: Reply with quote

Code:

;Execute the label Up_Button when you click on the UP button arrow
Hotkey, Up, Up_Button, On
;Execute the label Down_Button when you clikc on the DOWN button arrow
Hotkey, Down, Down_Button, On
;The rest off the scriot will only run when you presse the Left Button arrow and it will only run once unless you have a #persistent on the beguining
KeyWait, Left, D
MsgBox, 0, Waiting pressed button, I appears becouse you have pressed the Left button arrow, 2
return

Up_Button: 
MsgBox, 0, Checking pressed button, You press the UP button arrow, 2
return

Down_Button: 
MsgBox, 0, Checking pressed button, You press the DOWN button arrow, 2
return
Back to top
View user's profile Send private message
bartp



Joined: 14 Feb 2008
Posts: 12

PostPosted: Thu May 22, 2008 10:17 am    Post subject: Reply with quote

Superfraggle wrote:
Place a return after the hotkey command otherwise program flow will continue past the label and execute the command which would normally execute on the click.


that was it! thank you!

Extreminador, thank you too but that didn't work out for me.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group