EmilyLove Posted August 12, 2015 Posted August 12, 2015 (edited) I can set multiple hotkeys to a single function and it works on the first hotkey I press only. If I try to use one of the other bound hotkeys to activate the same function afterwards, it fails. Using the same key still works tho. I'm unsure how to fix this, since autoit is telling me there is no error. I want to get all the hotkeys working properly. It may also help if I knew what Hotkeyset does scriptwise (like its source code) so I can see myself what im doing wrong.The function called disables the hotkeys temporarily, does some work, and re-enables the hotkeys as the function ends. Hotkeys are set from a HotkeysOff() and HotkeysOn() functions to disable and enable the hotkeys.Behaviorally, it acts like the keys are bound to the function, as pressing them in a notepad results in no characters typed, as intended, however the function does not get executed. I went to Tools>add Trace lines to see if any of my lines were giving me an error code. They weren't, all Error = 0. I noticed in the trace that when I press a different hotkey than what I pressed the first time, nothing happens, at all, despite it being bounded to a function(as noted above). It just continues running the Idle() while 1 sleep function I got going and pretends I never pressed the hotkey. Its like autoit knows the key is bound to a function, but doesn't know which one. Edited August 12, 2015 by BetaLeaf forgot to note hotkeys are disabled on function call and enabled as it ends.
JohnOne Posted August 12, 2015 Posted August 12, 2015 Do you have a reproducer code? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
EmilyLove Posted August 12, 2015 Author Posted August 12, 2015 (edited) I cannot provide the actually code. If I did, I would be violating the nondisclosure agreement I signed with my client. I spoke with my client and I can, however, show you a cleaned up version. For some reason, the cleaned up code does not have any issues. The only changes I made to the clean version was rename the variables and functions I defined. expandcollapse popupGlobal $dowork = "" Global $ScriptName = StringTrimRight(@ScriptName, 4) LoadHotKeys() WinWait("notepad") $dotares = WinGetClientSize("notepad") idle() Func idle() While 1 Sleep(100) WEnd EndFunc ;==>idle Func LoadHotKeys() ;if Ini not found then If Not FileExists($ScriptName & ".ini") Then ;Create Default Storage to write INI. Local $BindStorage[3][2] = _ [ _ ["bind1", "1"], _ ["bind2", "2"], _ ["bind3", "3"]] ;Writes INI from Storage $writeerror = IniWriteSection($ScriptName & ".ini", "Binds", $BindStorage, 0) ;Informs the user of the result. If $writeerror = False Then MsgBox(0, $ScriptName, "Could not write INI. You need Admin permissions to write to " & @ScriptDir) Exit EndIf MsgBox(0, $ScriptName, "Could not find " & @ScriptDir & $ScriptName & ". Loading Default Binds.") ;Reruns this function, loading the default binds. LoadHotKeys() ;if Ini was found then Else ;Loads the binds stored in your INI. Global $bind1 = IniRead($ScriptName & ".ini", "Binds", "bind1", "1") Global $bind2 = IniRead($ScriptName & ".ini", "Binds", "bind2", "2") Global $bind3 = IniRead($ScriptName & ".ini", "Binds", "bind3", "3") ;Turns the hotkeys on HotKeysOn() EndIf Global $binds[3][2] = _ [ _ [1, $bind1], _ [2, $bind2], _ [3, $bind3]] EndFunc ;==>LoadHotKeys Func HotKeysOn() HotKeySet(StringLower($bind1), "DoWork") HotKeySet(StringLower($bind2), "DoWork") HotKeySet(StringLower($bind3), "DoWork") EndFunc ;==>HotKeysOn Func HotKeysOff() HotKeySet(StringLower($bind1)) HotKeySet(StringLower($bind2)) HotKeySet(StringLower($bind3)) EndFunc ;==>HotKeysOff Func DoWork() ;Turns hotkeys off HotKeysOff() ;Detects which hotkey was pressed. For $i = 0 To 2 If @HotKeyPressed = $binds[$i][1] Then Local $keypressed = $i ExitLoop EndIf Next Send($keypressed) ;Turns hotkeys back on HotKeysOn() EndFunc ;==>DoWorkI just noticed The NDA Code I cannot release fails to respond to Ctrl+Break after the second hotkey is used. Stranger yet, even when its in this state, I can still press the first hotkey that I pressed and it works fine, but not the second hotkey still does not work. Its literally like autoit is forgetting which function the keys are bound to after the first hotkey is pressed.>Process failed to respond; forcing abrupt termination...>Exit code: 1 Time: 28.34 Edited August 12, 2015 by BetaLeaf Additional info discovered.
JohnOne Posted August 12, 2015 Posted August 12, 2015 So this script does not reproduce the problem?It works just fine for me. Win 7 32, latest release AutoIt. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
EmilyLove Posted August 12, 2015 Author Posted August 12, 2015 (edited) Correct. Im not entirely sure why this cleaned-up version, which has just had its variables renamed and slimmed down, works fine, yet the other doesn't. Is there a limit to how many HotKeySet() you can have at once? The project I required it for needs exactly 10 HotKeySet() simultaneously. Edited August 12, 2015 by BetaLeaf
JohnOne Posted August 12, 2015 Posted August 12, 2015 Don't know about a limit, but I've had way more than 10.I think you can safely derive that your problem lies elsewhere from HotKeySet. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
EmilyLove Posted August 13, 2015 Author Posted August 13, 2015 Solved. Big thanks for taking time out of your life to help me. Was an issue with part of the NDA code that I finally fixed. Basically an error in If then Logic and Operator Orders
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now