Sign in to follow this  
Followers 0
Mazdryk

Had this issue forever please help

4 posts in this topic

#1 ·  Posted (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 by Mazdryk

Share this post


Link to post
Share on other sites



Mazdryk,

 

I want to disable the hotkey or have it ignored until the function runs from start to finish

So 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
EndFunc
But 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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by John117

Share this post


Link to post
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
Sign in to follow this  
Followers 0