LoginSignup
15
17

More than 5 years have passed since last update.

US/JIS配列両方でCtrl-+ をキャッチする

Last updated at Posted at 2015-06-18

「+」という文字の入力はUS配列だと shift+=, JIS配列では shift+;になる。
問題となるのは、ctrl+shift+αという組み合わせがどういうメタキーの組み合わせとして解釈されるか、キーボードの設定次第で変わる。
US配列だとkeyCode: 187 とctrlKey。JIS配列だと186とctrlKeyとshiftKeyになっていた。

window.addEventListener "keydown", (e) =>
  #  US / JIS
  if (e.keyCode is 187 and e.ctrlKey) or (e.keyCode is 186 and e.shiftKey and e.ctrlKey)
    e.preventDefault()
    # exec something
    return false
  return true

この挙動によって何が起こるかというと、JIS配列を考慮してないキーバインド定義ライブラリを使うと、どう頑張ってもメタ-+をキャッチできないようなことになっていることがある。CodeMirrorお前だ。

15
17
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
17