boolean (@NotNull KeyEvent e) { char c = e.getKeyChar(); if (c == KeyEvent.CHAR_UNDEFINED) { // ignore CHAR_UNDEFINED, like Swing text components do return false; } if (c < 0x20 || c == 0x7F) { return false; } // allow input of special characters on Windows in Persian keyboard layout using Ctrl+Shift+1..4 if (SystemInfoRt.isWindows && c >= 0x200C && c <= 0x200F) { return true; } else if (SystemInfoRt.isMac) { return !e.isMetaDown() && !e.isControlDown(); } else { return !e.isAltDown() && !e.isControlDown(); } }