Sorry, but parts of this post might not make sense until you read the whole post.
My script is specifically written to be use via a remote control session so I do not need the
TrayTip and the
Sleep lines that you see in the code below. You might not need them either, it depends on how you wish to invoke the script. If you have your MS Access full screened, then it might not be easy for you to double click on a shortcut to the script. It might be easiest to assign a Windows shortcut key (e.g.
Ctrl-Alt-B) to a shortcut that leads to the script.
Even if you have a portion of your desktop showing or if you use the Desktop toolbar on the Taskbar, you may find it difficult to double click on anything because the computer is so busy running the MS Access search that it might not accept each click fast enough to be considered a double click. Right clicking on the script (or a shortcut to the script) and then selecting
Run Script from the context menu is an alternative, but context menus are slow to build when the computer is busy. Even OS shortcut keys can be missed at times. If, after a few seconds, you do not see the TrayTip, then press
Ctrl-Alt-B again. If you should happen to end up with two or more copies of the script running at once, it won't matter; the other copies will just timeout after 5 or so seconds and will exit.
Windows has a "feature" (I'll not call it a bug since it has been this way since Windows 3). If you hold down the Ctrl key and you send the Ctrl key via a script, then Ctrl key will continue to be "held down" even after you release the Ctrl key. It is not a big deal to undo this condition; you just press and release the Ctrl key once again. But to avoid the condition all together, I try to remember to add a
Sleep line that gives me plenty of time to release the Ctrl on the real keyboard before the script sends a virtual Ctrl during the
Ctrl Break line of code.
Code:
Opt("TrayIconDebug", 1)
TrayTip("", "waiting for you to release the Ctrl key", 100)
Sleep(5000)
WinActivate("Find and Replace")
If WinWaitActive("Find and Replace", "", 5) Then Send("^{BREAK}")
I'll try and explain each line so that you can modify things as desired.
Feel free to ask for help with modifications and I'll do what I can for you.
TrayIconDebug
If enabled shows the current script line in the tray icon tip to help debugging.
0 = no debug information (default)
1 = show debug
If the script hangs, mouse over the AutoIt icon in the system tray and a tool tip should let you know the line of code that it is hung up on. There are much more detailed debug tools, but I leave this one turned on for minor debugging. There are no lines of code in this version of the script that can hang. If you just want to see the debug tool tip in action, run the script while there is no MS Access search taking place and you will have 5 seconds to mouse over the AutoIt icon in the notification area (system tray) down by the clock. The AutoIt icon might be hidden. You might want to tell Windows to always show icons from AutoIt or to just always show every system tray icon.
TrayTip and Sleep
I've already explained why they are there.
WinActivate
...is just like it sounds. It activates the window. (Brings it into focus. Brings it to the foreground.) If you opt to start the script from a desktop shortcut, then the desktop will be in focus until this line of code attempts to change that.
WinWaitActive
Again, this is just like it sounds. The script waits until the window of interest is active before moving on to more code. The WinWaitActive function has a timeout feature. I have set the timeout to 5 seconds. If the timeout occurs, then the the function will return a 0. This 0 makes the condition for the single line If statement not true - so the
Sending of the Ctrl-Break will not happen.
In other words, if the Window of interest is not present or the computer is so busy that it cannot activate the window of interest within 5 seconds, the script will not attempt to send the Ctrl-Break key combo to any window; instead, the script will just exit. If desired, code can be added to let you know that it did not try to send the Ctrl-Break. I've just never had it be that busy, so I did not bother to code a notification.
Here is a post that has some more info about AutoIt (and a download link):
http://www.sevenforums.com/general-...ear-after-explorer-restart-2.html#post1841812
You do not need to compile this script into an exe; just leave it as a text file. If you plan on not using the OS shortcut key (e.g.
Ctrl-Alt-B), then you can just put the script file directly on your desktop. Otherwise, put the script elsewhere and place a shortcut to it on your desktop.
Obviously, the script above is meant to send Ctrl-Break to the MS Access Find/Replace dialog box. You will need to code another script for your MS Excel needs. It is possible to put the code for both needs into one script, but we can save that for later.
AutoIt comes with a script editor. Because you will be making another script, I would suggest that you install the more
advanced editor from here. (Click on the link named SciTE4AutoIt3.exe) That version should give you auto-complete prompts and syntax prompts - as well as take you to the help file entry for a given function if you place the cursor on the function and press F1.
Now - having put you to sleep with that boring novel of a post - I'll mention another way to use a script to send the Ctrl-Break key combo to an app. You could have the script start when your computer starts and have the script run in a loop until you press a key combo like
Ctrl-Shift-a. That would cause the script to activate the MS Access window and send the Ctrl-Break key combo. Pressing another key combo like
Ctrl-Shift-x could send the Ctrl-Break key combo to MS Excel. The way that you write/use the script depends on how often you encounter the need to send Ctrl-Break key combo to an app.
Here is a link to another AutoIt script that I offered to another OP:
http://www.sevenforums.com/microsof...-txt-file-existing-extension.html#post2336160 but I never heard back to know if the OP made use of it :-(