• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Eventhandler for national characters

Community Expert ,
Sep 12, 2022 Sep 12, 2022

Copy link to clipboard

Copied

For my script FMfindRepl I want that the user can handle occasionally long drop-down lists similar to the quick catalgoues: typing a character sequence to select the appropriate item.

It turns out that the keyName in the event handler does not give useful results for national characters (non-ASCII letters) such as the German umlauts or French accented character - which I can get on my Swiss-German keyboard with ease.

This script

 

var asItemsDe = ["Absatztyp →", "Automatischer Trennstrich", "Bedingter Text…", 
"Bedingungsformat * →", "Benutzer Zeichenkette : *", "Farbe * →", "Fußnote", 
"Irreguläres Absatzformat", "Irreguläres Objektstilformat", "Irreguläres Tabellenformat", "Irreguläres Zeichenformat", "Leere Textzeile *", "Marke – Text :", "Marke – Typ →",
"Marke (alle)", "Objektstiltag →", "Querverweis – Format →", "Querverweis (alle)", 
"Querverweis (unaufgelöst)", "Rubi", "Tabelle (alle)", "Tabellentyp →", 
"Text (formatiert) aus Zw.ablage", "Text :", "Texteinschub (alle)", 
"Texteinschub (unaufgelöst)", "Überfließende Zelle *", "Überfließender Text *", 
"Variable – Name →", "Variable (alle)", "Verankerter Rahmen", "Zeichenformat...", 
"Zeichentyp →"];
var w = new Window ("dialog", "Drop-down select");
  w.ddown = w.add ("dropdownlist", undefined, asItemsDe);
  w.ddown.minimumSize.width = 200;
  w.ddown.selection = 0;
  w.ddown.active = true;
  w.ddown.addEventListener ("keydown", Accellerator);
  w.ddown.evParm = asItemsDe;
  w.show ();

function Accellerator (oEvt) {
var k = oEvt.keyName.toLowerCase();
var aList = oEvt.currentTarget.evParm;
$.writeln(k);    // <<<<<<<<<<<<<
var   i = 0;
  while (i < aList.length-1 && asItemsDe[i].charAt(0).toLowerCase() != k) {
    ++i;
  }
  if (aList[i].charAt(0).toLowerCase() == k) {
    oEvt.currentTarget.selection = i;
  }
}

 

reports for ü → semicolon; ö → apostrophe; ä → backslash;  etc.

(after typing such a character for the first time, it is not logged immediately. You may need to type it twice to see it in the log).

Hence this property of the event object is not correct for non-english characters...

What can I do?

Views

91

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Sep 13, 2022 Sep 13, 2022

Well, at least those characters which require just one keystroke can be handled. On my Swiss keyboard these are German umlauts and some French accented characters. But characters like É which are combined by ALTGR+´ and then SHIFT+e can not be found by typing é (which is is SHIFT+ö).

  • Since in FMfindRepl I have four drop-down lists I pass the list argument to the handler. The buffer must be global, it can not be such a parameter.
  • If the list is not in alphabetical order it will be difficult to f
...

Votes

Translate

Translate
Community Expert ,
Sep 12, 2022 Sep 12, 2022

Copy link to clipboard

Copied

I have found oEvt.keyIdentifier which provides the Unicode, for example ü » U+00FC. Cutting off the U+ and converting the code to a character ... 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 13, 2022 Sep 13, 2022

Copy link to clipboard

Copied

LATEST

Well, at least those characters which require just one keystroke can be handled. On my Swiss keyboard these are German umlauts and some French accented characters. But characters like É which are combined by ALTGR+´ and then SHIFT+e can not be found by typing é (which is is SHIFT+ö).

  • Since in FMfindRepl I have four drop-down lists I pass the list argument to the handler. The buffer must be global, it can not be such a parameter.
  • If the list is not in alphabetical order it will be difficult to find some items: typing k find Kastanien. But you have no immediate knowledge about Kartoffeln. you need to know that it exists and type Kar to select it.
  • With up/down arrow keys you can further change the selection.
//@target framemaker
var KLD_Z = KLD_Z || {};                          // global script object

