abramhum.c.l
Hi:
I hope to trigger the key event at the same time, such as
Alt+Ctrl, is this possible?
What I know now is the following codes:
$(function() { var e = $.Event('keypress'); e.which = 79; $('item').trigger(e); });is that possible to make that, thanks a lot.
Capture the state of the keys in an array while pressed (keydown) and check if the key values exist in the array. When the key is released, remove the key value from the array.
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Key press</title><script src="//code.jquery.com/jquery-1.11.0.min.js"></script><script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script><script type="text/javascript">$(document).ready(function () { var ctrl = 17; var alt = 18; var keyDownList = new Array(); $(document).keydown(function (e) { //Push the key code keyDownList.push(e.keyCode); //Does the array contain ctrl + alt if ($.inArray(ctrl, keyDownList) + $.inArray(alt, keyDownList) > 0) { console.log("ctrl-alt pressed!"); } //console.log(keyDownList.join(", ")); }).keyup(function (e) { //Remove the key code keyDownList = $.grep(keyDownList, function (value) { return value != e.keyCode; }); //console.log(keyDownList.join(", ")); }); });</script></head><body></body></html>
JQuery References
https://api.jquery.com/keydown/