0

Itunes内でhtml、css、javascriptを使用して「デジタルLP」を作成する「Itunes LP」形式のタッチアプリケーションを作成しています。アプリケーションには、タッチスクリーンを介して探索するいくつかの LP があります。フルスクリーン モード (Itunes および LP 内) では、「esc キー」を押して LP を終了し、別の LP を選択して探索できる「coverflow ビュー」に入ることができます。キーボードやマウスがないので、ユーザーがこのリンクをクリックしたときに 1 つのことを行うボタン/リンクを作成する必要があります。それは、押された ESC キーをシミュレートすることです。

私の質問は次のとおりです。リンクで JavaScript を使用してキーボード ショートカットが押されていることをシミュレートすることは可能ですか? 私のリンクは「ホーム」で、このリンクをクリックすると、ブラウザーは ESC キーが押されたように動作します。

これに関するヒントは最も役に立ちます。ありがとう!

デビッド

30/6 追加。

(iTunes LP の TuneKit.js の一部)

    /* ==================== Keyboard Navigation ==================== */

TKSpatialNavigationManager.prototype.handleKeydown = function (event) {

  var key = event.keyCode;

  // check if our controller knows what it's doing and let it take over in case it does
  if (this._managedController.wantsToHandleKey(key)) {
    // prevent default actions
    event.stopPropagation();
    event.preventDefault();
    // have the controller do what it think is best in this case
    this._managedController.keyWasPressed(key);
    return;
  }

  // reset the sound
  TKSpatialNavigationManager.soundToPlay = null;

  // check we know about this key, otherwise, do nothing
  if (TKSpatialNavigationManagerKnownKeys.indexOf(key) == -1) {
    return;
  }

  var navigation = TKNavigationController.sharedNavigation;
  // first, check if we're hitting the back button on the home screen, in which case
  // we don't want to do anything and let the User Agent do what's right to exit
  if (event.keyCode == KEYBOARD_BACKSPACE && navigation.topController === homeController) {
    return;
  }

  // before we go any further, prevent the default action from happening
  event.stopPropagation();
  event.preventDefault();

  // check if we're busy doing other things
  if (TKSpatialNavigationManager.busyControllers > 0) {
    return;
  }
  // see if we pressed esc. so we can pop to previous controller
  if (event.keyCode == KEYBOARD_BACKSPACE) {
    var top_controller = navigation.topController;
    if (top_controller !== homeController) {
      // at any rate, play the exit sound
      TKUtils.playSound(SOUND_EXIT);
      // see if the top controller has a custom place to navigate to with the back button
      if (top_controller.backButton instanceof Element && top_controller.backButton._navigationData !== undefined) {
        navigation.pushController(TKController.resolveController(top_controller.backButton._navigationData.controller));
      }
      // otherwise, just pop the controller
      else {
        navigation.popController();
      }
    }
  }

****私のスクリプトは次のようになります:****

    var albumHelper = {};

albumHelper.playAlbum = function() {
  var playlist = bookletController.buildPlaylist(appData.songs);
  playlist.play();
};

var event = {};

event.keyCode = function() {
  var escapeKeyProxy = TKSpatialNavigationManager.prototype.handleKeydown({'keyCode':27});
    document.getElementById('btnExitFullScreen').onclick = escapeKeyProxy;
};

var homeController = new TKController({
  id: 'home',
  actions : [
    { selector: '.menu > .play', action: albumHelper.playAlbum },
    { selector: '.menu > .linernotes', action: event.keyCode }
  ],
  navigatesTo : [
    { selector: '.menu > .songs', controller: 'songs' },
    { selector: '.menu > .photos', controller: 'photos' },
    { selector: '.menu > .videos', controller: 'videos' },
    { selector: '.menu > .credits', controller: 'credits' }
  ],
  // make the PLAY button be default highlight
  highlightedElement : '.menu > .play'
});

だから私が欲しいのは.linernotesの画像です。クリックすると、ESCキーが押されたようにシミュレートされます!

4

1 に答える 1

0

この回答は、iTunes LP アプリケーションが全画面表示を終了するために使用する JS 関数があることを前提としています。

おそらくできますが、イベントをシミュレートする必要はありません。操作している Key イベントは、イベント リスナーまたはイベント ハンドラーのいずれかによって関数 (この場合は、フルスクリーン モードを終了する関数) に結び付けられます。ボタンを作成し、(同様のイベント リスナーまたはイベント ハンドラーによって) 同じ関数に関連付けることができるはずです。

キーイベントは押されたキーに関する情報を渡しますが、マウスイベントは渡さないため、直接関連付けることはできません。したがって、プロキシを介して送信する必要があります。コードは次のようになります。この場合、iTunes LP ライブラリの Key イベントを受け取るコードは、iTunesLPKeyPressEvent と呼ばれます。私はそれが実際に何と呼ばれているのか分かりません。

var escapeKeyProxy = function() {
    iTunesLPKeyPressEvent({'keyCode':27});
} 
document.getElementById('btnExitFullScreen').onclick = escapeKeyProxy;

これを少しマッサージする必要があるかもしれませんが、基本的な考え方はうまくいくはずです.

[編集]あなたの更新に基づいて、それがあなた TKSpatialNavigationManager.prototype._managedControllerが扱う必要があるオブジェクトであり、おそらくTKSpatialNavigationManager.prototype._managedController.keyWasPressed(key)エスケープキーをキャプチャするコードであると思います。addEventListener("keypress",SOME_METHOD,true)(またはkeyupまたはkeydown)のコードに目を通すとSOME_METHOD、イベントを処理しているのは です。それはあなたがハイジャックしたい方法です。手が届きやすい範囲に収まっていれば幸いです。

于 2010-06-29T10:07:45.587 に答える