Photoshop: Script - Is there way how read if CTRL key is pressed down while script is running?

  • 1
  • Question
  • Updated 2 years ago
  • (Edited)
Hard question - Is there way how read if CTRL key is pressed down while script is running? I have scripts to improve certain functions in PS.
E.g. better layer distribution if you click on layers alignment button in toolbar. I would like have old layer distribution posibility if you click on this button with CTRL pressed down. Any chance to do that?
Photo of Jaroslav Bereza

Jaroslav Bereza

  • 809 Posts
  • 187 Reply Likes

Posted 2 years ago

  • 1
Photo of Paul Riggott

Paul Riggott

  • 359 Posts
  • 143 Reply Likes
Have a look at the  NumericEditKeyboardHandler in "Image Processor.jsx", it shows how to get what keys are pressed.
It is at the bottom of the script.
Photo of Jaroslav Bereza

Jaroslav Bereza

  • 809 Posts
  • 187 Reply Likes
I want do it for these buttons: http://sklad.bereza.cz/00-jarda/00_screenshot/2016-05-29_101859.jpg or whole Photoshop window.
Photo of Paul Riggott

Paul Riggott

  • 359 Posts
  • 143 Reply Likes
That will be extreamly difficult if at all.
You would need a c/c++ plugin using the sdk.
You could ask @ https://forums.adobe.com/community/photoshop/photoshop_sdk/content
Photo of Jaroslav Bereza

Jaroslav Bereza

  • 809 Posts
  • 187 Reply Likes
Ok thx for info.
Photo of Max Johnson

Max Johnson, Champion

  • 488 Posts
  • 235 Reply Likes
Is there a reason why the script can't check for mod-keys at the start of the script? If you are still holding ctrl when the listener triggers the .jsx, you should be able to get that, right? (making some broad assumptions here about how the script is run, too)
Photo of Jaroslav Bereza

Jaroslav Bereza

  • 809 Posts
  • 187 Reply Likes
I don't know how to do that. I think I need custom UI for check mod-keys.

Maybe I could show some invisible, traparent UI dialog for very short time and in this period get mod-keys info?
Photo of Paul Riggott

Paul Riggott

  • 359 Posts
  • 143 Reply Likes
This might be what you are after...
//app.notifiersEnabled = true;
//app.notifiers.add( "setd",new File('~/desktop/align.jsx'), "Prpr" );

try {
if (arguments.length >= 2) {
CTRL = ScriptUI.environment.keyboardState.ctrlKey;
var desc = arguments[0];
if(desc.hasKey(stringIDToTypeID('to'))){
switch(typeIDToStringID(desc.getObjectValue(stringIDToTypeID('to')).getEnumerationValue(stringIDToTypeID('align')))){
    case 'left' : leftFunction(); break;
    case 'center' : centerFunction(); break;
    case 'right' : rightFunction(); break;
    default : break;
    }
}
}
function leftFunction(){
    alert("left - Control key pessed = " + CTRL);
    }
function rightFunction(){
    alert("right - Control key pessed = " + CTRL);
    }
function centerFunction(){
    alert("center - Control key pessed = " + CTRL);
    }
}catch(e){alert(e + "\n" + e.line);}
(Edited)
Photo of Max Johnson

Max Johnson, Champion

  • 488 Posts
  • 235 Reply Likes
This sounds like exactly the thing. Checking the system keyboard instead on a UI elemet. I will probably also need this at some point. Thank you!
Photo of Jaroslav Bereza

Jaroslav Bereza

  • 806 Posts
  • 187 Reply Likes
It works! Thx a lot. When our plugin will be ready. You will get it free. ;-)