Surma Posted July 13, 2011 Share Posted July 13, 2011 Hello.I'm kinda new to autoit and this is probably some small mistake, but anyway.I am making a script which is supposed to run a function once when a key is pressed. Something like this:HotKeySet("g","_func") Func _func () ; Code EndFunc While 1 Sleep(50) WEndThe problem is that when g is pressed, ; Code just keeps getting executed over and over again. I only want it to run once. How do I achieve this? Link to comment Share on other sites More sharing options...
bogQ Posted July 13, 2011 Share Posted July 13, 2011 The problem is that when g is pressed, ; Code just keeps getting executed over and over again. I only want it to run once. How do I achieve this? fast way to do it is to block it untill the key is up #include <Misc.au3> HotKeySet("g","_func") While 1 Sleep(10) WEnd Func _func () ; Code Do Sleep(10) Until Not _IsPressed("47");G EndFunc TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
Exit Posted July 13, 2011 Share Posted July 13, 2011 HotKeySet("g","_func") Func _func () HotKeySet("g") ; unset hotkey ; Code HotKeySet("g","_func") ; set hotkey again EndFunc While 1 Sleep(50) WEnd App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
DrKovra Posted July 13, 2011 Share Posted July 13, 2011 Well, if you ONLY want to run it once, then this will do. HotKeySet("g","_func") Func _func () ; Code Exit EndFunc While 1 Sleep(50) WEnd Add the "Exit" command after your code [s][font="Impact"]░▒▓▓►DrKovra◄▓▓▒░[/font][/s]The only thing I [sup]know [/sup]is that I don't know [sub]nothing[/sub]--------------- __________------------------------------ __________--------------- Link to comment Share on other sites More sharing options...
Surma Posted July 13, 2011 Author Share Posted July 13, 2011 Well, if you ONLY want to run it once, then this will do. HotKeySet("g","_func") Func _func () ; Code Exit EndFunc While 1 Sleep(50) WEnd Add the "Exit" command after your code Exit would cause the whole script to exit, wouldn't it? Or is it just the function that exists? Anyway, I'm not sure that I completely understand why it behaves as it does. I'd really like to understand that and why your suggestions fixes it. Link to comment Share on other sites More sharing options...
Developers Jos Posted July 13, 2011 Developers Share Posted July 13, 2011 You haven't specified what code is in the _Func() that could cause this behaviour. The posted code will work fine and only execute the Func one time when the HotKey is pressed. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 13, 2011 Share Posted July 13, 2011 (edited) @Surma: This typically happens because something you are doing in _Func() is sending a synthetic "g" keystroke, which fires the hotkey again in a loop. You didn't answer to forumer100's post above showing how to avoid that. Edited July 13, 2011 by PsaltyDS 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 More sharing options...
Surma Posted July 15, 2011 Author Share Posted July 15, 2011 @Surma: This typically happens because something you are doing in _Func() is sending a synthetic "g" keystroke, which fires the hotkey again in a loop. You didn't answer to forumer100's post above showing how to avoid that.Sorry, must've scrolled past him.Uh, yes indeed I am using send, among other things, in the function. I feel stupid...Thank you all a million, you've made my day 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