1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Photoshop | EditTextに数字以外の文字を入力できないようにする

Last updated at Posted at 2018-08-03
#target photoshop

var GUI_TEST = GUI_TEST || {};

(function() {
    var layout = "dialog { text: 'GUI TEST', \
        edt1: EditText {text: '数字のみ入力可' } \
        edt2: EditText {text: '数字とカンマのみ入力可' } \
    }";

    // 数字のみ入力を許可する
    var numericEditKeyboardHandler = function(event) {
        var key = event.keyName;
        var keyIsOK = ('0' <= key && key <= '9' && !event.shiftKey) ||
                      key == 'Left'      || key == 'Right'   ||
                      key == 'Backspace' || key == 'Delete'  ||
                      key == 'Home'      || key == 'End'     ||
                      key == 'Tab'       || key == 'Escape';
        if (!keyIsOK) {
            // keydownイベントを受け付けないようにする
            event.preventDefault();
            app.beep();
        }
    };

    // 数字とピリオドのみ入力を許可する
    var decimalEditKeyboardHandler = function(event) {
        var key = event.keyName;
        var keyIsOK = ('0' <= key && key <= '9' && !event.shiftKey) ||
                      key == 'Decimal'   || key == 'Period' ||
                      key == 'Left'      || key == 'Right'  ||
                      key == 'Backspace' || key == 'Delete' ||
                      key == 'Home'      || key == 'End'    ||
                      key == 'Tab'       || key == 'Escape';
        if (!keyIsOK) {
            // keydownイベントを受け付けないようにする
            event.preventDefault();
            app.beep();
        }
    };

    var win = new Window(layout);

    win.edt1.addEventListener('keydown', numericEditKeyboardHandler);
    win.edt2.addEventListener('keydown', decimalEditKeyboardHandler);

    win.show();
}).apply(GUI_TEST);
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?