tntyeeter Posted December 2, 2020 Share Posted December 2, 2020 (edited) Recently, I was getting bored because of quarantine. So I thought maybe let's do some AutoIt. I recently discovered that you can use the command prompt to run autoit scripts with CmdLine, so I was excited to use it for the first time. I wanted to make a program which "creates" a 2nd clipboard. So this is how it should work. - I open cmd - I type in "filename.au3 [the words that i want to copy]" - I press enter - It creates a hotkey to paste the copied word - It does an empty while loop so it doesn't immediately exit - To exit the script, I type in "filename.au3 exit". But "filename.au3 exit" doesn't work so I have to manually click on the tray icon which is not what I wanted. I'm fairly new to AutoIt so I don't really know how things work. Sorry if my English is horrible, it isn't my native language. Any help would be greatly appreciated. Global Const $g_iProfileDir = @UserProfileDir & "\" Global Const $g_iProgDir = @UserProfileDir & "\Clipify 2.0\" ;dir path Global Const $g_iIniFile = $g_iProgDir & "config.ini" ;ini file path DirCreate($g_iProgDir) Local $iIniRead = IniRead($g_iIniFile, "Setup", "IfExists", "NOEXIST") ; checks if the ini file exists If $iIniRead = "NOEXIST" Then IniWrite($g_iIniFile, "Setup", "IfExists", "1") FileMove(@ScriptFullPath, $g_iProfileDir & @ScriptName) ; if it doesn't exist, it'll create the ini file and move the script to the user directory so you don't have to put the entire file path Else Select Case $CmdLine[0] = "" ToolTip("") Case $CmdLine[1] <> "Exit" HotKeySet("{TAB}", "_Clip2") HotKeySet("`", "_Exit") While 1 WEnd Case $CmdLine[1] = "Exit" Local $aProcessList = ProcessList(@AutoItPID) For $i = 1 To $aProcessList[0][0] ProcessClose($aProcessList[$i][1]) Next Case Else ; if it has more than 2 parameters it will automatically exit Exit EndSelect EndIf Func _Clip2() Send($CmdLine[1]) EndFunc ;==>_Clip2 Func _Exit() Exit EndFunc ;==>_Exit Edited December 2, 2020 by Jos codebox added Link to comment Share on other sites More sharing options...
Nine Posted December 2, 2020 Share Posted December 2, 2020 Your problem is the ProcessList. @AutoItPID is unique to each process. Since you are creating 2 different processes, they have their own individual PID. Your ProcessList should look for all AutoIt3.exe and close them. But I would recommend that you close all processes except the one @AutoItPID which should be close normally with Exit. When you have While...WEnd loop, include a small sleep inside so you do not overload your CPU. And please use this tool when you post code. tntyeeter 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
tntyeeter Posted December 2, 2020 Author Share Posted December 2, 2020 21 minutes ago, Nine said: Your problem is the ProcessList. @AutoItPID is unique to each process. Since you are creating 2 different processes, they have their own individual PID. Your ProcessList should look for all AutoIt3.exe and close them. But I would recommend that you close all processes except the one @AutoItPID which should be close normally with Exit. When you have While...WEnd loop, include a small sleep inside so you do not overload your CPU. And please use this tool when you post code. It worked! And I didn't even know that it could overload my CPU. Thanks! Link to comment Share on other sites More sharing options...
Nine Posted December 2, 2020 Share Posted December 2, 2020 Congrats. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
JockoDundee Posted December 5, 2020 Share Posted December 5, 2020 On 12/2/2020 at 4:42 AM, tntyeeter said: And I didn't even know that it could overload my CPU. Such is the latent power of Autoit... Code hard, but don’t hard code... 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