dbmtrde 0 Posted January 16 Share Posted January 16 Hi Everyone, I am currently trying to send multiple keys for a application in different time periods but it is not working as i expect. (I am new in Autoit) Example Every X miliseconds an X key should be sent, Every Y miliseconds a Y key, Every Z miliseconds a NUMPAD2 key should be sent. I have tried to realize this with several functions but then only one of the three functions works and not all after each sleep. expandcollapse popup#RequireAdmin HotKeySet ( "{F6}" , "Start1" ) HotKeySet ( "{F7}" , "Start2" ) HotKeySet ( "{F8}" , "Start3" ) HotKeySet ( "{F9}" , "Pause" ) HotKeySet ( "{F11}" , "Ende" ) while (1) sleep(50) wend Func Start () HotKeySet ( "{F9}" , "Pause" ) While 1 Sleep(300000) Send ("{X}") Wend EndFunc Func Start2 () HotKeySet ( "{F9}" , "Pause" ) While 1 Sleep(300000) Send ("{Y}") Wend EndFunc Func Start3 () HotKeySet ( "{F9}" , "Pause" ) While 1 Sleep(300000) Send ("{NUMPAD2}") Wend EndFunc Func Pause () While (1) Wend EndFunc Func Ende () Exit EndFunc Can anyone tell me where I'm making mistakes or how to make this work? Link to post Share on other sites
ioa747 35 Posted January 16 Share Posted January 16 sleep time = 300000 / 1000 = 300 sec 300 sec / 60 = 5 min => to long and for regular using Send ("X") instant Send ("{X}") Link to post Share on other sites
dbmtrde 0 Posted January 16 Author Share Posted January 16 11 minutes ago, ioa747 said: sleep time = 300000 / 1000 = 300 sec 300 sec / 60 = 5 min => to long and for regular using Send ("X") instant Send ("{X}") I have read here that it can be used up to 24 days in miliseconds. -> https://www.autoitscript.com/autoit3/docs/functions/Sleep.htm Am a little confused... I need every 5 min send X, every 15 min send Y and every 30 min send NUMPAD2 Is it not possible to do it with autoit? Link to post Share on other sites
ioa747 35 Posted January 16 Share Posted January 16 ... and error: Start1(): undefined function. start with small step #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 6 -w- 7 HotKeySet("{F6}", "Start") HotKeySet("{F7}", "Start2") HotKeySet("{F8}", "Start3") HotKeySet("{F11}", "Ende") While (1) Sleep(100) WEnd Func Start() Send("X") EndFunc ;==>Start Func Start2() Send("Y") EndFunc ;==>Start2 Func Start3() Send("{NUMPAD2}") EndFunc ;==>Start3 Func Ende() Exit EndFunc ;==>Ende with While 1 Wend in your func the flow come never out Link to post Share on other sites
ioa747 35 Posted January 16 Share Posted January 16 10 minutes ago, dbmtrde said: I need every 5 min send X, every 15 min send Y and every 30 min send NUMPAD2 Is it not possible to do it with autoit? HotKeySet mind you press the key Link to post Share on other sites
dbmtrde 0 Posted January 16 Author Share Posted January 16 1 minute ago, ioa747 said: HotKeySet mind you press the key ok but if I have to press the hotkeys manually anyway then I can do it without autoit 🙂 What I need is to start once every 5 min sendkey X, every 15 min sendkey Y and every 30 min sendkey NUMPAD2 My purpose is to automate the whole thing to avoid annoying repetitive things. Link to post Share on other sites
Trong 105 Posted January 16 Share Posted January 16 (edited) It will look like this: Opt("TrayAutoPause", 0) ;0=no pause, 1=Pause ; Press F11 for Exit HotKeySet("{F11}", "_Exit_") ;Every X miliseconds an X key should be sent, AdlibRegister('Send_X', 5 * 60000) ; 5 min ;Every Y miliseconds a Y key, AdlibRegister('Send_Y', 15 * 60000) ; 15 min ;Every Z miliseconds a NUMPAD2 key should be sent. AdlibRegister('Send_NUMPAD2', 30 * 60000) ; 30 min While (1) Sleep(100) WEnd Func Send_X() Send("X") EndFunc ;==>Send_X Func Send_Y() Send("Y") EndFunc ;==>Send_Y Func Send_NUMPAD2() Send("{NUMPAD2}") EndFunc ;==>Send_NUMPAD2 Func _Exit_() Exit EndFunc ;==>_Exit_ Edited January 16 by VIP min Regards, Link to post Share on other sites
water 2,702 Posted January 16 Share Posted January 16 Can you please tell us why you need to press this keys every n minutes? Most of the time there are more reliable ways to solve your problem My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to post Share on other sites
dbmtrde 0 Posted January 16 Author Share Posted January 16 54 minutes ago, VIP said: It will look like this: Opt("TrayAutoPause", 0) ;0=no pause, 1=Pause ; Press F11 for Exit HotKeySet("{F11}", "_Exit_") ;Every X miliseconds an X key should be sent, AdlibRegister('Send_X', 5 * 60000) ; 5 min ;Every Y miliseconds a Y key, AdlibRegister('Send_Y', 15 * 60000) ; 15 min ;Every Z miliseconds a NUMPAD2 key should be sent. AdlibRegister('Send_NUMPAD2', 30 * 60000) ; 30 min While (1) Sleep(100) WEnd Func Send_X() Send("X") EndFunc ;==>Send_X Func Send_Y() Send("Y") EndFunc ;==>Send_Y Func Send_NUMPAD2() Send("{NUMPAD2}") EndFunc ;==>Send_NUMPAD2 Func _Exit_() Exit EndFunc ;==>_Exit_ Hi I will try it but in first glance I could not find start stop function. How could I include it? Link to post Share on other sites
dbmtrde 0 Posted January 16 Author Share Posted January 16 50 minutes ago, water said: Can you please tell us why you need to press this keys every n minutes? Most of the time there are more reliable ways to solve your problem it will run on a document processing server (Windows) as a trigger. Link to post Share on other sites
water 2,702 Posted January 16 Share Posted January 16 3 hours ago, dbmtrde said: it will run on a document processing server (Windows) as a trigger. Very strange. A server program should ALWAYS run without user intervention 🤔 But I'm sure you will get a solution here My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to post Share on other sites
dbmtrde 0 Posted January 16 Author Share Posted January 16 2 hours ago, water said: Very strange. A server program should ALWAYS run without user intervention 🤔 But I'm sure you will get a solution here It's a quick crafted application, nothing professional. It does what it is supposed to do, but needs a trigger via the keyboard. Script shared by @VIP works pretty well, thanks for that. But of course it would be more helpful if I could somehow include start, pause, end. Then it would be perfect! Can you help me with that? Link to post Share on other sites
ioa747 35 Posted January 16 Share Posted January 16 exit all ready ; Press F11 for Exit HotKeySet("{F11}", "_Exit_") Link to post Share on other sites
ioa747 35 Posted January 16 Share Posted January 16 from https://www.autoitscript.com/autoit3/docs/functions/HotKeySet.htm Example 1 #include <MsgBoxConstants.au3> ; Press Esc to terminate script, Pause/Break to "pause" Global $g_bPaused = False HotKeySet("{PAUSE}", "TogglePause") HotKeySet("{ESC}", "Terminate") HotKeySet("+!d", "ShowMessage") ; Shift-Alt-d While 1 Sleep(100) WEnd Func TogglePause() $g_bPaused = Not $g_bPaused While $g_bPaused Sleep(100) ToolTip('Script is "Paused"', 0, 0) WEnd ToolTip("") EndFunc ;==>TogglePause Func Terminate() Exit EndFunc ;==>Terminate Func ShowMessage() MsgBox($MB_SYSTEMMODAL, "", "This is a message.") EndFunc ;==>ShowMessage perfect example! Link to post Share on other sites
Solution Trong 105 Posted January 16 Solution Share Posted January 16 [*] Happy Lunar New Year : expandcollapse popupOpt("TrayAutoPause", 0) ;0=no pause, 1=Pause Global Const $nSEND_X = 5 * 60000 Global Const $nSEND_Y = 15 * 60000 Global Const $nSEND_NUMPAD2 = 30 * 60000 ; Press F8 for START (to start the timer) / STOP (Time will be reset) HotKeySet("{F8}", "_Stop_") ; Press F9 for EXIT HotKeySet("{F9}", "_Exit_") Global $g_bPaused = False _Clock_Start_() While 1 Sleep(100) WEnd Func _Stop_() $g_bPaused = Not $g_bPaused If $g_bPaused Then _Clock_Stop() Else _Clock_Start_() EndIf EndFunc ;==>_Stop_ Func Send_X() Send("X") ConsoleWrite("- SEND: X on: " & @HOUR & ":" & @MIN & ":" & @SEC & " !" & @CRLF) EndFunc ;==>Send_X Func Send_Y() Send("Y") ConsoleWrite("- SEND: Y on: " & @HOUR & ":" & @MIN & ":" & @SEC & " !" & @CRLF) EndFunc ;==>Send_Y Func Send_NUMPAD2() Send("{NUMPAD2}") ConsoleWrite("- SEND: NUMPAD2 on: " & @HOUR & ":" & @MIN & ":" & @SEC & " !" & @CRLF) EndFunc ;==>Send_NUMPAD2 Func _Exit_() Exit EndFunc ;==>_Exit_ Func _Clock_Start_() ToolTip('The timer is running!', 5, 5) ConsoleWrite("- Clock START on: " & @HOUR & ":" & @MIN & ":" & @SEC & " !" & @CRLF) ;Every ... min an X key should be sent, AdlibRegister('Send_X', $nSEND_X) ; ;Every ... min a Y key should be sent, AdlibRegister('Send_Y', $nSEND_Y) ; ;Every ... min a NUMPAD2 key should be sent. AdlibRegister('Send_NUMPAD2', $nSEND_NUMPAD2) ; EndFunc ;==>_Clock_Start_ Func _Clock_Stop() ToolTip('The timer has stopped!', 5, 5) ConsoleWrite("- Clock stoped on: " & @HOUR & ":" & @MIN & ":" & @SEC & " !" & @CRLF) AdlibUnRegister('Send_X') AdlibUnRegister('Send_Y') AdlibUnRegister('Send_NUMPAD2') EndFunc ;==>_Clock_Stop Regards, Link to post Share on other sites
dbmtrde 0 Posted January 17 Author Share Posted January 17 9 hours ago, VIP said: [*] Happy Lunar New Year : expandcollapse popupOpt("TrayAutoPause", 0) ;0=no pause, 1=Pause Global Const $nSEND_X = 5 * 60000 Global Const $nSEND_Y = 15 * 60000 Global Const $nSEND_NUMPAD2 = 30 * 60000 ; Press F8 for START (to start the timer) / STOP (Time will be reset) HotKeySet("{F8}", "_Stop_") ; Press F9 for EXIT HotKeySet("{F9}", "_Exit_") Global $g_bPaused = False _Clock_Start_() While 1 Sleep(100) WEnd Func _Stop_() $g_bPaused = Not $g_bPaused If $g_bPaused Then _Clock_Stop() Else _Clock_Start_() EndIf EndFunc ;==>_Stop_ Func Send_X() Send("X") ConsoleWrite("- SEND: X on: " & @HOUR & ":" & @MIN & ":" & @SEC & " !" & @CRLF) EndFunc ;==>Send_X Func Send_Y() Send("Y") ConsoleWrite("- SEND: Y on: " & @HOUR & ":" & @MIN & ":" & @SEC & " !" & @CRLF) EndFunc ;==>Send_Y Func Send_NUMPAD2() Send("{NUMPAD2}") ConsoleWrite("- SEND: NUMPAD2 on: " & @HOUR & ":" & @MIN & ":" & @SEC & " !" & @CRLF) EndFunc ;==>Send_NUMPAD2 Func _Exit_() Exit EndFunc ;==>_Exit_ Func _Clock_Start_() ToolTip('The timer is running!', 5, 5) ConsoleWrite("- Clock START on: " & @HOUR & ":" & @MIN & ":" & @SEC & " !" & @CRLF) ;Every ... min an X key should be sent, AdlibRegister('Send_X', $nSEND_X) ; ;Every ... min a Y key should be sent, AdlibRegister('Send_Y', $nSEND_Y) ; ;Every ... min a NUMPAD2 key should be sent. AdlibRegister('Send_NUMPAD2', $nSEND_NUMPAD2) ; EndFunc ;==>_Clock_Start_ Func _Clock_Stop() ToolTip('The timer has stopped!', 5, 5) ConsoleWrite("- Clock stoped on: " & @HOUR & ":" & @MIN & ":" & @SEC & " !" & @CRLF) AdlibUnRegister('Send_X') AdlibUnRegister('Send_Y') AdlibUnRegister('Send_NUMPAD2') EndFunc ;==>_Clock_Stop Works as expected and very well, thank you! ✌️ Link to post Share on other sites
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