Jump to content

Macro issue


Champak
 Share

Go to solution Solved by water,

Recommended Posts

I have a function that is called by a hotkey and onevent from a button and a combo box. In the function it looks for a specific button press with an IF condition by ways of the guicntrlID. If I hit the button, the function operates with no problem, if I then call the function with the hotkey any time after that there is no problem. The problem happens if I decide to access the function though the hotkey first before ever pressing the button. When I do that I get an error stating "unknown macro". This doesnt seem to make sense, Is this normal? What's the workaround?

Link to comment
Share on other sites

How should we know?

Give us more information! At least the source code!

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

In AutoIt macros are "variables" starting with @ like @Username. But Au3Check should post an error when it encounters an invalid macro before the script is started.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

i made this here, but it should work.

#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)


HotKeySet("1", "_test")

guicreate("gui",300,300)

$button = GUICtrlCreateButton("button",50,50,100,100)
GUICtrlSetOnEvent($button,"_test")


$exit = GUICtrlCreateButton("exit",200,50,50,50)
GUICtrlSetOnEvent($exit,"_exit")
GUISetState()

while 1
    Sleep(100)
WEnd

    Func _test()
        If @GUI_CtrlId + $button Then
            MsgBox(0,0,"keypress")
        Else
            MsgBox(0,0,"hotset")
        EndIf
    EndFunc
Func _exit()
    Exit
    EndFunc
Link to comment
Share on other sites

Shouldn't this line

If @GUI_CtrlId + $button Then

be

If @GUI_CtrlId = $button Then

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Champak,

From the Helpfile:

@GUI_CtrlId Last click GUI Control identifier. Only valid in an event Function. See the GUICtrlSetOnEvent() function

 

Apparently this is not set until a control is actioned.

Also, besides what water has pointed out, this

Else
            MsgBox(0,0,"hotset")

does not make sense as the script exits when the only other button is pressed.

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

It wasn't meant to make sense, just a quick extrapolation from memory of the overall situation to demonstrate. Now how do we fix this, because this doesn't make sense. What if I choose not to press the button. The macro should always be set once the app starts...in my opinion. Is there a way I can call/declare the macro on launch of the application without activating the function.

Link to comment
Share on other sites

Macros can not be set by a script - exceptions are @error and @extended which can be set by functions SetError and SetExtended.

I would let the hotkey call a different function. In this function set a variable e.g. $bHotKey = True and then call function _test. So you can tell if the button or the hotkey was pressed.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Thanks. Before I go the route of making another function, why can't I make a "SetMacro" function like the error functions. Where do I find that function to make changes to it if that's possible. Going the 2nd function route is going to create bloat in my app.

Link to comment
Share on other sites

  • Solution

My approach doesn't add too much code to your script:

Global $bHotKey = False
HotKeySet("1", "_TestHotKey")

Func _TestHotKey()
    $bHotKey = True
    _test()
EndFunc

Don't forget to reset $bHotKey when a button is pressed.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...