Wutklumpen Posted January 13, 2014 Share Posted January 13, 2014 Hi, i have mutliple hotkeys bound to a single function (due to lack of passing arguments via HotKeySet). The function is pretty expensive, takes about 1 to 1.5 seconds. If i hit multiple of those hotkeys in a row while the function is still running it shows a strange behaviour. I think its because of this HotkeySet-Documentation : A hotkey-press *typically* interrupts the active AutoIt function/statement and runs its user function until it completes or is interrupted. Exceptions are as follows: 1) If the current function is a "blocking" function, then the key-presses are buffered and execute as soon as the blocking function completes. MsgBox() and FileSelectFolder() are examples of blocking functions. Sounds like i have 2 possible solutions. Either i can "block" the function somehow, like MsgBox() does it (does the "blocking" state occur because of the expectation of an userinput?), or i have to use a semaphore in the function, which puts all additional hotkey "presses" in a sleep-loop, until the function is done, and then go on with the next. What do you think is a good way to handle this? Thanks in advance, Wutklumpen Link to comment Share on other sites More sharing options...
JohnOne Posted January 13, 2014 Share Posted January 13, 2014 What behaviour do you want? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Wutklumpen Posted January 13, 2014 Author Share Posted January 13, 2014 (edited) A synchronized behaviour. No matter how often which hotkeys are pressed, process one after the other. Like 1) in the documentation: *snip* key-presses are buffered and execute as soon as the blocking function completes. *snip* Edited January 13, 2014 by Wutklumpen Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted January 13, 2014 Moderators Solution Share Posted January 13, 2014 Wutklumpen,Welcome to the AutoIt forum. I would do it something like this:expandcollapse popup#include <Array.au3> HotKeySet("{ESC}", "On_Exit") HotKeySet("w", "_HotKeyPressed") HotKeySet("e", "_HotKeyPressed") HotKeySet("r", "_HotKeyPressed") Global $aHotKeyCalls[1] = [0] While 1 Sleep(10) If $aHotKeyCalls[0] Then ; Show calling key ConsoleWrite($aHotKeyCalls[1] & @CRLF) ; Simulate function that lasts 2 secs Sleep(2000) ; Remove call _ArrayDelete($aHotKeyCalls, 1) $aHotKeyCalls[0] -= 1 EndIf WEnd Func _HotKeyPressed() ; Add call to array $aHotKeyCalls[0] += 1 ReDim $aHotKeyCalls[$aHotKeyCalls[0] + 1] $aHotKeyCalls[$aHotKeyCalls[0]] = @HotKeyPressed EndFunc Func On_Exit() Exit EndFuncPlease ask if anything is unclear. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Wutklumpen Posted January 13, 2014 Author Share Posted January 13, 2014 Hi, Melba23! Thanks, that looks like a pretty smart solution to my problem. As well it's straight forward but i dont think i have could implemented this by myself! I wrote some comments on your code, my understanding of what it does. If you dont mind reviewing my review?^^ Could be usefull for people stumbling upon this question also. expandcollapse popup#include <Array.au3> HotKeySet("{ESC}", "On_Exit") HotKeySet("w", "_HotKeyPressed") HotKeySet("e", "_HotKeyPressed") HotKeySet("r", "_HotKeyPressed") Global $aHotKeyCalls[1] = [0] While 1 Sleep(10) If $aHotKeyCalls[0] Then ;-- while calls in queue ; Show calling key ConsoleWrite($aHotKeyCalls[1] & @CRLF) ; Simulate function that lasts 2 secs Sleep(2000) ;-- do stuff ; Remove call _ArrayDelete($aHotKeyCalls, 1) ;-- delete saved hotkey from queue, shrink the array by one element $aHotKeyCalls[0] -= 1 ;-- decrement queue count EndIf WEnd Func _HotKeyPressed() ; Add call to array $aHotKeyCalls[0] += 1 ;-- increment the current count of calls ReDim $aHotKeyCalls[$aHotKeyCalls[0] + 1] ;-- expand the call array to a size of <count of current calls> +1 $aHotKeyCalls[$aHotKeyCalls[0]] = @HotKeyPressed ;-- insert the hotkey-call to the recently added index (i think i can put what ever i want in here, right?) EndFunc Func On_Exit() Exit EndFunc And thank you for the warm welcome! =] Thanks, Wutklumpen Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 13, 2014 Moderators Share Posted January 13, 2014 Wutklumpen,Your comments are spot on. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
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