Check if CTRL is pressed

In my toolbar I have a button for Notepad:

Now, i would like to distinguish between the following scenarios:

  • If I click on the Notepad-Button, then open the Notepad with the selected file. This I achieve as follows:
cd %USERPROFILE%
@async:"C:\PortableApps\Notepad++\notepad++.exe" "{filepath}" 

Now, i would expand the script to do this:

  • If the CTRL-key is pressed during clicking the button, then just open Notepad (without the selected file)

This was my first approach using JScript:

function OnClick(clickData)
{

	var exeNotepad = "C:\\PortableApps\\Notepad++\\notepad++.exe";
	if (clickData.func.qualifiers == "ctrl") {
		var strCmd = '"' + exeNotepad + '" "' + filepath + '"';
	   	DOpus.Output(strCmd);
		clickData.func.command.RunCommand(strCmd);
	} else {
		var strCmd = '"' + exeNotepad + '"';
		DOpus.Output(strCmd);
	    clickData.func.command.RunCommand(strCmd);
	}
	
}

No, I got the error, that "filepath" is unknown. So, how can i use {filepath} in JavaScript?

Please bear with me, these are really my first attempts at script programming with DOPUS.

No need for scripting in this case. You can use @keydown in a non-script command:

cd %USERPROFILE%
@keydown:!ctrl
@async:"C:\PortableApps\Notepad++\notepad++.exe" "{filepath}"
@keydown:ctrl
@async:"C:\PortableApps\Notepad++\notepad++.exe"

Thank you, Leo. It works like a charm.

Only for learning purpose and if it does not take too much of your time: How would I concatenate the string in JavaScript:

var strCmd = 'Notepad.exe' + {filepath};

How can I access the value of {filepath}?

Have a look at the example/default script that you get when creating a new button and switching it to script mode. It shows how to use Opus's scripting objects to get filepaths etc.

Things like {filepath} only work in commands, not the script code itself. You can use it as part of a command line, but you'd just literally include it in the string, not convert it to an actual filepath. To get the filepath as a scripting variable, you'd use the scripting objects instead.

Thank you very much, Leo. I see this for the first time. Shame on me.