Jump to content

Troubleshooting HotKeySet


litlmike
 Share

Recommended Posts

Problem

When the script is run as a stand-alone, it works great. When I #include the script in my larger script, and try to call the function (HotKeySet ("+!h", "GUI_Email_to_ACT")), nothing happens. It is as if I never pressed the hotkey. This has happened once before, with another script, and I never figured it out. I must have 25 Hotkey Sets that I use daily and they normally work just fine. Any suggestions?

Additional Info

1) All my other HotKeySets still work, even though this one won't call.

2) This is a script that I #include in another script. (my Parent script)

3) Scite reports no errors.

4) Changing the HotKey does not work.

5) The 'Parent' Script uses #include <GuiConstants.au3>

6) When I #include this file in the 'Parent' script, I remove the

While 1 
    Sleep (100)
WEndoÝ÷ Ù8ZKojwjëh×6HotKeySet ("+!h", "GUI_Email_to_ACT")

While 1 
    Sleep (100)
WEnd

Func GUI_Email_to_ACT()
    
$Form1 = GUICreate("Enter Your Email Body", 545, 408, 193, 115)
Global $Edit1 = GUICtrlCreateEdit("", 8, 8, 529, 353)

$Button1 = GUICtrlCreateButton("Done", 216, 360, 121, 33, 0)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Paste_Email_ACT ()
    EndSwitch
WEnd

EndFunc

Func Paste_Email_ACT ()
    Global $Edit1_Value = GUICtrlRead ($Edit1)
    Activate_ACT()
    Click_Insert_Button()
    Sleep (3000)
    Paste_Email_Notes_History()
    Beep (440, 100)
EndFunc

Func Click_Insert_Button()
ControlClick ("ACT! -", "Insert Note", "Button21")
EndFunc

Func Paste_Email_Notes_History()
    ClipPut ($Edit1_Value)
    Send ($Edit1_Value)
EndFunc

Func Activate_ACT()
Opt("WinTitleMatchMode",1)
$title = WinGetTitle("")
;ToolTip ($title)
;Opt("WinTitleMatchMode",4)
WinWait("ACT!","")
If Not WinActive("ACT!","") Then WinActivate("ACT!","")
WinWaitActive("ACT!","")
;Return
EndFunc
Edited by litlmike
Link to comment
Share on other sites

  • Moderators

SciTe tells you your errors, this works:

#include <guiconstants.au3>
HotKeySet ("+!h", "GUI_Email_to_ACT")
Global $Edit1, $Edit1_Value
While 1
    Sleep (100)
WEnd

Func GUI_Email_to_ACT()
   
$Form1 = GUICreate("Enter Your Email Body", 545, 408, 193, 115)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 529, 353)

$Button1 = GUICtrlCreateButton("Done", 216, 360, 121, 33, 0)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Paste_Email_ACT ()
    EndSwitch
WEnd

EndFunc

Func Paste_Email_ACT ()
    $Edit1_Value = GUICtrlRead ($Edit1)
    Activate_ACT()
    Click_Insert_Button()
    Sleep (3000)
    Paste_Email_Notes_History()
    Beep (440, 100)
EndFunc

Func Click_Insert_Button()
ControlClick ("ACT! -", "Insert Note", "Button21")
EndFunc

Func Paste_Email_Notes_History()
    ClipPut ($Edit1_Value)
    Send ($Edit1_Value)
EndFunc

Func Activate_ACT()
Opt("WinTitleMatchMode",1)
$title = WinGetTitle("")
;ToolTip ($title)
;Opt("WinTitleMatchMode",4)
WinWait("ACT!","")
If Not WinActive("ACT!","") Then WinActivate("ACT!","")
WinWaitActive("ACT!","")
;Return
EndFunc
Are you supposed to declare Global Vars in a function?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

SciTe tells you your errors, this works:Are you supposed to declare Global Vars in a function?

THanks Smoke for always being so helpful. You are right about the Global Vars, I should have declared them outside of the function. However, I still cannot get the script to call that function. Scite does not report any errors to me, nor does the script close down. It just seems like I never pressed the Hotkey.

Any suggestions?

Link to comment
Share on other sites

Weird. And you don't get the error msgbox when you run the script? And you're pressing SHIFT+ALT+H, all at the same time? (sorry, just trying everything that could go wrong.)

If Include GUIConstants.au3, your script works just fine for me.

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Link to comment
Share on other sites

Weird. And you don't get the error msgbox when you run the script? And you're pressing SHIFT+ALT+H, all at the same time? (sorry, just trying everything that could go wrong.)

If Include GUIConstants.au3, your script works just fine for me.

Its okay to ask the obvious questions, sometimes it is the obvious that we overlook.

1) I do NOT get the msgbox when I run the script

