paul Posted March 20, 2009 Report Posted March 20, 2009 What a shame that you can't run the same macro more than once at the same time, thus denying the possibility of recursion. I've just designed a set of macros to allow me to present a "menu" of choices and respond to a single-letter response without having to press ENTER after making my choice. I could have done this in 2 macros if I had been allowed to run multiple instances of the same macro. Instead I end up with 37 macros, one master and 36 macros, one for each possible single-letter response (0-9, A-Z). Still, it does work nicely and quickly. I can now present myself with a menu of, say, 8 choices, 1-8, and respond as soon as any number from 1-8 is entered, just like the 4Nt Inkey command. Quote
joe Posted March 20, 2009 Report Posted March 20, 2009 Still, it does work nicely and quickly. I can now present myself with a menu of, say, 8 choices, 1-8, and respond as soon as any number from 1-8 is entered ... Very nice OzMan ... you are an innovator, to be sure. Quote
Cory Posted March 20, 2009 Report Posted March 20, 2009 Sweet. I remember trying to figure out how to do that back in the ME3 days. How are you doing it? Does the master macro enable all the other macros which use hot keys then disable when done? I'd love to see an example. Quote
paul Posted March 21, 2009 Author Report Posted March 21, 2009 [Revised 22nd March after testing for all 36 conditions simultaneously] Let's take it from the top. I use SQL Server's Query Analyzer many times a day. If loaded in vanilla mode, it asks you for a server. You can start it with a prespecified server, but as I have 4 servers, that's 4 menu choices. So... MACRO QAOpen - Set a variable to my "menu" of 4 server names - Initialize %hotkey% with a string of 4 unique letters - these are the bolded letters above, e.g. CGLV - Run macro Keypress and wait for it to end - Close the text box - If registry value KeyPressReturned is empty, set it to L ((local) - Load Query Analyzer for the selected server whose 1st letter is in registry value KeyPressReturned MACRO Keypress - Set registry value KeyPressRepeats to 2 - Set registry value KeyPressReturned to "*" - Calculate length of %hotkey% - Repeat HotkeyLength times * Extract next character from %hotkey% * Run macro KeyPress + HotkeyCharacter (do not wait for it to end) - Set registry value KeyPressReturned to "" (this causes all KeypressX macros to start processing) - Display menu set by caller - Multiply KeyPressRepeats by 4 (representing 250 milliseconds) - Repeat (KeyPressRepeats x 4) times * Read registry value KeyPressReturned * If not empty Break * Delay 250 milliseconds MACRO Keypress0 - KeypressZ (36 macros) - Read registry value KeyPressRepeats - Repeat until registry value KeyPressReturned <> "*" (this ensures all KeyPressx macros start simultaneously) * Timed Delay 20 milliseconds - Repeat KeyPressRepeats times * Wait for key press 0-Z, depending on the macro (wait a maximum of 1 second) * If timeout occurs (using On Error) $ Read registry value KeyPressReturned $ If not empty, Macro return $ Continue * Set registry value KeyPressReturned to 0-Z (this line gets executed only if the key was pressed) * Break In this example, macros Keypress, KeypressC, KeypressG, KeypressL and KeypressV are all running. If nothing is entered within 2 seconds, these 5 macros will all end and KeyPressReturned will be empty (and then processed by QAOpened as if it were L). If any one of C, G, L or V is entered, these 5 macros will all end within a second, and the related server will be used. I have now tried this with all 36 choices and have revised my code as a result - it all works as intended. If needed, I can tune this by changing the 1st line of Keypress to a value other than 2 (which represents 2 seconds, and therefore 8 250-millisecond repeats for each macro); I can also vary the 250 milliseconds to some other value. There's another approach that I now know will work. I could present a ME menu of choices (running it as a separate macro not waiting for it to end), and simultaneously fire off an AutoIt script that handles the keyboard at a low level and returns whatever has been entered. So once any relevant menu key has been pressed, I can kill the menu macro via its window title and process accordingly. Quote
Alexis Posted August 31, 2009 Report Posted August 31, 2009 Well, i think that´s just too much for me. First of all, your text in the white box is not MEX code. It´s more a brief description what to do / to code, right? Could you paste some original MEX code / lines to make it a little bit clearer. It looks like you work the machine pretty deep. Reading, setting registry values is not for beginners, right? ;-) Though, with a brief example i would give it a try. Thank you very much. Alexandra Quote
paul Posted August 31, 2009 Author Report Posted August 31, 2009 My aim here is to provoke thought and some thinking "outside the box", not to provide prebuilt solutions for others to use "out the box". I'm trying to show people how to make a hamburger (with a little effort) rather than providing a hamburger for others to eat. Quote
Alexis Posted August 31, 2009 Report Posted August 31, 2009 I'm trying to show people how to make a hamburger (with a little effort) rather than providing a hamburger for others to eat. That is so generous and even ethical of you! Makes me feel like a third world child. I made an effort so far. I ´ll do an extra effort for you to make it as easy for you i can think of. Just type an X near Yes/No for answering my questions. The "CODE" text in the white box is MEX code? YES / NO So what is it? Its: _________________ How can this text help any other MEX User? ____________________ Is the problem i described solvable just by MEX only? YES / NO Do you know anybody who can confirm your "Code" as working? YES / NO Just let me know if you want me to make more effort. Alexandra Quote
wzeller Posted February 10, 2010 Report Posted February 10, 2010 <Deleted my own post for unwarranted snarkiness. Upon review later in the day, I can only assume I must have been in an un-noticed bad mood or something. I seemed to sense a lack of appreciation of Paul's time in the responses here, but looking at them now I'm not sure that was the case. So I retract.> Quote
Alexis Posted February 28, 2010 Report Posted February 28, 2010 Any tips of further explanations on this topic will be wildy appreciated! When i read my last post on this topic it may appear sarcastic or even offensive for the reader. I´m sorry for that. I guess i wrote it in a different mood too. But still...I was asking for help. Alexandra Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.