Tweed Posted June 22, 2014 Share Posted June 22, 2014 Greetings All First you should know that I am a complete scripting noob (I just delved into this yesterday) and my question will probably sound dumb to you so I apologize in advance. So I am trying to get a process to end when I press ESC. I am not looking for anything fancy, just have the script watch the process and if ESC is entered the process will end and the script will stop. From looking at other peoples scripts I have cobbled together the below but I believe something is wrong with my loop and I am unsure how to proceed. Currently the script runs but just closes right after it's run without doing anything. Any assistance would be much appreciated. HotKeySet("{ESC}", "Terminate") sleep(100) Func Terminate() ProcessClose ( "notepad.exe" ) Exit 0 EndFunc Link to comment Share on other sites More sharing options...
orbs Posted June 22, 2014 Share Posted June 22, 2014 (edited) hello Tweed, welcome to AutoIt and to the forum! your script does exactly what you asked of it: register a hotkey, wait for 100ms, then exit. you are NOT asking your script to do anything else, like wait in idle, for example: HotKeySet("{ESC}", "Terminate") While True ; do something here - this is where your main action should be sleep(100) ; this is just here to keep the CPU from burning WEnd Func Terminate() ProcessClose ( "notepad.exe" ) Exit 0 EndFunc also, when you post code to the forum, use the code tags - that makes your script much more readable. use the "A" button (tooltip: "Code") on the toolbar menu. Edited June 22, 2014 by orbs Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Link to comment Share on other sites More sharing options...
JohnOne Posted June 22, 2014 Share Posted June 22, 2014 something is wrong with my loop Indeed there is. It's missing. Palestinian 1 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Tweed Posted June 22, 2014 Author Share Posted June 22, 2014 Hmmm how about how I changed it...would that work? hello Tweed, welcome to AutoIt and to the forum! your script does exactly what you asked of it: register a hotkey, wait for 100ms, then exit. you are NOT asking your script to do anything else, like wait in idle, for example: HotKeySet("{ESC}", "Terminate") While True ProcessExists(notepad.exe) sleep(100) ; this is just here to keep the CPU from burning WEnd Func Terminate() ProcessClose ( "notepad.exe" ) Exit 0 EndFunc also, when you post code to the forum, use the code tags - that makes your script much more readable. use the "A" button (tooltip: "Code") on the toolbar menu. Link to comment Share on other sites More sharing options...
Geir1983 Posted June 22, 2014 Share Posted June 22, 2014 You did not really change anything by adding the ProcessExists.. What was the intention, exit script if it does not exist? Link to comment Share on other sites More sharing options...
orbs Posted June 22, 2014 Share Posted June 22, 2014 other than being a syntax error, that won't give you anything. the line you add just computes the existence of notepad.exe, but it does not DO anything with it. Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Link to comment Share on other sites More sharing options...
Tweed Posted June 22, 2014 Author Share Posted June 22, 2014 (edited) You did not really change anything by adding the ProcessExists.. What was the intention, exit script if it does not exist? No...I want it to do nothing at all unless I press ESC...then if I press ESC to end the process "Notepad.exe" Currently I run it, its jumps up for a split second and ends...looking for it to keep going until I press ESC. Edited June 22, 2014 by Tweed Link to comment Share on other sites More sharing options...
JohnOne Posted June 22, 2014 Share Posted June 22, 2014 No...I want it to do nothing at all unless I press ESC...then if I press ESC to end the process "Notepad.exe" Currently I run it, its jumps up for a split second and ends...looking for it to keep going until I press ESC. That's exactly what orbs' script does. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
orbs Posted June 22, 2014 Share Posted June 22, 2014 then you don't need it. ProcessClose() will fail if the target process does not exist, but it will not crush your script. your script will exit as planned no matter the result of ProcessClose(), so preliminary check is redundant. do you mean you want your script to accept the Esc key only when notepad is running? Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Link to comment Share on other sites More sharing options...
JohnOne Posted June 22, 2014 Share Posted June 22, 2014 HotKeySet("{ESC}", "Terminate") While True ;ProcessExists(notepad.exe) sleep(100) ; this is just here to keep the CPU from burning WEnd Func Terminate() ProcessClose ( "notepad.exe" ) ;Exit 0 EndFunc AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Tweed Posted June 22, 2014 Author Share Posted June 22, 2014 That's exactly what orbs' script does. Oh LOL sorry...I thought he was asking me to insert something into his script hehe spent the last couple hours searching for what to put in it...didn't realize that was what I was looking for. Also just saw your sig...reading it now. Link to comment Share on other sites More sharing options...
orbs Posted June 22, 2014 Share Posted June 22, 2014 Oh LOL sorry...I thought he was asking me to insert something into his script hehe spent the last couple hours searching for what to put in it...didn't realize that was what I was looking for. Also just saw your sig...reading it now. sorry for confusing you. the point was that the main action of your script is actually doing nothing in a loop. it is more common that a script is actually doing something, which may be interrupted by a hot key. Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff 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