2) I do NOT get the msgbox when I press the HotKey SHIFT+ALT+H (at the same time)

3) GUIConstants.au3 is #included in my 'Parent' script.

4) This script is #included in my 'Parent' script also.

This is really seeming to stump everyone. I don't feel as bad now. Any suggestions?

Link to comment
Share on other sites

  • Moderators

Is there a limit to how many HotKeySets can be compiled?

Remarks

Up to 64 simultaneous hotkeys per script may be registered.

:)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Does anyone know of a Script that can make a directory list of my .au3's, and read the .au3's to tell me what HotKeys are defined?

I did a search but didn't come up with anything like that. Is there a command to 'read' a .au3, without opening it?

An .au3 file is just a plain text file. You can read it to an array or one line at a time and just select the lines that contain "HotKeySet". Nothing special to it.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • Moderators

Here, in the midst of argueing with my wife... (she went and got the divorce papers :) )

Opt('GUIResizeMode', 802)
$MainGUI = GUICreate('Key Get Text', 230, 400)
_GUIResize($MainGUI, 100)
$BDir = GUICtrlCreateButton('Directory Search', 10, 20, 100, 30)
$BFile = GUICtrlCreateButton('File Search', 120, 20, 100, 30)
$Edit = GUICtrlCreateEdit('', 10, 80, 210, 300)
GUISetState()
While 1
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $BDir
            GUICtrlSetData($Edit, '')
            _GUIResize($MainGUI, 100)
            $hD = FileSelectFolder('Choose a Directory', @HomeDrive)
            If Not @error Then
                $sHotkey = _DirGetText($hD)
                If Not @error Then
                    GUICtrlSetData($Edit, StringReplace($sHotkey, @LF, @CRLF))
                    _GUIResize($MainGUI, 430)
                Else
                    MsgBox(64, 'Error', 'No Hotkeys found')
                EndIf
            EndIf
        Case $BFile
            GUICtrlSetData($Edit, '')
            _GUIResize($MainGUI, 100)
            $hFile = FileOpenDialog('Check Au3 for HotKeySet', @ScriptDir, 'Au3 (*.au3)')
            If Not @error Then
                $sHotkey = _KeyWordGetText($hFile, 'hotkeyset', 1)
                If Not @error Then
                    Local $sHold
                    For $iCC = 1 To $sHotkey[0]
                        If Not StringInStr(@LF & $sHold, @LF & $sHotkey[$iCC] & @LF) Then
                            $sHold &= $sHotkey[$iCC] & @LF
                        EndIf
                    Next
                    GUICtrlSetData($Edit, StringReplace($sHold, @LF, @CRLF))
                    _GUIResize($MainGUI, 430)
                Else
                    MsgBox(64, 'Error', 'No Hotkeys found')
                EndIf
            EndIf
    EndSwitch
WEnd

Func _DirGetText($hDir)
    Local $aSplit = StringSplit(StringStripCR(_DirRecurse($hDir)), @LF)
    Local $sHold, $sText
    For $iCC = 1 To $aSplit[0]
        If StringRight($aSplit[$iCC], 4) = '.au3' Then
            $sText = _KeyWordGetText($aSplit[$iCC], 'hotkeyset', 1)
            For $xCC = 1 To UBound($sText) - 1
                If Not StringInStr(@LF & $sHold, @LF & $sText[$xCC] & @LF) Then
                    $sHold &= $sText[$xCC] & @LF
                EndIf
            Next
        EndIf
    Next
    If Not $sHold Then Return SetError(1, 0, 0)
    Return $sHold
EndFunc

Func _KeyWordGetText($sString, $sText, $iArray = False)
    Local $sHold
    If FileExists($sString) Then
        $sString = FileRead($sString)
    EndIf
    $sString = StringStripWS($sString, 8)
    While StringLen($sString) > 0
        $sDQ = StringInStr($sString, $sText & '("')
        $sSQ = StringInStr($sString, $sText & "('")
        If Not $sDQ And Not $sSQ Then ExitLoop
        If $sSQ And ($sDQ > $sSQ Or $sDQ = 0) Then
            $sString = StringTrimLeft($sString, $sSQ + (StringLen($sText) + 1))
            $sSQ = StringInStr($sString, "'")
            $sHold &= StringLeft($sString, $sSQ - 1) & @LF
        Else
            $sString = StringTrimLeft($sString, $sDQ + (StringLen($sText) + 1))
            $sDQ = StringInStr($sString, '"')
            $sHold &= StringLeft($sString, $sDQ - 1) & @LF
        EndIf
    WEnd
    If Not $sHold Then Return SetError(1, 0, 0)
    If $iArray Then Return StringSplit(StringTrimRight($sHold, 1), @LF)
    Return $sHold
EndFunc

