diff --git a/src/client/js/input.js b/src/client/js/input.js index 19ee59f4..ec853325 100644 --- a/src/client/js/input.js +++ b/src/client/js/input.js @@ -159,6 +159,19 @@ define([ return result; }, + isKeyAllowed: function (key) { + const result = ( + key.length > 1 || + this.whitelistedKeys.includes(key) || + ( + !this.blacklistedKeys.includes(key) && + !this.blacklistedKeys.includes('*') + ) + ); + + return result; + }, + events: { keyboard: { /* eslint-disable-next-line max-lines-per-function */ @@ -176,16 +189,7 @@ define([ if ((e.keyCode === 9) || (e.keyCode === 8) || (e.keyCode === 122)) e.preventDefault(); - const allowKey = ( - key.length > 1 || - this.whitelistedKeys.includes(key) || - ( - !this.blacklistedKeys.includes(key) && - !this.blacklistedKeys.includes('*') - ) - ); - - if (!allowKey) + if (!this.isKeyAllowed(key)) return; if (this.keys.has(key)) diff --git a/src/server/clientComponents/serverActions.js b/src/server/clientComponents/serverActions.js index 2c7c2763..5201dd9a 100644 --- a/src/server/clientComponents/serverActions.js +++ b/src/server/clientComponents/serverActions.js @@ -1,9 +1,11 @@ define([ 'js/system/events', - 'js/system/client' + 'js/system/client', + 'js/input' ], function ( events, - client + client, + input ) { return { type: 'serverActions', @@ -19,7 +21,10 @@ define([ }, onKeyUp: function (key) { - this.actions.forEach(function (a) { + if (!input.isKeyAllowed(key)) + return; + + this.actions.forEach(a => { if (a.key !== key) return; @@ -28,7 +33,7 @@ define([ method: 'performAction', data: a.action }); - }, this); + }); }, extend: function (blueprint) {