我想提前感谢您为此花费的任何时间和精力。好的,所以我有一个脚本,它应该在页面加载后 3 秒后模拟按键事件。我希望这个按键可以运行键盘快捷键,但它所做的只是按下键。一旦按下,我怎样才能让它真正运行快捷方式?不确定这是否可能。再次感谢。
<script>
setTimeout( function(){
// jQuery plugin. Called on a jQuery object, not directly.
jQuery.fn.simulateKeyPress = function(character) {
// Internally calls jQuery.event.trigger
// with arguments (Event, data, elem). That last arguments is very important!
jQuery(this).trigger({ type: 'keypress', which: character.charCodeAt(0) });
};
jQuery(document).ready( function($) {
// Bind event handler
$( 'body' ).keypress( function(e) {
alert( String.fromCharCode( e.which ) );
console.log(e);
});
// Simulate the key press
$( 'body' ).simulateKeyPress('z');
});
}, 3000); //3 seconds
</script>
<script type="text/javascript">
// define a handler
function doc_keyUp(e) {
// this would test for whichever key is 40 and the ctrl key at the same time
if (e.ctrlKey && e.keyCode == 122) {
// call your function to do the thing
pauseSound();
}
}
// register the handler
document.addEventListener('keyup', doc_keyUp, false);
</script>