So if I create a hot key with this code:
function OnClick(clickData)
{
var wsh = new ActiveXObject("WScript.Shell");
wsh.SendKeys("{HOME}+{END}");
}
\
Then what - I insert the date/time code from the other thread into a scripot file called WScript.Shell?
Is that right?
--
I'm honestly not dumb just more arts than sciences inclined.
I'm trying to figure stuff out\ myself (perhaps with limited success)
Honestly, I read up on, & solved, perhaps 10 distinct issues without ever posting myself. I have like 120 tabs saved trying to find stuff out BEFORE I ever asked for help
Leo's post shows how you can send keys to other programs from Opus. You'd need to change it to send the date or whatever it is you want to send. Or just stick with the solution you already have.
But at the moment it is AHK that turns the key combination (Shift-Z-Alt) into a command to insert date & time in my preferred format wherever I'm typing
I understand how to make system wide hotkeys in DirOpus (I hope)
Unless I have the wrong end of the stick, I don't want to send keys combinations to another program
I want a DirOpus run key combination produce the text "2020.09.04 @ 17.44 - "
That's not the same thing as sending keys, right?
Or is it?
I just wanted to try to clarify this issue since it still seems to be causing confusion.
You seem to be under the impression that "inserting text at the cursor anywhere in the system" is a built-in function of Opus.
It's not.
Opus does not have a function like that. That's a function of something like AHK.
The one way you can do it through Opus, which is what the thread Leo pointed you to described, is to use a bit of scripting to use the WScript object's SendKeys method to generate key presses.
(The WScript object is also not part of Opus. It's provided by Windows.)
When a text field is active, generating key presses (which makes it appear that you are typing on the keyboard) has the effect of inserting text at the cursor position.
So if you really want to do this through Opus, instead of AHK, you need to take the scripting example that Leo pointed you to, and adapt it to send the key presses corresponding to the text that you want to insert. You then need to set it up on a system-wide Opus hotkey so that pressing that hotkey when Opus is running triggers the script.
But again, and I can't stress this enough, this is not a function that Opus has built-in, it's not something Opus was designed to do, and if you expect it to be possible through a "one word command" you're going to be disappointed.
The actual code that sends the virtual key presses is one line (wsh.SendKeys("....")) so changing what it sends is just a matter of editing that line. If you want to send a fixed string it's trivial. If you want to send date & time as you initially asked for you will also need script code to generate that string (not difficult, but another step).
You've got to stop thinking of this as doing it with Opus though. You'd be doing it with scripting and the WScript shell object. Opus is just acting as the launcher here.
Right. Sorry about the technological inexactitude.
To ME, it does FEEL like I am doing it all through DirOpus & trying to pull everything under one roof. Want to purge my system of a hodge-podge of freeware & shareware partial solutions to all my workflow issues. (To the greatest extent possible anyway.)
I've never done any scripting before
so, for me, it IS a novel thing I'm doing in DirOpus.
I'll strive to bear in mind that it isn't, in fact, that.
What is WScript shell, then?
part of Windows or the DOS underneath?
Or, have I got totally the wrong end of the stick here?
I have a collection of about 20 key-press shortcuts for text - maybe half half changing like date, time strings
& also have just phrases like
Shift +P+L becomes
"Private & Confidential Legal Advice. If received in error, do not read"
function zfill2(n) // This function puts "0" prefix to any single-digit number.
{
return n <= 9 ? "0" + n : n;
}
function OnClick(clickData)
{
// Build our "date @ time" string
var today = new Date();
var strDate = today.getFullYear() + "." + zfill2(today.getMonth() + 1) + "." + zfill2(today.getDate());
var strTime = zfill2(today.getHours()) + "." + zfill2(today.getMinutes());
var outString = strDate + " @ " + strTime + " - ";
//DOpus.Output(outString);
// Send the "outString" to any currently active window
var wsh = new ActiveXObject("WScript.Shell");
wsh.SendKeys("^+%"); // Cancel any held modifiers to prevent garbled text.
wsh.SendKeys(outString);
}
Just to be sure, even though you already know how to do it, here are step-by-step instructions on how to bind this to a global Shift+P hotkey in Opus:
We'll use Shift+P in this example.
Just press the Shift+P key combination in the Hotkey box, we don't type it in!
Side note: @Leo can we create hotkeys with multiple modifiers, such asCtrl+Shift+P? I didn't find a way for it. Additionally, compound key combos such asCTRL + K, Vare possible for the Toolbars, but not hotkeys?
Step 4
Now you need to select a Function type. There are several possible, select the "Script Function" so that we can use the most advanced way of scripting available in the Opus.
Step 5
Under the "Script Type" make sure that the jscript is selected. We'll be using thejscriptfor this example since it offers the combination of power and modern syntax as opposed to the other available option "vbscript" which is also powerful but its syntax is archaic and I forgot it.
Delete all the template code that is already there, and replace it with the code I've given you above.
Close all the windows (OK buttons) so that our setup is saved, and try pressing the Shift+P in the Notepad, Word or anywhere there is a textbox. Sometimes it may happen that you get garbled text, that's the SendKeys issue (related to the modifier keys being held by you while text is being "sent", I've tried to mitigate it in the code, but... you know how these things go), in that case try pressing it again.
You can close all Opus windows and the global hotkey (and our script) will continue to work normally as long as there is an Opus icon in the taskbar tray (i.e., Opus process is active in the background). So Opus can replace the AHK for you.
Multiple modifiers: Yes, just type what you want as if you were activating the hotkey. If it doesn't work, something else might already be intercepting that key.
Compound keys: Should work as both toolbar and standalone hotkeys (at least as far as I know), but I doubt they'd work for system-wide hotkeys as that would require taking input focus in order to see the second keypress.