ユーザーがホットキーを動的に定義してトリガーできるようにしたいという私が取り組んでいるWebアプリがあります。誰かが私を助けてくれることを願っていますか?
関連する HTML を使用してJSFiddle HEREを作成しました。
これが私のJavaScriptです:
// Assign Hotkey (this seems to be working)
$('input.hotkey').keydown( function(event) {
var hkey = event.keyCode;
if ( hkey == $('span#hk').text()){
alert('This key is already in use');
} else
$(this).parent().parent().prev().find('span#hk').text(hkey);
});
// Fire Hotkey (the problem might be here?)
$(document).not('input').keydown( function (event) {
var hkey = event.keyCode;
if (hkey == $('span#hk').text()){
$("span#hk:contains("+hkey+")").parent().click();
}
});
// Play Selected Track
$('#track').live('click', function () {
// Fake Function
var title = $('#title', this).text();
alert(title + ' is playing...');
});
注: 'space' と 'left/right' 矢印キーをグローバル ホットキーとして既に使用しています。それらを保護/割り当てられないようにする方法はありますか?
入力の入力中にトラックが起動するのを防ぐために .not('input') よりも使用するのに適したセレクターはありますか?
助けてくれてありがとう!