Estoy tratando de ejecutar este código en una página web, que alertará a "shift" si detecta que se presionó una tecla shift.
// ==UserScript== // @name New Userscript // @namespace http://tampermonkey.net/ // @version 0.1 // @description try to take over the world! // @author You // @match ... // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== // @require http://code.jquery.com/jquery-3.4.1.min.js // @grant none // ==/UserScript== (function() { 'use strict'; alert('Loaded!'); var $ = window.jQuery; $(document).keypress(function(e) { if (e.which == 16) { alert("shift"); } }); })();El programa alerta "¡Cargado!" pero no alerta "cambio" cuando presiono el botón de cambio. ¿Puede alguien por favor ayudarme a averiguar dónde está el problema?
El evento keypress ha quedado obsoleto. Utilice el evento keydown en su lugar.
// ==UserScript== // @name New Userscript // @namespace http://tampermonkey.net/ // @version 0.1 // @description try to take over the world! // @author You // @match https://stackoverflow.com/* // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== // @require http://code.jquery.com/jquery-3.4.1.min.js // @grant none // ==/UserScript== (function() { 'use strict'; alert('Loaded!'); var $ = window.jQuery; $(document).on('keydown', function(e) { if (e.which == 16) { alert("shift"); } }); })();