Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Function won't work when hotkey calls it



  • Please log in to reply
3 replies to this topic
Azevedo
  • Members
  • 179 posts
  • Last active: Nov 04 2015 04:37 PM
  • Joined: 07 Mar 2012

Can someone tell me why this function won't retrieve the contents of txt_search if called from a hotkey?

Search()
{
        Global
        
        GuiControlGet, txt_search
        msgbox % txt_search
}

; this won't work: txt_search returns blank
    Enter::Search()

; this works: returns txt_search 
  Search()


Shadowpheonix
  • Members
  • 268 posts
  • Last active:
  • Joined: 10 Feb 2014

When placing anything on the same line after the ::, it becomes a key remap instead of a hotkey.  To have the hotkey actually perform an action (such as run your function), the command needs to be on a separate line, and then you must end the hotkey with a Return commend.  In other words, instead of Enter::Search(), use...

Enter::
Search()
Return


Azevedo
  • Members
  • 179 posts
  • Last active: Nov 04 2015 04:37 PM
  • Joined: 07 Mar 2012

Still.

I put in the same line because I'm using #if

#if (WinActive("MyAppTitle") == MAIN_HWND )
        Enter::Search()
#if

The function is called but it only retrives GuiControlGet, txt_search if I make a plain call

Search()

otherwise the function is called but can't get the contents of txt_search

 

from

Gui, Add, Edit, vtxt_search


Azevedo
  • Members
  • 179 posts
  • Last active: Nov 04 2015 04:37 PM
  • Joined: 07 Mar 2012
✓  Best Answer

Found the solution:

the function called by hotkey must have Gui, MAIN_WINDOW:Submit, NoHide

Search(){
 Global

        Gui, MAIN_WINDOW:Submit, NoHide       
        GuiControlGet, txt_search
        msgbox % txt_search
}

Enter::Search()

very tricky!! they should fill the documentation with more information...