0

バーコード タグ スキャナーから入力を取得し、ページを呼び出してフィールドに書き込む Firefox 拡張機能を作成しました。スキャナは、タグを読み取った後にキーストロークを送信するようにプログラムされています。をリッスンしているウィンドウ オブジェクトにイベントを追加しましたCTRLK。私の問題は、テキストボックスに焦点が当てられていることです。テキストボックスが失われると、機能しません。私の質問は、テキストボックス要素を使用せずにスキャンされたタグの値を取得することは可能ですか? スキャナ入力は、キーボード インターフェイスを介して行われます。

BrowserOverlay.xul:

<window id="main-window">
<script type="application/x-javascript">

window.addEventListener("keydown", barcodeInit, false);

function sel(){
var textbox = document.getElementById("editIndex");
textbox.focus();
}
</script>
<hbox>
  <spacer flex="1"/>
<textbox id="editIndex" value="" size="1" maxlength="25" oncommand="sel()" />
<statusbar id="status-bar" class="chromeclass-status"> 
<statusbarpanel label="Barcode AddOn" class="statusbarpanel-iconic"
      onclick="openPreferences('barcodePane');" align="left" 
          src="chrome://topas/content/images/icon18.png" />
</statusbar>

</hbox>

テキストボックスのコンテンツを取得したら、openURIメソッドを呼び出して実際のウィンドウでページを開き、データを投稿します

BrowserOverlay.js:

if (event.ctrlKey && pressedKey == prefKey ){
  if(typeof editIndex != "undefined"){
    var dataString = "barcodeValue=" + editIndex;
    immidiate = true;
    document.getElementById("editIndex").value = "";
    window.loadURI(stringURL, null, dataString, false);
  }
4

1 に答える 1

1

keypressオブジェクトのイベントをリッスンすることで、押されたキーを受け取ることができますwindow。ウィンドウのどの要素がアクティブであっても、ブラウザー ウィンドウがフォーカスされている限りキーを取得します。これらの行に沿って:

var data = "";
window.addEventListener("keypress", processKeyPress, false);
window.addEventListener("keydown", processKeyDown, false);

function processKeyPress(event)
{
  data += String.fromCharCode(event.charCode);
}

function processKeyDown(event)
{
  if (event.ctrlKey && event.keyCode == prefKey)
  {
    var dataString = "barcodeValue=" + data;
    data = "";
    ...
  }
}

ドキュメンテーション: event.charCode

于 2012-08-14T15:45:23.517 に答える