"디지털 LP"를 만들기 위해 Itunes에서 html, css 및 javascript를 사용하는 "Itunes LP"형식의 터치 응용 프로그램을 만들고 있습니다. 응용 프로그램에는 터치 스크린을 통해 탐색 할 여러 LP가 있습니다. 전체 화면 모드 (iTunes 및 LP 내)에서 "esc 키"를 눌러 LP를 종료하고 탐색 할 다른 LP를 선택할 수있는 "coverflow view"를 입력 할 수 있습니다. 사용자가이 링크를 클릭 할 때 실제로 ESC 키를 눌렀을 때 한 가지 일을하는 버튼/링크를 만들어야하므로 키보드 또는 마우스가 없습니다.JavaScript를 사용하여 링크를 클릭하여 키보드 단축키를 시뮬레이션 할 수 있습니까?
제 질문은; 링크에서 JavaScript를 사용하여 키보드 단축키를 시뮬레이션 할 수 있습니까? 내 링크가 "집"이고이 링크를 클릭하면 ESC 키를 누를 때 브라우저가 작동합니다.
이 정보는 도움이 될 것입니다. 감사합니다.
다윗은
은 30/6 추가;
(아이튠즈 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 키를 시뮬레이션합니다!
감사합니다. 위의 편집을 참조하십시오. 나는 그 옳지 않다는 것을 안다. 그러나 나는 JS에서 경험이별로 없지만 많이 시도했다. 그러나 이것은 프로젝트의 마지막 부분이다. 그리고 끝난다. 그래서 집안을 시작하는 것은 어리석은 일이 될 것이다. js 파일을 작동 시키려면? 고마워! /david – Dave
코드를 기반으로 답변을 업데이트했습니다. 여전히 문제가 있다면,'TKSpatialNavigationManager'의 인스턴스를 생성하는 라인과'onkeypress' 또는'addEventListener ("onkeypress")'를 갖는 라인을 제공 할 수 있습니까? – Andrew