KLD_Z.ListSelector = function (oEvt) { // =======================================
var array, j=0, kName, kChar, kID, buffer;
  array  = oEvt.currentTarget.evParm;
  kName = oEvt.keyName.toLowerCase();
  if (kName == "down" || kName == "up") {return}
  if (kName == "backspace") {
    KLD_Z.evBuffer = KLD_Z.evBuffer.replace (/.$/, "");
  } else {
    kID = oEvt.keyIdentifier;           // U+006D → m; U+00FC → ü; U+0068 → h
    kID = kID.substring  (2);           //   006D
    kChar = parseInt(kID, 16);          //    109         252         104
    kChar = String.fromCharCode(kChar); //      m           ü           h
    kChar = kChar.toLowerCase();
    KLD_Z.evBuffer += kChar;
    while (j < array.length-1 && array[j].toLowerCase().indexOf (KLD_Z.evBuffer) != 0) {
      ++j;
    }
  }
//$.writeln (KLD_Z.evBuffer, " ", kName, " ", kID, " ", kChar, " ");
  if (array[j].toLowerCase().indexOf (KLD_Z.evBuffer) == -1) {
    oEvt.currentTarget.selection = 0;
//$.writeln ("selection = 0");
  } else {
    oEvt.currentTarget.selection = j;
//$.writeln ("selection = ", j);
  }
} // --- end ListSelector --------------------------------------------------------

KLD_Z.main = function () { // <><><><><><><><><><><><><><><><><><><><><><<><><><><
var asItems1 =[ "Anchored Frame", "Automatic Hyphen", "Character Format Override", "Character Format…",
    "Character Tag →", "Colour * →", "Condition Tag * →", "Conditional Text…", "Cross-Reference (any)",
    "Cross-Reference of Format →", "Cross-Reference (unresolved)", "Empty TextLine *", "Footnote",
    "Marker (any)", "Marker of Text :", "Marker of Type →", "Object Style Format Override",
    "Object Style Tag →", "Overflow cell *", "Overflow text *", "Paragraph Format Override",
    "Paragraph Tag →", "Rubi (any)", "Table (any)", "Table Format Override", "Table Tag →", "Text :",
    "Text Inset (any)", "Text Inset (unresolved)", "Text on Clipboard (formatted)",
    "User String : *", "Variable (any)", "Variable named →" ];
var asItems2 = ["Äpfel", "Birnen", "Beleidgte Leberwurst", "Essiggurken", "Kastanien", "Fische",
    "Fenchel", "Beeren", "Himbeeren", "Brombeeren", "Ingwer","Wassermelone", "Cavaillon Melone",
    "Muskatnuss", "Kartoffeln", "Übeltäter", "Querulant", "Rubin", "Sondanelle", "Saft", "Trauben",
     "Unkraut", "Brunnenkresse", "Öpfelschnaps", "Überreifes Obst", "Liberté", "Égalité", "Fraternité",
     "Ñiño", "Zahnweh"];

var w = new Window ("dialog", "Listbox select");
  w.orientation = "row";
  w.g1 = w.add ("group", undefined);              // optional for dropdownlist
  w.g1.list = w.g1.add ("dropdownlist", undefined, asItems1);
  w.g1.list.minimumSize.width = 200;
  w.g1.list.onActivate = w.g1.list.onDeactivate = function () {KLD_Z.evBufferr = ""; }
  w.g1.list.addEventListener  ("keydown", KLD_Z.ListSelector);
  w.g1.list.evParm = asItems1;

  w.g2 = w.add ("group", undefined);              // required for listbox
  w.g2.list = w.g2.add ("listbox", undefined, asItems2);
  w.g2.list.minimumSize.width = 200;
  w.g2.list.onActivate = w.g2.list.onDeactivate = function () {KLD_Z.evBuffer = ""; }
  w.g2.list.addEventListener  ("keydown", KLD_Z.ListSelector);
  w.g2.list.evParm = asItems2;
  w.show ();
} //--- end main -----------------------------------------------------------------

KLD_Z.main ();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines