diff --git a/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts b/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts index 551d14c246..87288b93af 100644 --- a/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts +++ b/developer/src/kmc-convert/src/keylayout-to-kmn/keylayout-to-kmn-converter.ts @@ -8,47 +8,47 @@ import { ConverterToKmnArtifacts } from "../converter-artifacts.js"; /*import { util } from '@keymanapp/common-types'; //_S2 import boxXmlArray = util.boxXmlArray;*/ +{ + // TODO keylayout->kmn + // OK modifiers: The identifier of the element to use for this range of hardware keyboard types. + // OK defaultIndex: The table number to use for modifier key combinations which are not explicitly specified by any element within the . + // write read, convert, write + // tests for 3 functions read write convert + // add data to object + // Use filter functions + // action/output:use filter etc to shorten func + // deadkeyables:use filter etc to shorten func + // dk-> for all action:use filter etc to shorten func + // remove unneccessary data from dataObject + // rename symbols + // OK remove part using kmn_key_Name1 + // OK remove unnecceaasry map_UkeleleKC_To_kmn_Key_Name_Array_Position_n etc + // OK loop throught ANSI, JIS- at moment only use [keyMapSet_count] (keyMapSet_count=0) + // OK remove funcs at teh end + // import { makePathToFixture } from '../../test/helpers/index.js'; + // OK Mapping 0->30 or 0->K_A-> missing entries in mapping + // OK Replace any-types + // Several steps action-> action-> action->character ( not only action->character) + // TODO waht about using actions twice in a row??? + // Usable for all keylayout files + // Return conditions + // Use callbacks as for writeFileSync + // Tests throws + // Conditions NCAPS,OPT;... + // TODO move func outside of class + // Functions as object methods? + // objects contain only used stuff READ in: -- out: only read arrays / CONVERT in: only read arrays out: return only to write arrays + // Use catch blocks for file read + // read: answer : + [K_A] > 'a' is OK / TODO which format to use in output ? + [K_A] > 'a' (character code) or + [K_A] > U+0061 (virt Keycode) + // read TODO which stores? + // one entry vs several entry in tags + // false arrangement of tags + // no added NCAPS when first modifier in modifierMap does not contain "caps" or"caps?" + // use length to clear array instead of defining evetry time new (modifierMap_ONE_InKeymapSelect.length=0 + // naming of for-loop var i,j,k?... + // warning if contrADICTING RULES E:G: [ 'modifier_C0', 'SHIFT NCAPS', 'K_C', 'c', '0', '1' ], vs [ 'modifier_C0', 'SHIFT NCAPS', 'K_C', 'C', '1', '0' ], -// TODO keylayout->kmn -// OK modifiers: The identifier of the element to use for this range of hardware keyboard types. -// OK defaultIndex: The table number to use for modifier key combinations which are not explicitly specified by any element within the . -// write read, convert, write -// tests for 3 functions read write convert -// add data to object -// Use filter functions -// action/output:use filter etc to shorten func -// deadkeyables:use filter etc to shorten func -// dk-> for all action:use filter etc to shorten func -// remove unneccessary data from dataObject -// rename symbols -// OK remove part using kmn_key_Name1 -// OK remove unnecceaasry map_UkeleleKC_To_kmn_Key_Name_Array_Position_n etc -// OK loop throught ANSI, JIS- at moment only use [keyMapSet_count] (keyMapSet_count=0) -// OK remove funcs at teh end -// import { makePathToFixture } from '../../test/helpers/index.js'; -// OK Mapping 0->30 or 0->K_A-> missing entries in mapping -// OK Replace any-types -// Several steps action-> action-> action->character ( not only action->character) -// TODO waht about using actions twice in a row??? -// Usable for all keylayout files -// Return conditions -// Use callbacks as for writeFileSync -// Tests throws -// Conditions NCAPS,OPT;... -// TODO move func outside of class -// Functions as object methods? -// objects contain only used stuff READ in: -- out: only read arrays / CONVERT in: only read arrays out: return only to write arrays -// Use catch blocks for file read -// read: answer : + [K_A] > 'a' is OK / TODO which format to use in output ? + [K_A] > 'a' (character code) or + [K_A] > U+0061 (virt Keycode) -// read TODO which stores? -// one entry vs several entry in tags -// false arrangement of tags -// no added NCAPS when first modifier in modifierMap does not contain "caps" or"caps?" -// use length to clear array instead of defining evetry time new (modifierMap_ONE_InKeymapSelect.length=0 -// naming of for-loop var i,j,k?... -// warning if contrADICTING RULES E:G: [ 'modifier_C0', 'SHIFT NCAPS', 'K_C', 'c', '0', '1' ], vs [ 'modifier_C0', 'SHIFT NCAPS', 'K_C', 'C', '1', '0' ], - - +} import { XMLParser } from 'fast-xml-parser'; // for reading a file import { readFileSync } from 'fs'; @@ -56,7 +56,7 @@ import { readFileSync } from 'fs'; //import * as fs from 'fs'; // what is this/do I need it? - either import all or seperately like above - +// todo use from elsewhere function boxXmlArray_S(o: any, x: string): void { if (typeof o == 'object' && !Array.isArray(o[x])) { if (o[x] === null || o[x] === undefined) { @@ -130,7 +130,6 @@ export interface convert_object { ArrayOf_processed_deadkeyables: string[][], // add char that can be modified with dk ( a,e,i,o,u) ArrayOf_processed_deadkeyedChar: string[][], // add modified keys ( â,ê,î,ô,û) ArrayOf_processed_RuleData: Uint8Array[][] // add modified keys ( â,ê,î,ô,û) - ArrayOf_processed_RuleDataStr: String[][] // add modified keys ( â,ê,î,ô,û) }; @@ -158,7 +157,7 @@ export class KeylayoutToKmnConverter { } console.log(' _S2 first READ file ........................................in:', inputFilename); - const inArray: convert_object = this.read_old(inputFilename) + const inArray: convert_object = this.read(inputFilename) if (!inArray) { return null; @@ -198,316 +197,6 @@ export class KeylayoutToKmnConverter { }; - console.log("xmlFile_name", (process.cwd() + "\\data" + filename.substring(filename.lastIndexOf("\\"))).replace(" ", "")) - //const xmlFile = readFileSync(`${process.cwd()}/data/MySample.keylayout`, 'utf8') - const xmlFile = readFileSync((process.cwd() + "\\data" + filename.substring(filename.lastIndexOf("\\"))).replace(" ", ""), 'utf8'); - - // we don`t need file-read with uint8array return - /*const fullPath = (process.cwd() + "\\data" + filename.substring(filename.lastIndexOf("\\"))).replace(" ", "") - const xmlFile1 = this.callbacks.loadFile(fullPath) - console.log("xmlFile1",xmlFile1)*/ - - console.log("layouts_array read ") - const parser = new XMLParser(options); - const jsonObj = parser.parse(xmlFile); // get plain Object - boxArrays_S(jsonObj.keyboard); - - const modifierMap_ALL_KeyMapSelects: string[][] = [] // modifier for each keymapselect - const modifierMap_all_Layers: string[] = [] // array holding all MODIFIER strings e.g. "anyShift caps anyOption" -why not put modifiers into Uint8Array along with values of keys of layer - const keys_output_all_Layers: Uint8Array[][] = [] - const keys_action_all_Layers: Uint8Array[][] = [] // array holding all values with ACTION attribute (needed for finding deadkeys) - const terminators_all_Layers: Uint8Array[] = [] // array holding all DEADKEYS for each mod state â, ê, ,.... - const duplicate_layouts_array: string[] = [] // array holding the layouts e.g. ANSI or JIS // needed?? I think no - const deadkeyedChars_all_Layers: string[][] = [] // array holding all DEADKEYS for each mod state â, ê, ,.... - const kmn_Rules_AllLayers: Uint8Array[][] = [] - const kmn_Rules_AllLayersStr: string[][] = [] - let dk_pairs_all_Layers: string[][] = [] // add dk-mapping ( dk1 <-> '^' ) - - - // fill arrays - // TODO call: get only ANSI - // Do I need to care or is there always ANSI which is always keyMapSet[0] - // if so code can be shortened - // ......................................................... - // LAYOUTS: get all groups like ANSI JIS, remove JIS - // ......................................................... - - // in case we need to find ANSI - for (let i = 0; i < jsonObj.keyboard.layouts.layout.length; i++) { - duplicate_layouts_array[i] = jsonObj.keyboard.layouts.layout[i]['@_mapSet'] - } - - // remove duplicates from array - const layouts_array_both: any[] = duplicate_layouts_array.filter(function (item, pos, self) { - return self.indexOf(item) == pos; - }) - - // use only ANSI - the first element - const layouts_array: any[] = layouts_array_both.filter(function (item, pos, self) { - return self.indexOf(item) == 0; - }) - - // in case there always ANSI which is always keyMapSet[0] - //const layouts_array: string[] = duplicate_layouts_array - const keyMapSet_count = 0 - - //#### end layouts ############################################################################################################################################### - - for (let j = 0; j < jsonObj.keyboard.modifierMap.keyMapSelect.length; j++) { - const modifierMap_ONE_InKeymapSelect: string[] = [] - - for (let k = 0; k < jsonObj.keyboard.modifierMap.keyMapSelect[j].modifier.length; k++) { - modifierMap_all_Layers.push(jsonObj.keyboard.modifierMap.keyMapSelect[j].modifier[k]['@_keys']) - modifierMap_ONE_InKeymapSelect.push(jsonObj.keyboard.modifierMap.keyMapSelect[j].modifier[k]['@_keys']) - } - modifierMap_ALL_KeyMapSelects.push(modifierMap_ONE_InKeymapSelect) - - // create a new array of keys_in_Layer (type Uint8tarray) - const keys_output_One_Layer: Uint8Array[] = [] - const keys_action_One_Layer: Uint8Array[] = [] - - //#### end modifierMap ############################################################################################################################################### - - // ......................................................... - // KEYMAP: get all keys for attribute "output" ( y,c,b,...) - // output type Uint8Array -> string - // ......................................................... - for (let i = 0; i < jsonObj.keyboard.keyMapSet[keyMapSet_count].keyMap[j].key.length; i++) { - if (jsonObj.keyboard.keyMapSet[keyMapSet_count].keyMap[j].key[i]['@_output'] !== "\0") { - // textencoder converts string -> bytes ( 'A' -> [ 65 ], '☺' -> [ 226, 152, 186 ]) - // textencoder is of Uint8Array(1) for A and Uint8Array(3) for ☺ - keys_output_One_Layer[i] = new TextEncoder().encode(jsonObj.keyboard.keyMapSet[keyMapSet_count].keyMap[j].key[i]['@_output']); - } - // ToDo do I need empty fields in keys_output_all_Layers, keys_action_all_Layers - // ......................................................... - // KEYMAP: get all keys for attribute "action" ( ^,a,e,i,...) - // action type Uint8Array -> string - // ......................................................... - if (jsonObj.keyboard.keyMapSet[keyMapSet_count].keyMap[j].key[i]['@_action'] !== "\0") { - keys_action_One_Layer[i] = new TextEncoder().encode(jsonObj.keyboard.keyMapSet[keyMapSet_count].keyMap[j].key[i]['@_action']); - } - } - - // ......................................................... - // create array of "action" and array of "output" - keys_output_all_Layers.push(keys_output_One_Layer) // save all @output data ( will be used for conversion, write...) - keys_action_all_Layers.push(keys_action_One_Layer) // save all @action data ( will be used for deadkeys) - //#### end output+action ############################################################################################################################################### - } - - // ......................................................... - // ACTION: create array of "deadkey" / "deadkey names" - // action type string[] -> string[][] - // ......................................................... - const dk_pairs_all_Layers_max: string[][] = [] - // here replace with function to find - // C3 state none + next Nr => deadkeys - console.log("--------------------------------") - - // loop through actions and get the value of attribute "next" (which indicates this is a deadkey) - for (let jj = 0; jj < jsonObj.keyboard.actions.action.length; jj++) { - for (let kk = 0; kk < jsonObj.keyboard.actions.action[jj].when.length; kk++) { - - if (jsonObj.keyboard.actions.action[jj].when[kk]['@_next'] !== undefined) { - const vec1d: string[] = [] - let dk_to_print - - const text_attribute_next = jsonObj.keyboard.actions.action[jj].when[kk]['@_next'] - - // loop through terminators and get output of that next state - for (let n = 0; n < jsonObj.keyboard.terminators.when.length; n++) { - if (jsonObj.keyboard.terminators.when[n]['@_state'] === text_attribute_next) - dk_to_print = jsonObj.keyboard.terminators.when[n]['@_output'] - } - - vec1d.push(text_attribute_next) - vec1d.push(dk_to_print) - vec1d.push(jsonObj.keyboard.actions.action[jj]['@_id']) // todo remove later - dk_pairs_all_Layers_max.push(vec1d) - } - } - } - dk_pairs_all_Layers = dk_pairs_all_Layers_max.filter(function (item, pos, self) { - return self.indexOf(item) == pos; - }) - console.log("dk_pairs_all_Layers", dk_pairs_all_Layers) - const dk: string[] = []; - - // ......................................................... - // ACTION: create array of "deadkeyables_all_Layers" - TODO can i use shorter function? - // deadkeyables_one type Uint8Array -> string[][] - // ......................................................... - const deadkeyables_all_Layers: string[][] = [] - const action_name = "" - // needed? we just want ANSI = the first one - for (let j = 0; j < jsonObj.keyboard.keyMapSet[keyMapSet_count].keyMap.length; j++) { - const deadkeyables_one: string[] = [] - // loop through all keys of ANSI 109 - /*for (let i = 0; i < jsonObj.keyboard.keyMapSet[keyMapSet_count].keyMap[0].key.length; i++) { - - let dk_char - // find output in action id 20 - for (let jj = 0; jj < jsonObj.keyboard.actions.action.length; jj++) { - - // find the action ID which was specified in keymap->key->action e.g. a19 - action_name = new TextDecoder().decode(keys_action_all_Layers[j][i]) - - if (action_name !== "") { - // find action id in actions->action e.g. a19 - if (jsonObj.keyboard.actions.action[jj]['@_id'] === action_name) { - - //a85 - - // 4 cases: - // C1 state none + output => - // C2 state Nr + output => - // OK C3 state none + next Nr => deadkeys see above - // C4 state Nr + next Nr => loop deadkeyables - - - const mytestVar = this.get_Terminator_Output_from_Next(jsonObj.keyboard, "a16", '@_state', '@_output') - console.log("mytestVar", mytestVar) - - if (jsonObj.keyboard.actions.action[jj].when[0]['@_state'] === "none") { - dk_char = jsonObj.keyboard.actions.action[jj].when[0]['@_output'] - console.log("++++++++++++++++++++++dk_char", j, i, jj, "action_name", action_name, - jsonObj.keyboard.actions.action[jj].when[0], "===>", dk_char, "mytestVar", mytestVar) - - // if @_next instead of @_output - // loop again - // and again... again...( -> recursive func!!) - } - } - } - } - - // fills correct entries into modifier 1-3 then false ( because of no action any more) - - //const resulting_character = new TextDecoder().decode(keys_action_all_Layers[j][i]) - const resulting_character = dk_char - - if (resulting_character !== "") - deadkeyables_one.push(resulting_character) - } -*/ - - - - - - - - for (let k = 0; k < dk_pairs_all_Layers.length; k++) { - dk.push(dk_pairs_all_Layers[k][1]) - } - - if (deadkeyables_one.length !== 0) { - deadkeyables_all_Layers.push(deadkeyables_one) - } - } - - - console.log("ction_name", action_name) - //console.log("deadkeyables_all_Layers before",deadkeyables_all_Layers) - for (let j = 0; j < deadkeyables_all_Layers.length; j++) { - // filter out dk -> plain deadkeyables_all_Layers ( a,^, e,i,´,u => a,e,i,u) - // return all that don`t find ^,´, ` - deadkeyables_all_Layers[j] = deadkeyables_all_Layers[j].filter(function (el) { - return dk.indexOf(el) < 0; - }); - - } - //console.log("deadkeyables_all_Layers after", deadkeyables_all_Layers) - - //double not needed??? - // ......................................................... - // TERMINATOR: create array of "terminators" - TODO can i use shorter function? what element of terminators do i need - // terminators when state type Uint8Array[] - // ......................................................... - for (let i = 0; i < jsonObj.keyboard.terminators.when.length; i++) { - terminators_all_Layers[i] = jsonObj.keyboard.terminators.when[i] - } - - // ......................................................... - // TODO can i use shorter function? -> yes use terminators, filter, map or reduce - - // this addresses state+output and none+output - // but not state+next or none+next - - // loop through all dk, key-actions and find @_action - // find this value in - // in their 'when' find output for dk - // for all 'action' at keys paragraph - - - for (let j = 0; j < dk_pairs_all_Layers.length; j++) { - - const deadkeys_One_dk: string[] = [] - // find in action e.g. - for (let k = 0; k < keys_action_all_Layers[j].length; k++) { - - const action_from_keys_prargraph = new TextDecoder().decode(keys_action_all_Layers[j][k]) - if (action_from_keys_prargraph !== "") { - // find the same id (e.g. ) in the actions-paragraph - for (let l = 0; l < jsonObj.keyboard.actions.action.length; l++) { - - if (jsonObj.keyboard.actions.action[l]['@_id'] === action_from_keys_prargraph) { - // loop through when until dk name (e.g. dk s0) - for (let m = 0; m < jsonObj.keyboard.actions.action[l].when.length; m++) { - - // and get their @_output - if (jsonObj.keyboard.actions.action[l].when[m]['@_state'] === dk_pairs_all_Layers[j][0]) { - // todo push only if @output is found. if next is found: get value from terminators - //if (typeof jsonObj.keyboard.actions.action[l].when[m]['@_output'].property !== 'undefined') - deadkeys_One_dk.push(jsonObj.keyboard.actions.action[l].when[m]['@_output']) - //else - //console.log(deadkeys_One_dk, "§§§§§§ PROP UNDEFINED", j, "-", k, "-", l, "-", m, "-", dk_pairs_all_Layers[j][0], jsonObj.keyboard.actions.action[l].when[m].property) - } - } - } - } - } - } - // console.log("deadkeys_One_dk", deadkeys_One_dk) - deadkeyedChars_all_Layers.push(deadkeys_One_dk) - - //console.log("deadkeyedChars_all_Layers", deadkeyedChars_all_Layers) - } - - - const vk: (string | number)[][] = [] - // TODO remove unneccassary elements - const DataObject: convert_object = { - name: "Ukelele-kmn", // needed?? remove - ArrayOf_Element_Layouts: layouts_array, // needed?? I think no - ArrayOf_Element_KeyOutput: keys_output_all_Layers, - ArrayOf_Element_KeyAction: keys_action_all_Layers, - ArrayOf_Element_ALL_ModifierMaps: modifierMap_all_Layers, // all 18 modifiers in 1 array - ArrayOf_Element_ModifierMaps_ALLKeyMapSelect: modifierMap_ALL_KeyMapSelects, // 18 modifiers in 8 KeyMapSelect(behaviors) - ArrayOf_Element_Terminators: terminators_all_Layers, // add terminators ( ^,´,`) - ArrayOf_processed_VK_from_keylayout: vk, - ArrayOf_processed_dk: dk_pairs_all_Layers, // add dk-mapping ( dk1 <-> '^' ) - - ArrayOf_processed_deadkeyables: deadkeyables_all_Layers, // add char that can be modified with dk ( a,e,i,o,u) - ArrayOf_processed_deadkeyedChar: deadkeyedChars_all_Layers, // add modified keys ( â,ê,î,ô,û) - ArrayOf_processed_RuleData: kmn_Rules_AllLayers, - ArrayOf_processed_RuleDataStr: kmn_Rules_AllLayersStr - }; - - // TODO review condition - return DataObject - //return ((keys_output_all_Layers.length === nrOfStates + 5) && keys_output_all_Layers[0].length === nrOfKeys_inLayer) ? keys_output_all_Layers : null; - } - - public read_old(filename: string): convert_object { - - console.log("inputFilename read", filename) - const options = { - ignoreAttributes: false, - attributeNamePrefix: '@_' // to access the attribute - }; - - console.log("xmlFile_name", (process.cwd() + "\\data" + filename.substring(filename.lastIndexOf("\\"))).replace(" ", "")) //const xmlFile = readFileSync(`${process.cwd()}/data/MySample.keylayout`, 'utf8') const xmlFile = readFileSync((process.cwd() + "\\data" + filename.substring(filename.lastIndexOf("\\"))).replace(" ", ""), 'utf8'); @@ -529,7 +218,6 @@ export class KeylayoutToKmnConverter { const duplicate_layouts_array: string[] = [] // array holding the layouts e.g. ANSI or JIS // needed?? I think no const deadkeyedChars_all_Layers: string[][] = [] // array holding all DEADKEYS for each mod state â, ê, ,.... const kmn_Rules_AllLayers: Uint8Array[][] = [] - const kmn_Rules_AllLayersStr: string[][] = [] let dk_pairs_all_Layers: string[][] = [] // add dk-mapping ( dk1 <-> '^' ) boxArrays_S(jsonObj.keyboard); @@ -562,6 +250,9 @@ export class KeylayoutToKmnConverter { //#### end layouts ############################################################################################################################################### + // ......................................................... + // MODIFIER MAP: get behaviours(=MapIndex) and modifiers (shift? leftShift caps? ) + // ......................................................... for (let j = 0; j < jsonObj.keyboard.modifierMap.keyMapSelect.length; j++) { const modifierMap_ONE_InKeymapSelect: string[] = [] @@ -570,17 +261,20 @@ export class KeylayoutToKmnConverter { modifierMap_ONE_InKeymapSelect.push(jsonObj.keyboard.modifierMap.keyMapSelect[j].modifier[k]['@_keys']) } modifierMap_ALL_KeyMapSelects.push(modifierMap_ONE_InKeymapSelect) + } + //#### end modifierMap ############################################################################################################################################### + + for (let j = 0; j < jsonObj.keyboard.modifierMap.keyMapSelect.length; j++) { // create a new array of keys_in_Layer (type Uint8tarray) const keys_output_One_Layer: Uint8Array[] = [] const keys_action_One_Layer: Uint8Array[] = [] - //#### end modifierMap ############################################################################################################################################### - // ......................................................... - // KEYMAP: get all keys for attribute "output" ( y,c,b,...) - TODO can i use shorter function? + // KEYMAP - OUTPUT : get all keys for attribute "output" ( y,c,b,...) - TODO can i use shorter function? // output type Uint8Array -> string // ......................................................... + // loop keys for (let i = 0; i < jsonObj.keyboard.keyMapSet[keyMapSet_count].keyMap[j].key.length; i++) { if (jsonObj.keyboard.keyMapSet[keyMapSet_count].keyMap[j].key[i]['@_output'] !== "\0") { // textencoder converts string -> bytes ( 'A' -> [ 65 ], '☺' -> [ 226, 152, 186 ]) @@ -589,10 +283,10 @@ export class KeylayoutToKmnConverter { } // ToDo do I need empty fields in keys_output_all_Layers, keys_action_all_Layers // ......................................................... - // KEYMAP: get all keys for attribute "action" ( ^,a,e,i,...) - TODO can i use shorter function? + // KEYMAP - ACTION: get all keys for attribute "action" ( ^,a,e,i,...) - TODO can i use shorter function? // action type Uint8Array -> string // ......................................................... - if (jsonObj.keyboard.keyMapSet[keyMapSet_count].keyMap[j].key[i]['@_action'] !== "\0") { + else if (jsonObj.keyboard.keyMapSet[keyMapSet_count].keyMap[j].key[i]['@_action'] !== "\0") { keys_action_One_Layer[i] = new TextEncoder().encode(jsonObj.keyboard.keyMapSet[keyMapSet_count].keyMap[j].key[i]['@_action']); } } @@ -676,9 +370,6 @@ export class KeylayoutToKmnConverter { // C4 state Nr + next Nr => loop deadkeyables - /*const mytestVar = this.get_Terminator_Output_from_Next(jsonObj.keyboard, "a16", '@_state', '@_output') - console.log("mytestVar", mytestVar)*/ - if (jsonObj.keyboard.actions.action[jj].when[0]['@_state'] === "none") { dk_char = jsonObj.keyboard.actions.action[jj].when[0]['@_output'] /* console.log("++++++++++++++++++++++dk_char", j, i, jj, "action_name", action_name, @@ -740,7 +431,7 @@ export class KeylayoutToKmnConverter { // for all 'action' at keys paragraph // ToDo URTGENT duplicate dk ????? - + // todo use lookup functions for (let j = 0; j < dk_pairs_all_Layers.length; j++) { //for (let j = 0; j < keys_action_all_Layers.length; j++) { const deadkeys_One_dk: string[] = [] @@ -791,328 +482,25 @@ export class KeylayoutToKmnConverter { ArrayOf_Element_Terminators: terminators_all_Layers, // add terminators ( ^,´,`) ArrayOf_processed_VK_from_keylayout: vk, ArrayOf_processed_dk: dk_pairs_all_Layers, // add dk-mapping ( dk1 <-> '^' ) - ArrayOf_processed_deadkeyables: deadkeyables_all_Layers, // add char that can be modified with dk ( a,e,i,o,u) ArrayOf_processed_deadkeyedChar: deadkeyedChars_all_Layers, // add modified keys ( â,ê,î,ô,û) - ArrayOf_processed_RuleData: kmn_Rules_AllLayers, - ArrayOf_processed_RuleDataStr: kmn_Rules_AllLayersStr + ArrayOf_processed_RuleData: kmn_Rules_AllLayers }; - const filled_Data = this.collect_Data_From_File(DataObject, jsonObj) + // Todo ? move to convert? + // move up instead of action/output? + // do i need to return a value? + const rule_Data = this.createRuleData(DataObject, jsonObj) - console.log("filled_Data-len", filled_Data.length) - console.log("filled_Data", filled_Data) + console.log("rule_Data-lenU8", rule_Data.ArrayOf_processed_RuleData.length) + console.log("rule_Data_U8", rule_Data.ArrayOf_processed_RuleData) // TODO review condition - return filled_Data - return DataObject + return rule_Data //return ((keys_output_all_Layers.length === nrOfStates + 5) && keys_output_all_Layers[0].length === nrOfKeys_inLayer) ? keys_output_all_Layers : null; } - public read_backup_runableMinimalVersion(filename: string): convert_object { - - console.log("inputFilename read", filename) - const options = { - ignoreAttributes: false, - attributeNamePrefix: '@_' // to access the attribute - }; - - - console.log("xmlFile_name", (process.cwd() + "\\data" + filename.substring(filename.lastIndexOf("\\"))).replace(" ", "")) - //const xmlFile = readFileSync(`${process.cwd()}/data/MySample.keylayout`, 'utf8') - const xmlFile = readFileSync((process.cwd() + "\\data" + filename.substring(filename.lastIndexOf("\\"))).replace(" ", ""), 'utf8'); - - // we don`t need file-read with uint8array return - /*const fullPath = (process.cwd() + "\\data" + filename.substring(filename.lastIndexOf("\\"))).replace(" ", "") - const xmlFile1 = this.callbacks.loadFile(fullPath) - console.log("xmlFile1",xmlFile1)*/ - - - console.log("layouts_array read ") - const parser = new XMLParser(options); - const jsonObj = parser.parse(xmlFile); // get plain Object - const modifierMap_ALL_KeyMapSelects: string[][] = [] // modifier for each keymapselect - const modifierMap_all_Layers: string[] = [] // array holding all MODIFIER strings e.g. "anyShift caps anyOption" -why not put modifiers into Uint8Array along with values of keys of layer - const keys_output_all_Layers: Uint8Array[][] = [] - const keys_action_all_Layers: Uint8Array[][] = [] // array holding all values with ACTION attribute (needed for finding deadkeys) - const terminators_all_Layers: Uint8Array[] = [] // array holding all DEADKEYS for each mod state â, ê, ,.... - const duplicate_layouts_array: string[] = [] // array holding the layouts e.g. ANSI or JIS // needed?? I think no - const deadkeyedChars_all_Layers: string[][] = [] // array holding all DEADKEYS for each mod state â, ê, ,.... - const kmn_Rules_AllLayers: Uint8Array[][] = [] - const kmn_Rules_AllLayersStr: string[][] = [] - let dk_pairs_all_Layers: string[][] = [] // add dk-mapping ( dk1 <-> '^' ) - - boxArrays_S(jsonObj.keyboard); - - // fill arrays - // TODO call: get only ANSI - // Do I need to care or is there always ANSI which is always keyMapSet[0] - // if so code can be shortened - // ......................................................... - // LAYOUTS: get all groups like ANSI JIS, remove JIS - // ......................................................... - - // in case we need to find ANSI - for (let i = 0; i < jsonObj.keyboard.layouts.layout.length; i++) { - duplicate_layouts_array[i] = jsonObj.keyboard.layouts.layout[i]['@_mapSet'] - } - - // remove duplicates - const layouts_array: any[] = duplicate_layouts_array.filter(function (item, pos, self) { - return self.indexOf(item) == pos; - }) - // remove JIS (if keyMap contains baseMapSet it`s JIS) - for (let i = 0; i < layouts_array.length; i++) { - if (jsonObj.keyboard.keyMapSet[i].keyMap[0]['@_baseMapSet']) - layouts_array.splice(i, 1); - } - // in case there always ANSI which is always keyMapSet[0] - //const layouts_array: string[] = duplicate_layouts_array - const keyMapSet_count = 0 - - //#### end layouts ############################################################################################################################################### - - for (let j = 0; j < jsonObj.keyboard.modifierMap.keyMapSelect.length; j++) { - const modifierMap_ONE_InKeymapSelect: string[] = [] - - for (let k = 0; k < jsonObj.keyboard.modifierMap.keyMapSelect[j].modifier.length; k++) { - modifierMap_all_Layers.push(jsonObj.keyboard.modifierMap.keyMapSelect[j].modifier[k]['@_keys']) - modifierMap_ONE_InKeymapSelect.push(jsonObj.keyboard.modifierMap.keyMapSelect[j].modifier[k]['@_keys']) - } - modifierMap_ALL_KeyMapSelects.push(modifierMap_ONE_InKeymapSelect) - - // create a new array of keys_in_Layer (type Uint8tarray) - const keys_output_One_Layer: Uint8Array[] = [] - const keys_action_One_Layer: Uint8Array[] = [] - - //#### end modifierMap ############################################################################################################################################### - - // ......................................................... - // KEYMAP: get all keys for attribute "output" ( y,c,b,...) - TODO can i use shorter function? - // output type Uint8Array -> string - // ......................................................... - for (let i = 0; i < jsonObj.keyboard.keyMapSet[keyMapSet_count].keyMap[j].key.length; i++) { - if (jsonObj.keyboard.keyMapSet[keyMapSet_count].keyMap[j].key[i]['@_output'] !== "\0") { - // textencoder converts string -> bytes ( 'A' -> [ 65 ], '☺' -> [ 226, 152, 186 ]) - // textencoder is of Uint8Array(1) for A and Uint8Array(3) for ☺ - keys_output_One_Layer[i] = new TextEncoder().encode(jsonObj.keyboard.keyMapSet[keyMapSet_count].keyMap[j].key[i]['@_output']); - } - // ToDo do I need empty fields in keys_output_all_Layers, keys_action_all_Layers - // ......................................................... - // KEYMAP: get all keys for attribute "action" ( ^,a,e,i,...) - TODO can i use shorter function? - // action type Uint8Array -> string - // ......................................................... - if (jsonObj.keyboard.keyMapSet[keyMapSet_count].keyMap[j].key[i]['@_action'] !== "\0") { - keys_action_One_Layer[i] = new TextEncoder().encode(jsonObj.keyboard.keyMapSet[keyMapSet_count].keyMap[j].key[i]['@_action']); - } - } - - // ......................................................... - // create array of "action" and array of "output" - keys_output_all_Layers.push(keys_output_One_Layer) // save all @output data ( will be used for conversion, write...) - keys_action_all_Layers.push(keys_action_One_Layer) // save all @action data ( will be used for deadkeys) - - - //#### end output+action ############################################################################################################################################### - } - - // ......................................................... - // ACTION: create array of "deadkey" / "deadkey names" - TODO can i use shorter function? - // action type string[] -> string[][] - // ......................................................... - const dk_pairs_all_Layers_max: string[][] = [] - // here replace with function to find - // C3 state none + next Nr => deadkeys - console.log("--------------------------------") - - // loop through actions and get the value of attribute "next" (which indicates this is a deadkey) - for (let jj = 0; jj < jsonObj.keyboard.actions.action.length; jj++) { - for (let kk = 0; kk < jsonObj.keyboard.actions.action[jj].when.length; kk++) { - - if (jsonObj.keyboard.actions.action[jj].when[kk]['@_next'] !== undefined) { - const vec1d: string[] = [] - let dk_to_print - - const text_attribute_next = jsonObj.keyboard.actions.action[jj].when[kk]['@_next'] - - // loop through terminators and get output of that next state - for (let n = 0; n < jsonObj.keyboard.terminators.when.length; n++) { - if (jsonObj.keyboard.terminators.when[n]['@_state'] === text_attribute_next) - dk_to_print = jsonObj.keyboard.terminators.when[n]['@_output'] - } - - vec1d.push(text_attribute_next) - vec1d.push(dk_to_print) - vec1d.push(jsonObj.keyboard.actions.action[jj]['@_id']) // todo remove later - dk_pairs_all_Layers_max.push(vec1d) - } - } - } - dk_pairs_all_Layers = dk_pairs_all_Layers_max.filter(function (item, pos, self) { - return self.indexOf(item) == pos; - }) - console.log("dk_pairs_all_Layers", dk_pairs_all_Layers) - const dk: string[] = []; - - // ......................................................... - // ACTION: create array of "deadkeyables_all_Layers" - TODO can i use shorter function? - // deadkeyables_one type Uint8Array -> string[][] - // ......................................................... - const deadkeyables_all_Layers: string[][] = [] - // needed? we just want ANSI = the first one - for (let j = 0; j < jsonObj.keyboard.keyMapSet[keyMapSet_count].keyMap.length; j++) { - const deadkeyables_one: string[] = [] - // loop through all keys of ANSI - for (let i = 0; i < jsonObj.keyboard.keyMapSet[keyMapSet_count].keyMap[0].key.length; i++) { - - let dk_char - // find output in action id - for (let jj = 0; jj < jsonObj.keyboard.actions.action.length; jj++) { - - // find the action ID which was specified in keymap->key->action e.g. a19 - const action_name = new TextDecoder().decode(keys_action_all_Layers[j][i]) - - if (action_name !== "") { - //console.log("ction_name",action_name) - // find action id in actions->action e.g. a19 - if (jsonObj.keyboard.actions.action[jj]['@_id'] === action_name) { - - //a85 - - // 4 cases: - // C1 state none + output => - // C2 state Nr + output => - // OK C3 state none + next Nr => deadkeys see above - // C4 state Nr + next Nr => loop deadkeyables - - - const mytestVar = this.get_Terminator_Output_from_Next(jsonObj.keyboard, "a16", '@_state', '@_output') - console.log("mytestVar", mytestVar) - - if (jsonObj.keyboard.actions.action[jj].when[0]['@_state'] === "none") { - dk_char = jsonObj.keyboard.actions.action[jj].when[0]['@_output'] - console.log("++++++++++++++++++++++dk_char", j, i, jj, "action_name", action_name, - jsonObj.keyboard.actions.action[jj].when[0], "===>", dk_char, "mytestVar", mytestVar) - - // if @_next instead of @_output - // loop again - // and again... again...( -> recursive func!!) - } - } - } - } - - // fills correct entries into modifier 1-3 then false ( because of no action any more) - - //const resulting_character = new TextDecoder().decode(keys_action_all_Layers[j][i]) - const resulting_character = dk_char - - if (resulting_character !== "") - deadkeyables_one.push(resulting_character) - } - - for (let k = 0; k < dk_pairs_all_Layers.length; k++) { - dk.push(dk_pairs_all_Layers[k][1]) - } - - if (deadkeyables_one.length !== 0) { - deadkeyables_all_Layers.push(deadkeyables_one) - } - } - //console.log("deadkeyables_all_Layers before",deadkeyables_all_Layers) - for (let j = 0; j < deadkeyables_all_Layers.length; j++) { - // filter out dk -> plain deadkeyables_all_Layers ( a,^, e,i,´,u => a,e,i,u) - // return all that don`t find ^,´, ` - deadkeyables_all_Layers[j] = deadkeyables_all_Layers[j].filter(function (el) { - return dk.indexOf(el) < 0; - }); - - } - - console.log("deadkeyables_all_Layers after", deadkeyables_all_Layers) - - //double??? - // ......................................................... - // TERMINATOR: create array of "terminators" - TODO can i use shorter function? what element of terminators do i need - // terminators when state type Uint8Array[] - // ......................................................... - for (let i = 0; i < jsonObj.keyboard.terminators.when.length; i++) { - terminators_all_Layers[i] = jsonObj.keyboard.terminators.when[i] - } - - // ......................................................... - // TODO can i use shorter function? -> yes use terminators, filter, map or reduce - - // this addresses state+output and none+output - // but not state+next or none+next - - // loop through all dk, key-actions and find @_action - // find this value in - // in their 'when' find output for dk - // for all 'action' at keys paragraph - - - for (let j = 0; j < dk_pairs_all_Layers.length; j++) { - - const deadkeys_One_dk: string[] = [] - // find in action e.g. - for (let k = 0; k < keys_action_all_Layers[j].length; k++) { - - const action_from_keys_prargraph = new TextDecoder().decode(keys_action_all_Layers[j][k]) - if (action_from_keys_prargraph !== "") { - // find the same id (e.g. ) in the actions-paragraph - for (let l = 0; l < jsonObj.keyboard.actions.action.length; l++) { - - if (jsonObj.keyboard.actions.action[l]['@_id'] === action_from_keys_prargraph) { - // loop through when until dk name (e.g. dk s0) - for (let m = 0; m < jsonObj.keyboard.actions.action[l].when.length; m++) { - - // and get their @_output - if (jsonObj.keyboard.actions.action[l].when[m]['@_state'] === dk_pairs_all_Layers[j][0]) { - // todo push only if @output is found. if next is found: get value from terminators - //if (typeof jsonObj.keyboard.actions.action[l].when[m]['@_output'].property !== 'undefined') - deadkeys_One_dk.push(jsonObj.keyboard.actions.action[l].when[m]['@_output']) - //else - //console.log(deadkeys_One_dk, "§§§§§§ PROP UNDEFINED", j, "-", k, "-", l, "-", m, "-", dk_pairs_all_Layers[j][0], jsonObj.keyboard.actions.action[l].when[m].property) - } - } - } - } - } - } - // console.log("deadkeys_One_dk", deadkeys_One_dk) - deadkeyedChars_all_Layers.push(deadkeys_One_dk) - - console.log("deadkeyedChars_all_Layers", deadkeyedChars_all_Layers) - } - - - const vk: (string | number)[][] = [] - - // TODO remove unneccassary elements - const DataObject: convert_object = { - name: "Ukelele-kmn", // needed?? remove - ArrayOf_Element_Layouts: layouts_array, // needed?? I think no - ArrayOf_Element_KeyOutput: keys_output_all_Layers, - ArrayOf_Element_KeyAction: keys_action_all_Layers, - ArrayOf_Element_ALL_ModifierMaps: modifierMap_all_Layers, // all 18 modifiers in 1 array - ArrayOf_Element_ModifierMaps_ALLKeyMapSelect: modifierMap_ALL_KeyMapSelects, // 18 modifiers in 8 KeyMapSelect(behaviors) - ArrayOf_Element_Terminators: terminators_all_Layers, // add terminators ( ^,´,`) - ArrayOf_processed_VK_from_keylayout: vk, - ArrayOf_processed_dk: dk_pairs_all_Layers, // add dk-mapping ( dk1 <-> '^' ) - - ArrayOf_processed_deadkeyables: deadkeyables_all_Layers, // add char that can be modified with dk ( a,e,i,o,u) - ArrayOf_processed_deadkeyedChar: deadkeyedChars_all_Layers, // add modified keys ( â,ê,î,ô,û) - ArrayOf_processed_RuleData: kmn_Rules_AllLayers, - ArrayOf_processed_RuleDataStr: kmn_Rules_AllLayersStr - }; - - // TODO review condition - return DataObject - //return ((keys_output_all_Layers.length === nrOfStates + 5) && keys_output_all_Layers[0].length === nrOfKeys_inLayer) ? keys_output_all_Layers : null; - } - /** * @brief member function to convert data of .keylayout-file to kmn-file This will convert/rename modifiers, position of Keys and deadkeys and save into an array * @param take data_ukelele and create a mapping from mac Keycodes to key-names and save to data_ukelele object @@ -1120,6 +508,10 @@ export class KeylayoutToKmnConverter { * @return outArray Uint8Array keys_all_Layers, the converted data for kmn-files if all layers have been converted; else null */ public convert(data_ukelele: convert_object): convert_object { + + + + const data_VK_from_keylayout: (string | number)[][] = []; for (let i = 0; i < data_ukelele.ArrayOf_Element_KeyOutput[0].length; i++) { @@ -1183,7 +575,7 @@ export class KeylayoutToKmnConverter { // ************************************************************* // **** write rules ******************************************** // *************************************************************^ - + // todo replace write rules with reading out of rule-array console.log("start write 1") // if caps is used in .keylayout-file we need to add NCAPS in kmn-file let isCAPSused = false @@ -1318,6 +710,18 @@ export class KeylayoutToKmnConverter { } } + + //TODO remove + data += 'NOW MY RULES ********************************\n' + for (let kkk = 0; kkk < data_ukelele.ArrayOf_processed_RuleData.length; kkk++) { + let line: string = "" + for (let lll = 0; lll < data_ukelele.ArrayOf_processed_RuleData[kkk].length; lll++) { + const entry = new TextDecoder().decode(data_ukelele.ArrayOf_processed_RuleData[kkk][lll]) + line += " " + entry + " " + } + data += line + '\n' + } + data += '\n' // console.log("start write 5") /*writeFileSync("data/MyResult.kmn", data, { flag: "w" })*/ const data_encoded = new TextEncoder().encode(data) @@ -1333,96 +737,61 @@ export class KeylayoutToKmnConverter { //... helpers ............................................................................................. // TODO move outside of class? - // TODO use UInt8 instead of string - - //public collect_Data_From_File(data_ukelele: convert_object, jsonObj: any): convert_object { - public collect_Data_From_File(data_ukelele: convert_object, jsonObj: any): any { - - /*const DataArray: string[][] = [] - const DataArrayU8: Uint8Array[][] = [] - - - - const testUI8 = "a" - const testUI8_1 = new TextEncoder().encode(testUI8); - - const testUI82 = "ẞ" - const testUI8_12 = new TextEncoder().encode(testUI82); - - const testUI83 = "ሴ" - const testUI8_13 = new TextEncoder().encode(testUI83); - - const arrayString: string[]=[] - const Ui8String: Uint8Array[]=[] - - - Ui8String.push(testUI8_1) - arrayString.push(testUI8,testUI8_1) - - - - console.log("arrayString",arrayString, - "Ui8String",Ui8String - )*/ + // ToDo keep only uint8array-version + // for more info about mapping and cases C0-C4 + // see https://docs.google.com/document/d/1ISjACTA9aUBueTo1AoKnOsI6QR5kXeeD_maI0XUyXqg/edit?tab=t.0 + public createRuleData(data_ukelele: convert_object, jsonObj: any): convert_object { + const DataArray_U8: Uint8Array[][] = [] let action_id let output_id const isCapsused = this.checkIfCapsUsed(data_ukelele.ArrayOf_Element_ModifierMaps_ALLKeyMapSelect) - // loop keys //for (let j = 0; j < jsonObj.keyboard.keyMapSet[0].keyMap[i].key.length; j++) { for (let j = 0; j < 52; j++) { + // loop behaviors for (let i = 0; i < jsonObj.keyboard.keyMapSet[0].keyMap.length; i++) { - let output_count = 0 - let action_count = 0 - let all_count = 0 // ...................................................................................................... - // case C0: code + output ............................................................................... + // case C0: output ...................................................................................... + // a key is mapped to a character ( code-> output) ...................................................... + // ...............e. g. ...................................................... + // ...................................................................................................... + // in keys at top for code 1 (K_S) take output ("s") [italian copy] + // get modifiers [modifer of Keymap index 0] + // write [modifer of Keymap index 0] + K_S > s // ...................................................................................................... - all_count++ if (jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['@_output'] !== undefined) { - - // ...................................................................................................... - // case C0: output .............................................................................DONE .... - // a key is mapped to a character ( code-> output) ...................................................... - // ...............e. g. ...................................................... - // ...................................................................................................... - // in keys at top for code 1 (K_S) take output ("s") [italian copy] - // get modifiers [modifer of Keymap index 0] - // write [modifer of Keymap index 0] + K_S > s - // ...................................................................................................... - output_count++ output_id = jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['@_output'] + // loop modifiers for (let l = 0; l < data_ukelele.ArrayOf_Element_ModifierMaps_ALLKeyMapSelect[i].length; l++) { - const DataArraySingleStateC0: string[] = [] + const DataArraySingleStateC0_U8: Uint8Array[] = [] if (output_id !== "") { - const first_modifier_C0 = this.create_kmn_modifier(data_ukelele.ArrayOf_Element_ModifierMaps_ALLKeyMapSelect[i][l], isCapsused) - const result_C0 = jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['@_output'] - const first_key_C0 = this.map_UkeleleKC_To_VK(Number(jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['@_code'])) + const first_modifier_C0_U8 = new TextEncoder().encode(this.create_kmn_modifier(data_ukelele.ArrayOf_Element_ModifierMaps_ALLKeyMapSelect[i][l], isCapsused)); + const result_C0_U8 = new TextEncoder().encode(jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['@_output']); + const first_key_C0_U8 = new TextEncoder().encode(this.map_UkeleleKC_To_VK(Number(jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['@_code']))); - console.log("### Key Nr ", - jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['@_code'], - "[ + C0 modifiers->", i, first_modifier_C0.padEnd(25, " "), "] ", - this.map_UkeleleKC_To_VK(Number(jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['@_code'])).padEnd(8, " "), - "> ", - jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['@_output']) + /* console.log("### Key Nr ", + jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['@_code'], + "[ + C0 modifiers->", i, first_modifier_C0.padEnd(25, " "), "] ", + this.map_UkeleleKC_To_VK(Number(jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['@_code'])).padEnd(8, " "), + "> ", + jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['@_output'])*/ - DataArraySingleStateC0.push("first_modifier_C0") - DataArraySingleStateC0.push(first_modifier_C0) - DataArraySingleStateC0.push(first_key_C0) - DataArraySingleStateC0.push(result_C0) + DataArraySingleStateC0_U8.push(new TextEncoder().encode("first_modifier_C0")) + DataArraySingleStateC0_U8.push(first_modifier_C0_U8) + DataArraySingleStateC0_U8.push(first_key_C0_U8) + DataArraySingleStateC0_U8.push(result_C0_U8) } - - if (DataArraySingleStateC0.length > 0) - DataArray.push(DataArraySingleStateC0) + if (DataArraySingleStateC0_U8.length > 0) + DataArray_U8.push(DataArraySingleStateC0_U8) } } @@ -1432,9 +801,9 @@ export class KeylayoutToKmnConverter { else if (jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['@_action'] !== undefined) { // ...................................................................................................... - // case C1: action + state none + output .......................................................DONE .. + // case C1: action + state none + output .............................................................. // a key is mapped to an action and then to an output ................................................... - // code->action->action(none)->action(output) .......................................................... + // code->action->action(none)->action(output) ........................................................... // ...............e. g. a + // write [modifer of Keymap index 0] + K_A > a // ...................................................................................................... - action_count++ - action_id = jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['@_action'] const result_C1 = this.lookup_6_ActionNone__To__ActionOutput(jsonObj, action_id) + const result_C1_U8 = new TextEncoder().encode(this.lookup_6_ActionNone__To__ActionOutput(jsonObj, action_id)) // modifiers for (let l = 0; l < data_ukelele.ArrayOf_Element_ModifierMaps_ALLKeyMapSelect[i].length; l++) { - const DataArraySingleStateC1: any[] = [] + const DataArraySingleStateC1_U8: Uint8Array[] = [] if (result_C1 !== undefined) { - const first_modifier_C1 = this.create_kmn_modifier(data_ukelele.ArrayOf_Element_ModifierMaps_ALLKeyMapSelect[i][l], isCapsused) - const first_key_C1 = this.map_UkeleleKC_To_VK(Number(jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['@_code'])) + const first_modifier_C1_U8 = new TextEncoder().encode(this.create_kmn_modifier(data_ukelele.ArrayOf_Element_ModifierMaps_ALLKeyMapSelect[i][l], isCapsused)) + const first_key_C1_U8 = new TextEncoder().encode(this.map_UkeleleKC_To_VK(Number(jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['@_code']))) - console.log( + /*console.log( "### Key Nr ", jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['@_code'], "[ + C1 modifiers->", i, first_modifier_C1.padEnd(25, " "), "] ", this.map_UkeleleKC_To_VK(Number(jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['@_code'])).padEnd(8, " "), "> ", - result_C1) + result_C1)*/ - DataArraySingleStateC1.push("first_modifier_C1") - DataArraySingleStateC1.push(first_modifier_C1) - DataArraySingleStateC1.push(first_key_C1) - DataArraySingleStateC1.push(result_C1) + DataArraySingleStateC1_U8.push(new TextEncoder().encode("first_modifier_C1")) + DataArraySingleStateC1_U8.push(first_modifier_C1_U8) + DataArraySingleStateC1_U8.push(first_key_C1_U8) + DataArraySingleStateC1_U8.push(result_C1_U8) } - if (DataArraySingleStateC1.length > 0) - DataArray.push(DataArraySingleStateC1) + if (DataArraySingleStateC1_U8.length > 0) + DataArray_U8.push(DataArraySingleStateC1_U8) } // ...................................................................................................... - // case C2: action + state Nr + output .........................................................DONE .... - // a key is mapped to an action, then to an output+state ................................................ - // code->action->action(none) + state->action(output) ................................................... + // case C2: action + state Nr + output .................................................................. + // a key is mapped to an action, then to an state+output ................................................ + // replace state x with all rules that result in x (action->action(none) + state-> output) ......................................................... // ...............e. g. .................................................... // ...................................................................................................... // in keys at top for code 0 (K_A) take actions id (a9) [italian copy] // get modifiers [modifer of Keymap index 0] - // loop all actions and look for next="2" (state="2" => next="2") (=>a8) + // loop all actions and look for next="2" (state="none" => next="2") (=>action id = a8) // get action id of this row (id = a8) - // look for a8 in keymap-keys action at top - // take code = 25 = K_9 - // get modifiers [modifer of Keymap index 3] (=anyOption) + // look for a8 in keymap-keys action at the top + // take code = 25 and map keycode to VK (VK= K_9) + // get second modifiers [modifer of Keymap index 3] (=anyOption) // [modifer of Keymap index 3] + K_A + K_9 > à - // write anyOption + K_A + K_9 > à + // write: [anyOption + K_A] > dk(dk1) ; dk(dk1) + [second modifiers K_9] > à // ...................................................................................................... let result_C2 + let result_C2_U8 let nextvalArray: string[] = [] // get action id: e.g. id a16 ->id nr 8 @@ -1508,22 +878,28 @@ export class KeylayoutToKmnConverter { if (stateVal !== undefined) { // get output result_C2 = jsonObj.keyboard.actions.action[indexInActions].when[jj]['@_output'] + result_C2_U8 = new TextEncoder().encode(jsonObj.keyboard.actions.action[indexInActions].when[jj]['@_output']) // get all cases which result in state 3 nextvalArray = this.lookup_5_ActionState__To__ActionNext_none(jsonObj, stateVal) // for all modifier combinations for (let l = 0; l < data_ukelele.ArrayOf_Element_ModifierMaps_ALLKeyMapSelect[i].length; l++) { - const DataArraySingleStateC2: string[] = [] + // const DataArraySingleStateC2: string[] = [] + const DataArraySingleStateC2_U8: Uint8Array[] = [] for (let k = 0; k < nextvalArray.length; k++) { if (result_C2 !== undefined) { - const first_modifier_C2 = this.create_kmn_modifier(data_ukelele.ArrayOf_Element_ModifierMaps_ALLKeyMapSelect[i][l], isCapsused) - const first_Key_C2 = this.map_UkeleleKC_To_VK(Number(jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['@_code'])) - const second_Key_C2 = this.map_UkeleleKC_To_VK(Number(this.lookup_11_KeyMapAction__To__KeyMapCode(jsonObj, nextvalArray[k]))) + /* const first_modifier_C2 = this.create_kmn_modifier(data_ukelele.ArrayOf_Element_ModifierMaps_ALLKeyMapSelect[i][l], isCapsused) + const first_Key_C2 = this.map_UkeleleKC_To_VK(Number(jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['@_code'])) + const second_Key_C2 = this.map_UkeleleKC_To_VK(Number(this.lookup_11_KeyMapAction__To__KeyMapCode(jsonObj, nextvalArray[k]))) + */ + const first_modifier_C2_U8 = new TextEncoder().encode(this.create_kmn_modifier(data_ukelele.ArrayOf_Element_ModifierMaps_ALLKeyMapSelect[i][l], isCapsused)) + const first_Key_C2_U8 = new TextEncoder().encode(this.map_UkeleleKC_To_VK(Number(jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['@_code']))) + const second_Key_C2_U8 = new TextEncoder().encode(this.map_UkeleleKC_To_VK(Number(this.lookup_11_KeyMapAction__To__KeyMapCode(jsonObj, nextvalArray[k])))) - console.log( + /*console.log( " ### Key Nr", "nextvalArray.length", nextvalArray.length, j, @@ -1544,16 +920,17 @@ export class KeylayoutToKmnConverter { this.lookup_11_KeyMapAction__To__KeyMapCode(jsonObj, nextvalArray[k]), " +keymapindex of this", this.lookup_11_KeyMapAction__To__KeyIndex(jsonObj, nextvalArray[k]) - ) + )*/ - DataArraySingleStateC2.push("modifier_C2") - DataArraySingleStateC2.push(first_modifier_C2) - DataArraySingleStateC2.push(first_Key_C2) - DataArraySingleStateC2.push(second_Key_C2)// state = none -> no modifier - DataArraySingleStateC2.push(result_C2) + DataArraySingleStateC2_U8.push(new TextEncoder().encode("first modifier_C2")) + DataArraySingleStateC2_U8.push(first_modifier_C2_U8) + DataArraySingleStateC2_U8.push(first_Key_C2_U8) + DataArraySingleStateC2_U8.push(second_Key_C2_U8)// state = none -> no modifier + DataArraySingleStateC2_U8.push(result_C2_U8) } - if (DataArraySingleStateC2.length > 0) - DataArray.push(DataArraySingleStateC2) + + if (DataArraySingleStateC2_U8.length > 0) + DataArray_U8.push(DataArraySingleStateC2_U8) } } } @@ -1562,35 +939,34 @@ export class KeylayoutToKmnConverter { // ...................................................................................................... // case C3: action + state Nr + Next .................................................................... // ...............e. g. ..................................................... + // replace state x with all rules that result in 14 (action->action(state)->action(next)->terminator(output) ........................................ // ...................................................................................................... {// in keys at top for code 10 (=K_BACKQUOTE) take actions id (a57) [German standard copy] // code 10 = K_BACKQUOTE (or another key 93) // get modifiers [modifer of Keymap index 0] - // goto action id a57 - // goto when 14 - - // loop through all actions to find next="14" ( might find several) - // get actionsId and output (a80 ) - // get modifiers [modifer of Keymap index 3] - // look at top for a80 => code 40 (= K_K) ( this is how we could get to state 14) - // take 20 and look for state = 20 in terminators ( because of "next") + // goto action id a57 and find 14 in + // find all rules that result in 14 (next="14" - there might be several) + // get actionsId and of that rule (a80 ) + // look at top for a80 and find key Code (code 40 = K_K) + // get modifiers Index of that key (code 40) [modifer of Keymap index 3] + // lookup modifier names from modifiers Index + // take 20 ( of next="20") and look for state = 20 in terminators ("next" points to terminators) // get output ("̭") - // [modifer of Keymap index 0] + a57 + +[modifer of Keymap index 3] state14 -> next 20 - // <=>[modifer of Keymap index 0] + K_BACKQUOTE +[modifer of Keymap index 3] K_K -> "̭" + // [first modifier + K_K] > dk(dk1) ; dk(dk1) + [second modifier K_BKQUOTE] > "̭" } // ...................................................................................................... // get a9 in behavior/key action_id = jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['@_action'] const actionIdIndex = this.lookup_10_ActionId__To__ActioIndex(jsonObj, action_id) - const DataArraySingleStateC3: string[] = [] + const DataArraySingleStateC3_U8: Uint8Array[] = [] let value_state let value_next let the_ContextKeyNr - let first_key_C3 + let first_key_C3_U8 let keymapIndexForactionID_2: any[][] // loop all action-when and find state-next-pair @@ -1611,42 +987,47 @@ export class KeylayoutToKmnConverter { // find all occurences of a17 e.g. key 28/3 [ [ '28', 3 ] ] keymapIndexForactionID_2 = this.lookup_14_ActionName__To__MapIndex(jsonObj, String(theContextID)) // get keyname e.g. 28-> K_8 - first_key_C3 = this.map_UkeleleKC_To_VK(Number(the_ContextKeyNr)) + first_key_C3_U8 = new TextEncoder().encode(this.map_UkeleleKC_To_VK(Number(the_ContextKeyNr))) } - const result_C3 = this.lookup_9_TerminatorState__To__TerminatorOutput_str(jsonObj, value_next) + // const result_C3 = this.lookup_9_TerminatorState__To__TerminatorOutput_str(jsonObj, value_next) + const result_C3_U8 = new TextEncoder().encode(this.lookup_9_TerminatorState__To__TerminatorOutput_str(jsonObj, value_next)) for (let l = 0; l < data_ukelele.ArrayOf_Element_ModifierMaps_ALLKeyMapSelect[i].length; l++) { - const second_modifier_C3 = this.create_kmn_modifier(data_ukelele.ArrayOf_Element_ModifierMaps_ALLKeyMapSelect[i][l], isCapsused) + // const second_modifier_C3 = this.create_kmn_modifier(data_ukelele.ArrayOf_Element_ModifierMaps_ALLKeyMapSelect[i][l], isCapsused) + const second_modifier_C3_U8 = new TextEncoder().encode(this.create_kmn_modifier(data_ukelele.ArrayOf_Element_ModifierMaps_ALLKeyMapSelect[i][l], isCapsused)) if (the_ContextKeyNr !== undefined) { const second_key_Nr = Number(jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['@_code']) - const second_key_C3 = this.map_UkeleleKC_To_VK(second_key_Nr) + // const second_key_C3 = this.map_UkeleleKC_To_VK(second_key_Nr) + + const second_key_C3_U8 = new TextEncoder().encode(this.map_UkeleleKC_To_VK(second_key_Nr)) for (let kk = 0; kk < data_ukelele.ArrayOf_Element_ModifierMaps_ALLKeyMapSelect[keymapIndexForactionID_2[0][1]].length; kk++) { - const first_modifier_text_C3 = data_ukelele.ArrayOf_Element_ModifierMaps_ALLKeyMapSelect[keymapIndexForactionID_2[0][1]][kk] - const first_modifier_C3 = this.create_kmn_modifier(first_modifier_text_C3, isCapsused) + const first_modifier_text_C3_U8 = data_ukelele.ArrayOf_Element_ModifierMaps_ALLKeyMapSelect[keymapIndexForactionID_2[0][1]][kk] + const first_modifier_C3_U8 = new TextEncoder().encode(this.create_kmn_modifier(first_modifier_text_C3_U8, isCapsused)) - console.log(" ### Key Nr", jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['@_code'], + /*console.log(" ### Key Nr", jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['@_code'], "[ + C3 modifiers->", i, l, "[", first_modifier_C3, first_key_C3, "]", "> dk(dk1) ######### ", " dk(dk1) + [", second_modifier_C3, second_key_C3, "] > ", result_C3, the_ContextKeyNr, - keymapIndexForactionID_2, first_key_C3) + keymapIndexForactionID_2, first_key_C3)*/ - DataArraySingleStateC3.push("first_modifier_C3") - DataArraySingleStateC3.push(first_modifier_C3) - DataArraySingleStateC3.push(first_key_C3) - DataArraySingleStateC3.push(second_modifier_C3) - DataArraySingleStateC3.push(second_key_C3) - DataArraySingleStateC3.push(result_C3) + DataArraySingleStateC3_U8.push(new TextEncoder().encode("first_modifier_C3")) + DataArraySingleStateC3_U8.push(first_modifier_C3_U8) + DataArraySingleStateC3_U8.push(first_key_C3_U8) + DataArraySingleStateC3_U8.push(second_modifier_C3_U8) + DataArraySingleStateC3_U8.push(second_key_C3_U8) + DataArraySingleStateC3_U8.push(result_C3_U8) } - if (DataArraySingleStateC3.length > 0) - DataArray.push(DataArraySingleStateC3) + + if (DataArraySingleStateC3_U8.length > 0) + DataArray_U8.push(DataArraySingleStateC3_U8) } } } @@ -1658,25 +1039,25 @@ export class KeylayoutToKmnConverter { // ...................................................................................................... // in keys for code 32 (K_U) at top find actions id a16 [italian copy] // get modifiers [modifer of Keymap index 3] - // in actions a16 find state "none" and get next (=4) - // in terminators find the state (=4) - // take output ("¨") + // in actions a16 () find state "none" and get next (=4) + // in terminators ( ) find the state (=4) and get output ("¨") // write [modifer of Keymap index 3] + K_U -> "¨" action_id = jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['@_action'] const next_id = this.lookup_3_ActionNone__To__ActionNext(jsonObj, action_id) const result_C4 = this.lookup_9_TerminatorState__To__TerminatorOutput_str(jsonObj, next_id) - // all + const result_C4_U8 = new TextEncoder().encode(this.lookup_9_TerminatorState__To__TerminatorOutput_str(jsonObj, next_id)) + for (let l = 0; l < data_ukelele.ArrayOf_Element_ModifierMaps_ALLKeyMapSelect[i].length; l++) { - const DataArraySingleStateC4: string[] = [] + const DataArraySingleStateC4_U8: Uint8Array[] = [] - const first_modifier_C4 = this.create_kmn_modifier(data_ukelele.ArrayOf_Element_ModifierMaps_ALLKeyMapSelect[i][l], isCapsused) - const first_key_C4 = this.map_UkeleleKC_To_VK(Number(jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['@_code'])) + const first_modifier_C4_U8 = new TextEncoder().encode(this.create_kmn_modifier(data_ukelele.ArrayOf_Element_ModifierMaps_ALLKeyMapSelect[i][l], isCapsused)) + const first_key_C4_U8 = new TextEncoder().encode(this.map_UkeleleKC_To_VK(Number(jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['@_code']))) if (result_C4 !== "") { - console.log( + /*console.log( "### Key Nr ", jsonObj.keyboard.keyMapSet[0].keyMap[i].key[j]['@_code'], "[ + C4 modifiers->", i, first_modifier_C4.padEnd(25, " "), "] ", @@ -1686,15 +1067,15 @@ export class KeylayoutToKmnConverter { " [", action_id, next_id, - "]") + "]")*/ - DataArraySingleStateC4.push("first_modifier_C4") - DataArraySingleStateC4.push(first_modifier_C4) - DataArraySingleStateC4.push(first_key_C4) - DataArraySingleStateC4.push(result_C4) + DataArraySingleStateC4_U8.push(new TextEncoder().encode("first_modifier_C4")) + DataArraySingleStateC4_U8.push(first_modifier_C4_U8) + DataArraySingleStateC4_U8.push(first_key_C4_U8) + DataArraySingleStateC4_U8.push(result_C4_U8) } - if (DataArraySingleStateC4.length > 0) - DataArray.push(DataArraySingleStateC4) + if (DataArraySingleStateC4_U8.length > 0) + DataArray_U8.push(DataArraySingleStateC4_U8) } } @@ -1703,12 +1084,8 @@ export class KeylayoutToKmnConverter { } } - // console.log("DataArray", DataArray) - - - data_ukelele.ArrayOf_processed_RuleDataStr = DataArray - - return data_ukelele.ArrayOf_processed_RuleDataStr + data_ukelele.ArrayOf_processed_RuleData = DataArray_U8 + return data_ukelele } /*public lookup_1_KeymapCode__To__keyMapAction(data: any, search: string): string { @@ -1871,261 +1248,7 @@ export class KeylayoutToKmnConverter { } return mapIndexArray_max } - //___________________ - /* ?? check:*/ public get_Terminator_Output_from_Next(data: any, valSearch: any, at_In: any, at_Out: any): any { - const returnvalue = "XX" - // take jsonObj(data), valSearch, valReturn, at_In, at_Out // valSearch =18 from next=18 - // return valReturn - // do: - // loop (i) through jsonObj-terminator until VAlSearch is found in when-@state - // get i - // return jsonObj-termin[i][@_out] - // a16: state = "none -> next =3" - - //console.log(" in:", valSearch, "->") - //const found_outputValue = this.get_Next_Output_from_None_and_id(data, valSearch, "none", at_In, at_Out) - - // console.log(" in:", valSearch, "->", found_outputValue) - //const returnvalue = this.get_Terminator_Output_from_Next(data, found_outputValue, at_In, at_Out) - - //console.log("§§§§§§§§§§§ in:", valSearch, "->", found_outputValue, "->", returnvalue) - return returnvalue - } - /* public get_all_next_from_state(data: any, action_idName: string): string[] { - const returnarray: string[] = [] - // e.g. action_idName = 3 - if (action_idName !== "none") { - // loop all action/when - for (let k = 0; k < data.keyboard.actions.action.length; k++) { - for (let j = 0; j < data.keyboard.actions.action[k].when.length; j++) { - // find attribute next === 3 - if (data.keyboard.actions.action[k].when[j]['@_next'] === action_idName) { - returnarray.push(data.keyboard.actions.action[k]['@_id']) - } - } - } - } - return returnarray - } */ - /* public get_Output_Output_from_None_and_id(data: any, actionId: any, valSearch: any): any { - // a16-> id ==a16 ->4 - //todo what if douplicate value?? - let OutputValue = "" - for (let jj = 0; jj < data.keyboard.actions.action.length; jj++) { - if (data.keyboard.actions.action[jj]['@_id'] === actionId) { - for (let kk = 0; kk < data.keyboard.actions.action[jj].when.length; kk++) { - if (data.keyboard.actions.action[jj].when[kk]['@_state'] === "none") { - OutputValue = data.keyboard.actions.action[jj].when[kk]['@_output'] - } - } - } - } - return OutputValue - } */ - /* public get_Output_Next_from_None_and_id(data: any, actionId: any, valSearch: any): any { - // a16-> id ==a16 ->4 - //todo what if douplicate value?? - let OutputValue = "" - - for (let jj = 0; jj < data.keyboard.actions.action.length; jj++) { - if (data.keyboard.actions.action[jj]['@_id'] === actionId) { - for (let kk = 0; kk < data.keyboard.actions.action[jj].when.length; kk++) { - if (data.keyboard.actions.action[jj].when[kk]['@_state'] === "none") - OutputValue = data.keyboard.actions.action[jj].when[kk]['@_next'] - } - } - } - return OutputValue - }*/ - /* public loop_Action_ToFind_index_from_ID_name(data: any, action_idName: string): number { - - for (let k = 0; k < data.keyboard.actions.action.length; k++) { - if (data.keyboard.actions.action[k]['@_id'] === action_idName) - - // console.log("data.actions.action[0]['@_id'] 2",data.keyboard.actions.action[0]['@_id'], k) - return k - } - return 0 - }*/ - /*public get_Next_Output_from_None(data: any, valSearch: any, at_In: any, at_Out: any): any { - - valSearch = "none" - - for (let k = 0; k < data.actions.action.length; k++) { - for (let j = 0; j < data.actions.action[k].when.length; j++) { - if ((data.actions.action[k].when[j]['@_state'] === valSearch && data.actions.action[k].when[j]['@_next'] !== "undefined")) { - const nextValue = data.actions.action[k].when[j]['@_next'] - // console.log("found pair: ", k, j, data.actions.action[k]['@_id'], data.actions.action[k].when[j]['@_state'], "nextValue",nextValue) - return nextValue - } - } - } - return "" - }*/ - /*public get_Next_Output_from_None_and_id(data: any, actionId: any, valSearch: any, at_In: any, at_Out: any): any { - // a16-> id ==a16 ->4 - valSearch = "none" - - let nextValue = "" - for (let jj = 0; jj < data.actions.action.length; jj++) { - if (data.actions.action[jj]['@_id'] === actionId) { - for (let kk = 0; kk < data.actions.action[jj].when.length; kk++) { - nextValue = data.actions.action[jj].when[kk]['@_next'] - } - } - } - return nextValue - }*/ - /*public get_Output_From_Terminator(data: any, actionId: any, valSearch: any): any { - // a16-> id ==a16 ->4 - //todo what if douplicate value?? - let OutputValue = "" - for (let jj = 0; jj < data.keyboard.terminators.when.length; jj++) { - if (data.keyboard.terminators.when[jj]['@_state'] === actionId) { - OutputValue = data.keyboard.terminators.when[jj]['@_output'] - } - } - return OutputValue - }*/ - /*public get_Attribut_follow(data: any, parent: any, child: any, actionId: any, findtag: any, returntag: any, findtagContents: any): any { - - console.log("Input:", - "\nchild", child, - "\nactionId", actionId, - "\nfindtag", findtag, - "\nreturntag", returntag, - "\nfindtagContents", findtagContents, - "\nfdata.child.length", parent + "." + child + ".length", - "\nparent.child[jj]['@_id'] ", parent + "." + child + ".[0]['@_id']", - "\nparent.child[jj].when.length ", parent + "." + child + ".[0].when.length", - "\nparent.child[jj].when[kk][findtag] ", parent + "." + child + ".d[0].when[0]["+findtag+"]" - ) - console.log("Input:" - ) - const parent_child= (parent + "." + child) - // a16-> id ==a16 ->4 - //todo what if douplicate value?? - let OutputValue = "" - for (let jj = 0; jj < parent_child.length; jj++) { - if (parent_child[jj]['@_id'] === actionId) { - for (let kk = 0; kk < parent.child[jj].when.length; kk++) { - if (parent.child[jj].when[kk][findtag] === findtagContents) { - OutputValue = parent.child[jj].when[kk][returntag] - } - } - } - } - return OutputValue - }*/ - /*public get_Terminator_Output_from_Next(data: any, valSearch: any, at_In: any, at_Out: any): any { - - const valReturn = 0 - // take jsonObj(data), valSearch, valReturn, at_In, at_Out // valSearch =18 from next=18 - // return valReturn - // do: - // loop (i) through jsonObj-terminator until VAlSearch is found in when-@state - // get i - // return jsonObj-termin[i][@_out] - - - let nextValue = 0 - let returnvalue =0 - - //for (let k = 0; k < data.actions.length; k++) { - for (let k = 0; k < data.actions.action.length; k++) { - for (let j = 0; j < data.actions.action[k].when.length; j++) { - if ((data.actions.action[k].when[j]['@_state'] === "none" && data.actions.action[k].when[j]['@_next'] !== "undefined")) { - // if ((data.actions.action[k].when[j]['@_state'] === "none" )) { - nextValue = data.actions.action[k].when[j]['@_next'] - // console.log("found pair: ", k, j, data.actions.action[k]['@_id'], data.actions.action[k].when[j]['@_state'], "nextValue",nextValue) - - - for (let i = 0; i < data.terminators.when.length; i++) { - if (data.terminators.when[i]['@_state'] === nextValue) { - - returnvalue= data.terminators.when[i]['@_output'] - // console.log("terminators pair: ", i, nextValue, data.terminators.when[i]['@_output'], returnvalue) - } - } - } - } - } - return valReturn - }*/ - /* public get_Next_Output_from_Any(data: any, valSearch: any, at_In: any, at_Out: any): any { - - for (let k = 0; k < data.actions.action.length; k++) { - for (let j = 0; j < data.actions.action[k].when.length; j++) { - if ((data.actions.action[k].when[j]['@_state'] === valSearch && data.actions.action[k].when[j]['@_next'] !== "undefined")) { - const nextValue = data.actions.action[k].when[j]['@_next'] - // console.log("found pair: ", k, j, data.actions.action[k]['@_id'], data.actions.action[k].when[j]['@_state'], "nextValue",nextValue) - return nextValue - } - } - } - return "" - } - */ - /* public find_ID_for_Next(data: any, state: string): string { - // a16-> id ==a16 ->4 - //todo what if douplicate value?? - for (let jj = 0; jj < data.keyboard.actions.length; jj++) { - for (let k = 0; k < data.keyboard.actions.action[jj].length; k++) { - if (data.keyboard.actions.action[jj].when[k]['@_next'] !== undefined) - return data.keyboard.actions.action[jj]['@_id'] - } - } - return "" - }*/ - /* public get_Next_Output_from_Any_and_id(data: any, actionId: any, valSearch: any, at_In: any, at_Out: any): any { - - for (let j = 0; j < data.actions.action[actionId].when.length; j++) { - if ((data.actions.action[actionId].when[j]['@_state'] === valSearch && data.actions.action[actionId].when[j]['@_next'] !== "undefined")) { - const nextValue = data.actions.action[actionId].when[j]['@_next'] - // console.log("found pair: ", k, j, data.actions.action[k]['@_id'], data.actions.action[k].when[j]['@_state'], "nextValue",nextValue) - return nextValue - } - } - return "" - } - */ - /* public get_Terminator_Output_from_State(data: any, actionId: any, valSearch: any, at_In: any, at_Out: any): any { - - for (let j = 0; j < data.terminators.when.length; j++) { - if (data.terminators.when[j]['@_state'] === valSearch) { - return data.terminators.when[j]['@_output'] - } - } - return "" - }*/ - /*public getCharacterFromActionName(data_ukelele: convert_object, ArrayOf_Element_KeyActionElement: Uint8Array): any { - //get character from ~ <- 4 <- a9 - //in: [ 97, 49 ] (a9) - // out: ~ - - //[ 97, 49 ]-> (a9) - console.log("ArrayOf_Element_KeyActionElement", ArrayOf_Element_KeyActionElement) - const ArrayOf_Element_KeyActionElement_string = new TextDecoder().decode(ArrayOf_Element_KeyActionElement) - - - if (ArrayOf_Element_KeyActionElement_string !== "") { - console.log("ArrayOf_Element_KeyActionElement_string in func", ArrayOf_Element_KeyActionElement_string) - - for (let jj = 0; jj < data_ukelele.ArrayOf_processed_dk.length; jj++) { - console.log(data_ukelele.ArrayOf_processed_dk[jj][2], "===?", ArrayOf_Element_KeyActionElement_string) - if (data_ukelele.ArrayOf_processed_dk[jj][2] === ArrayOf_Element_KeyActionElement_string) { - console.log("FOUND", data_ukelele.ArrayOf_processed_dk[jj][2]) - return data_ukelele.ArrayOf_processed_dk[jj][1] - } - - } - - return "" - } - - } -*/ /** * @brief member function to return the unicode value of a character