Skip to main content
Innotex Nico Tanne
Inspiring
September 24, 2024
Answered

Block Backspace Key while Script is open

  • September 24, 2024
  • 2 replies
  • 415 views
Hi, i need a little Help 😅
 
i have a UI window with edittext fields, but whe i press backspace, it deletes my layers and not the text in my edittext field.
thats why i want to block Backspace and Delete key.
The Delete Key Works fine but the Backspace key will only block if you have no Layers?!
 
do you have any idea for me? 🙏
 

 

window.addEventListener("keydown", function(event) {if (event.keyName === "Backspace") {event.preventDefault();alert("Backspace key pressed");}});
window.addEventListener("keydown", function(event) {if (event.keyName === "Delete") {event.preventDefault();}});

 

This topic has been closed for replies.
Correct answer Innotex Nico Tanne

Hej,

i think its because my window is defined as a Palette.

a Dialog Window blocks all interactions to Photoshop as it should, but you loose the flexibility of a palette. 

i fixed it with a dialog window popup if textfiled is active and it works fine for me 🙂

function openInputDialog(edittext) {
    var inputDialog = new Window("dialog", "Eingabewert " /* + edittext.text*/);
    var inputText = inputDialog.add("edittext", undefined, edittext.text);
    inputText.characters = 20;
    inputText.active = true;
    inputText.selection = [0, inputText.text.length];
    inputDialog.add("button", undefined, "OK", {name: "ok"});
    if (inputDialog.show() == 1) {
        edittext.text = inputText.text;
    }
}
edittext1.onActivate = function() {openInputDialog(edittext1);};
edittext2.onActivate = function() {openInputDialog(edittext2);};
edittext3.onActivate = function() {openInputDialog(edittext3);};
edittext4.onActivate = function() {openInputDialog(edittext4);};
edittext5.onActivate = function() {openInputDialog(edittext5);};
edittext6.onActivate = function() {openInputDialog(edittext6);};
edittext7.onActivate = function() {openInputDialog(edittext7);};
edittext8.onActivate = function() {openInputDialog(edittext8);};

 

 

2 replies

Innotex Nico Tanne
Inspiring
September 24, 2024

Thank you for your answer!

I will post the code tomorrow.

it must only block backspace when im in the edittext field. Evertyime i want to change my values an delete the old values it deletes my layers and not the text values from the edittext?! This is the only case wich should block backspace. I dont understand that the delete key if working fine when im in the edittext field.

Legend
September 24, 2024

Post the script that puts up the modal window. This is not about blocking keystrokes, something else is wrong.

Do you have any apps running that would intercept keystrokes?

Innotex Nico Tanne
Innotex Nico TanneAuthorCorrect answer
Inspiring
September 25, 2024

Hej,

i think its because my window is defined as a Palette.

a Dialog Window blocks all interactions to Photoshop as it should, but you loose the flexibility of a palette. 

i fixed it with a dialog window popup if textfiled is active and it works fine for me 🙂

function openInputDialog(edittext) {
    var inputDialog = new Window("dialog", "Eingabewert " /* + edittext.text*/);
    var inputText = inputDialog.add("edittext", undefined, edittext.text);
    inputText.characters = 20;
    inputText.active = true;
    inputText.selection = [0, inputText.text.length];
    inputDialog.add("button", undefined, "OK", {name: "ok"});
    if (inputDialog.show() == 1) {
        edittext.text = inputText.text;
    }
}
edittext1.onActivate = function() {openInputDialog(edittext1);};
edittext2.onActivate = function() {openInputDialog(edittext2);};
edittext3.onActivate = function() {openInputDialog(edittext3);};
edittext4.onActivate = function() {openInputDialog(edittext4);};
edittext5.onActivate = function() {openInputDialog(edittext5);};
edittext6.onActivate = function() {openInputDialog(edittext6);};
edittext7.onActivate = function() {openInputDialog(edittext7);};
edittext8.onActivate = function() {openInputDialog(edittext8);};

 

 

Legend
September 24, 2024

Photoshop runs ExtendScript as model, meaning that the script window should accept keystrokes and not pass them through. Please post the entire script that is not working.