keyboardevent-chobun

e.kana, e.char追加

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/530545/1558131/keyboardevent-chobun.js

const code2Kana = {
    "Digit3": "あ", "KeyE": "い", "Digit4": "う", "Digit5": "え", "Digit6": "お",
    "KeyT": "か", "KeyG": "き", "KeyH": "く", "Quote": "け", "KeyB": "こ",
    "KeyX": "さ", "KeyD": "し", "KeyR": "す", "KeyP": "せ", "KeyC": "そ",
    "KeyQ": "た", "KeyA": "ち", "KeyZ": "つ", "KeyW": "て", "KeyS": "と",
    "KeyU": "な", "KeyI": "に", "Digit1": "ぬ", "Comma": "ね", "KeyK": "の",
    "KeyF": "は", "KeyV": "ひ", "Digit2": "ふ", "Equal": "へ", "Minus": "ほ",
    "KeyJ": "ま", "KeyN": "み", "Backslash": "む", "Slash": "め", "KeyM": "も",
    "Digit7": "や", "Digit8": "ゆ", "Digit9": "よ",
    "KeyO": "ら", "KeyL": "り", "Period": "る", "Semicolon": "れ", "IntlRo": "ろ",
    "Digit0": "わ", "KeyY": "ん",
    "IntlYen": "ー", "BracketLeft": "゛", "BracketRight": "゜",
    "Space": "_",
    "Escape": ""
}

const code2ShiftKana = {
    "Digit3": "ぁ", "KeyE": "ぃ", "Digit4": "ぅ", "Digit5": "ぇ", "Digit6": "ぉ",
    "KeyZ": "っ", "Digit7": "ゃ", "Digit8": "ゅ", "Digit9": "ょ", "Digit0": "を",
    "Comma": "、", "Period": "。", "Slash": "・", "BracketRight": "「", "Backslash": "」"
};



Object.defineProperty(KeyboardEvent.prototype, "kana", {
    get() {
      return this.shiftKey && code2ShiftKana[this.code] ? code2ShiftKana[this.code] : code2Kana[this.code];
    }
});

Object.defineProperty(KeyboardEvent.prototype, "char", {
    get() {
      return this.key === " " ? "_" : this.key === "Escape" ? "" : this.key;
    }
});

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址