Func _DirRecurse($hDirectory)
    RunWait(@Comspec & ' /c dir /b /s /a "' & $hDirectory & '" > "' & _
        @TempDir & '\RecursiveOutput.txt"', @WorkingDir, @SW_HIDE)
    If Not FileExists(@TempDir & '\RecursiveOutput.txt') Then Return SetError(1, 0, 0)
    Local $sFRead = FileRead(@TempDir & '\RecursiveOutput.txt')
    FileDelete(@TempDir & '\RecursiveOutput.txt')
    Return $sFRead
EndFunc

Func _GUIResize($hWnd, $iHeight)
    Local $aWPos = WinGetPos(HWnd($hWnd))
    If Not IsArray($aWPos) Then Return SetError(1, 0, 0)
    WinMove(HWnd($hWnd), '', $aWPos[0], $aWPos[1], $aWPos[2], $iHeight)
    Return 1
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Here, in the midst of argueing with my wife... (she went and got the divorce papers :P )

Oh man, you are awesome, sorry I didn't see this post earlier. Sorry to hear about your wife, that sux man. Wish I could write a Script to fix it. :)

Well, according to Smoke's script, I have 43 HotKeySets declared, so I should be in the clear on running the limit. So any ideas why I can't call some of these HotKeys?

Link to comment
Share on other sites

when you use the hotkeyset command, is it in the main script, and is the function it references in the child script? I suspect you have the hotkeyset command in the child script, and it isn't getting ran, so the keys won't work.

I always put the HotKeySets in the child script, and so far they have always worked, if I shouldn't use this as a practice, I can certainly change it. However, I tried putting the HotKeySet in the parent script and it still will not activate.

Any other suggestions?

Link to comment
Share on other sites

  • Moderators

I always put the HotKeySets in the child script, and so far they have always worked, if I shouldn't use this as a practice, I can certainly change it. However, I tried putting the HotKeySet in the parent script and it still will not activate.

Any other suggestions?

2 things come to mind here.

1. Remember that once a script starts, it registers the hotkey so to speak. Meaning, if you had 2 scripts with the same hotkey, only the first one executed is going to work with that hotkey. (I think I've proven this to myself before :) )

2. Are you 100% positive the hotkeys you are using are not being used by any other currently running applications?

Now this brings the closing... You've been here long enough to know that all we can do from this point is speculate. You've given no re-creation of the issue you are having, I'd suggest you try that mode if it isn't working for you still.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

2 things come to mind here.

1. Remember that once a script starts, it registers the hotkey so to speak. Meaning, if you had 2 scripts with the same hotkey, only the first one executed is going to work with that hotkey. (I think I've proven this to myself before :) )

2. Are you 100% positive the hotkeys you are using are not being used by any other currently running applications?

Now this brings the closing... You've been here long enough to know that all we can do from this point is speculate. You've given no re-creation of the issue you are having, I'd suggest you try that mode if it isn't working for you still.

Thanks again for the feedback.

Am I 100% sure? Well I think that I am, but I know that I have overlooked the simple things before. Here is what a I did:

1) Found a HotKeySet that I know works 100% of the time

2) Reassigned it to the one Function that I can't call.

3) Also, made the function just a MsgBox MsgBox ("4096", "Success!","Success!", 5)

Result:

Still nothing! I am going nuts here.

Is there a limit on the amount of #includes in a script? Number of Func ? I have made my scripts very modular, and so many functions have there own .au3.

Link to comment
Share on other sites

  • Moderators

Thanks again for the feedback.

Am I 100% sure? Well I think that I am, but I know that I have overlooked the simple things before. Here is what a I did:

1) Found a HotKeySet that I know works 100% of the time

2) Reassigned it to the one Function that I can't call.

3) Also, made the function just a MsgBox MsgBox ("4096", "Success!","Success!", 5)

Result:

Still nothing! I am going nuts here.

Is there a limit on the amount of #includes in a script? Number of Func ? I have made my scripts very modular, and so many functions have there own .au3.

So we are going to start the guessing game? Why must the question always be asked of where is the script that has the issue... Personally I find it a waiste of time to just guess at things, then you read it, and hours later you respond whether it works or not, when it doesn't, the process starts again...

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

So we are going to start the guessing game? Why must the question always be asked of where is the script that has the issue... Personally I find it a waiste of time to just guess at things, then you read it, and hours later you respond whether it works or not, when it doesn't, the process starts again...

Oh sorry, I didn't understand what you meant earlier about providing the script. Sorry to be a bother to you as well, its not my intention to be a burden on these forums.

The reason I haven't included the script already, is because it has a lot of sensitive material related to work. Passwords, URLs, etc. I'll see if I can make a dummy version of the script without the sensitive info. It will take some time to go through all the scripts.

Thanks Again.

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...