var keyPressHandler = function(ev){ logger.debug("KeyPressHandler is going through all possible keybindings."); for(var i = 0; i < keybindings.length; ++i){ var binding = keybindings[i]; // Check if this is the binding which we are seeking. if(ks2kc[keysym.fromName(binding.key).keysym] === ev.keycode){ if( (ev.buttons&(~146)) === binding.mod ){ if(binding.hasOwnProperty("command")){ commandHandler(binding.command); } else if(binding.hasOwnProperty("program")){ execHandler(binding.program); } } } } }
keybindings.forEach(function(keyConfiguration){ var keyCode = ks2kc[keysym.fromName(keyConfiguration.key).keysym]; keyConfiguration.mod = 0; for( var i in keyConfiguration.modifier ) { keyConfiguration.mod = ( keyConfiguration.mod | conversion.translateModifiers(keyConfiguration.modifier[i]) ); } logger.debug("Grabbing key '%s'.", keyCode); // Grab the key with each combination of capslock(2), numlock(16) and scrollock (128) var combination = [0,2,16,18,128,130,144,146]; for( var code in combination ) { if( (keyConfiguration.mod&combination[code]) !== 0 ) continue; global.X.GrabKey( display.screen[0].root, 0, // Don't report events to the window keyConfiguration.mod | combination[code], keyCode, 1, // async pointer mode 1 // async keyboard mode ); } });