Mazdryk Posted December 20, 2013 Posted December 20, 2013 (edited) In most of my macros I have had this problem and I can never solve it. Basically my hotkey for a function is F10 and I spam that hotkey...the problem is that when I spam the hotkey the same function is ran several times and it never lets the original function finish. I want to disable the hotkey or have it ignored until the function runs from start to finish. In the script below if I spam the hotkey I just want the result to be 123456789123456789123456789 but what I get is 123451212121212121212345678934567893456789345678934567893456789345678934567896789. I do not want to use any timer, repeat, or ignore my entire keyboard. Example script: #include <Misc.au3> HotKeySet("{F9}", "_exit") Hotkeyset ("{F10}", "_go" ) While 1 Sleep (5000) ;Keeps script running WEnd Func _go() Send ("{1 DOWN}") Sleep (10) Send ("{1 UP}") Sleep (100) Send ("{2 DOWN}") Sleep (10) Send ("{2 UP}") Sleep (200) Send ("{3 DOWN}") Sleep (10) Send ("{3 UP}") Sleep (200) Send ("{4 DOWN}") Sleep (10) Send ("{4 UP}") Sleep (200) Send ("{5 DOWN}") Sleep (10) Send ("{5 UP}") Sleep (200) Send ("{6 DOWN}") Sleep (10) Send ("{6 UP}") Sleep (300) Send ("{7 DOWN}") Sleep (10) Send ("{7 UP}") Sleep (400) Send ("{8 DOWN}") Sleep (10) Send ("{8 UP}") Sleep (500) Send ("{9 DOWN}") Sleep (10) Send ("{9 UP}") Sleep (150) EndFunc Func _exit() Sleep(3000) Exit 0 EndFunc Edited December 20, 2013 by Mazdryk
Moderators Melba23 Posted December 20, 2013 Moderators Posted December 20, 2013 Mazdryk, I want to disable the hotkey or have it ignored until the function runs from start to finishSo why not do just that - disable the HotKey as you enter the function and re-enable it as you leave. This shows how you might do it: HotKeySet("^q", "_Func_Q") HotKeySet("{ESC}", "On_Exit") While 1 Sleep(10) WEnd Func _Func_Q() HotKeySet("^q") ConsoleWrite("In the function at " & @SEC & @CRLF) Sleep(1000) ConsoleWrite("Out of the function at " & @SEC & @CRLF) HotKeySet("^q", "_Func_Q") EndFunc Func On_Exit() Exit EndFuncBut spamming a key is a pretty inefficient way to go about things - if you explain what you are trying to automate we might be able to offer a better solution. 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
martin Posted December 20, 2013 Posted December 20, 2013 At the start of your func go() you must have HotKeySet("{F10}") ;Turn th ehotkey off then before the function returns have HotKeySet("{F10}","_go") Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
John117 Posted December 21, 2013 Posted December 21, 2013 (edited) Not sure what you are doing so it didn't test this. It may work for you. -edit: changed "I may work for you" to "It may work for you." - I no work for you! :-) #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.9.4 (beta) Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <Misc.au3> HotKeySet("{F9}", "_exit") HotKeySet("{F10}", "_go") While 1 Sleep(5000) ;Keeps script running WEnd Func _go() HotKeySet("{F10}") ;Turn th ehotkey off For $i = 1 To 9 Send(Execute('"{' & $i & '}"')) Send("{DOWN}") Sleep(10) Send("{1 UP}") Send(Execute('"{' & $i & '}"')) Send("{UP}") Next Sleep(150) HotKeySet("{F10}","_go") EndFunc ;==>_go Func _exit() Sleep(3000) Exit 0 EndFunc ;==>_exit Edited December 21, 2013 by John117
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