dbmtrde Posted January 16, 2023 Share Posted January 16, 2023 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 comment Share on other sites More sharing options...
ioa747 Posted January 16, 2023 Share Posted January 16, 2023 sleep time = 300000 / 1000 = 300 sec 300 sec / 60 = 5 min => to long and for regular using Send ("X") instant Send ("{X}") I know that I know nothing Link to comment Share on other sites More sharing options...
dbmtrde Posted January 16, 2023 Author Share Posted January 16, 2023 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 comment Share on other sites More sharing options...
ioa747 Posted January 16, 2023 Share Posted January 16, 2023 ... 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 I know that I know nothing Link to comment Share on other sites More sharing options...
ioa747 Posted January 16, 2023 Share Posted January 16, 2023 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 I know that I know nothing Link to comment Share on other sites More sharing options...
dbmtrde Posted January 16, 2023 Author Share Posted January 16, 2023 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 comment Share on other sites More sharing options...
Trong Posted January 16, 2023 Share Posted January 16, 2023 (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, 2023 by VIP min Regards, Link to comment Share on other sites More sharing options...
water Posted January 16, 2023 Share Posted January 16, 2023 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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
dbmtrde Posted January 16, 2023 Author Share Posted January 16, 2023 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 comment Share on other sites More sharing options...
dbmtrde Posted January 16, 2023 Author Share Posted January 16, 2023 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 comment Share on other sites More sharing options...
water Posted January 16, 2023 Share Posted January 16, 2023 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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
dbmtrde Posted January 16, 2023 Author Share Posted January 16, 2023 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 comment Share on other sites More sharing options...
ioa747 Posted January 16, 2023 Share Posted January 16, 2023 exit all ready ; Press F11 for Exit HotKeySet("{F11}", "_Exit_") I know that I know nothing Link to comment Share on other sites More sharing options...
ioa747 Posted January 16, 2023 Share Posted January 16, 2023 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! I know that I know nothing Link to comment Share on other sites More sharing options...
Solution Trong Posted January 16, 2023 Solution Share Posted January 16, 2023 [*] 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 comment Share on other sites More sharing options...
dbmtrde Posted January 17, 2023 Author Share Posted January 17, 2023 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 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