media.onSoftKeyEvent - GiGAGenie-ServiceSDK/UserGuide GitHub Wiki

gigagenie.media.onSoftKeyEvent

API ์„ค๋ช…

  • ํ•œ๊ธ€ ์†Œํ”„ํŠธ ํ‚ค ์ด๋ฒคํŠธ ์ˆ˜์‹  API
  • KeyEvent๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค์ง€ ์•Š๋Š” ํ•œ๊ธ€ ์†Œํ”„ํŠธ ํ‚ค ์ด๋ฒคํŠธ๋ฅผ ์ˆ˜์‹ ํ•จ
  • ์˜์–ด ์ž…๋ ฅ์€ eventListener๋ฅผ ์‚ฌ์šฉํ•ด ์ˆ˜์‹ 
  • showSoftKeyboard API ์ฐธ๊ณ 

API ๊ตฌ์กฐ

  • function callback(extra)
  • extra
    • composing: (Int) ์กฐํ•ฉ์ค‘์ธ ์ž์Œ ๋ชจ์Œ ๊ฐœ์ˆ˜
    • key: (String) ์ž…๋ ฅ๋œ ํ•œ๊ธ€

์‚ฌ์šฉ ์˜ˆ์‹œ

// callback ๋ฐฉ์‹
const backKeyeventCallback = function(event) {
    console.log(event)
    switch(event.keyCode) {
        case 8:
            var value = this.document.querySelector('input').value;
            this.document.querySelector('input').value = value.slice(0, -1);
            break;
    }
}
var inputData = "";//์ด์ „์— ์ž…๋ ฅ๋œ ๋ฐ์ดํ„ฐ
gigagenie.media.onSoftKeyEvent = function (extra) {
  window.addEventListener("keydown", backKeyEventCallback);
  var value = document.querySelector('input').value;//๋ณ€๊ฒฝ๋  text element
  if(extra.composing!=1) {
    if(inputData.length>0) value = value.slice(0, -inputData.length); //๋งˆ์ง€๋ง‰์— ์ž…๋ ฅ๋œ ๋ฐ์ดํ„ฐ๋งŒ ๋ฐ›๊ธฐ
  }
  document.querySelector('input').value = value + extra.key;
  inputData = extra.key;
};