如何根据键盘上的位置转换字符?

How to convert a Char by the position on the keyboard?

我需要一种方法来将字符串或字符转换为在不同语言的键盘上的等效项。因此,在希伯来语中,例如,“ש”将变为 "a" 或 "A".

如果不创建一个巨大的 switch 语句或字典,就找不到这样做的正确方法。

任何有关 JS 或 C# 的答案都很棒。

使用 keydownkeyup 事件的 keyCode。 属性此事件包含键盘按键代码但不包含符号代码。

document.addEventListener("keyup", function(event){
  console.log(String.fromCharCode(event.keyCode));
});

万一有人会寻找这个答案,这似乎不是不使用字典或 switch 语句的明确方法。

巴萨。

这是我在 javascript

中的做法
qwerty_mapping = {
"ת":"," ,",":"ת"
,"ף":";"    ,";":"ף"
,"ץ":"."    ,".":"ץ"
,"ש":"a"    ,"a":"ש"
,"נ":"b"    ,"b":"נ"
,"ב":"c"    ,"c":"ב"
,"ג":"d"    ,"d":"ג"
,"ק":"e"    ,"e":"ק"
,"כ":"f"    ,"f":"כ"
,"ע":"g"    ,"g":"ע"
,"י":"h"    ,"h":"י"
,"ן":"i"    ,"i":"ן"
,"ח":"j"    ,"j":"ח"
,"ל":"k"    ,"k":"ל"
,"ך":"l"    ,"l":"ך"
,"צ":"m"    ,"m":"צ"
,"מ":"n"    ,"n":"מ"
,"ם":"o"    ,"o":"ם"
,"פ":"p"    ,"p":"פ"
,"/":"q"    ,"q":"/"
,"ר":"r"    ,"r":"ר"
,"ד":"s"    ,"s":"ד"
,"א":"t"    ,"t":"א"
,"ו":"u"    ,"u":"ו"
,"ה":"v"    ,"v":"ה"
,"'":"w"    ,"w":"'"
,"ס":"x"    ,"x":"ס"
,"ט":"y"    ,"y":"ט"
}
function correctChar(old_char){
if(qwerty_mapping[old_char] == undefined)
    {
        return(old_char)
    } 
    else
    {
        return(qwerty_mapping[old_char])
    }
}

function correctString(old_string){
new_string = ""
for(i=0;i<old_string.length;i++){
    new_string = new_string+correctChar(old_string[i])
}
return new_string;
}