Search code examples
reactjswindowsrobotjs

Win+L combination not working using robotjs library


I am trying from to run the Win+L command using 'robotjs' but it is not working.

I tried this:

robot.keyToggle("command", "down");  
robot.keyTap("l");
robot.keyToggle("command", "up");

But it's not working. I tried the command up and down key toggle an it does press the windows key. I even tried to run other commands like Win+E and Win+R and they worked like this.

robot.keyToggle("command", "down");  
robot.keyTap("r");
robot.keyToggle("command", "up");

But for some reason the Win+L command its not functioning. Does anyone know how to make it work? I´m pretty shure that this must be some Windows security policy or something but I still want to make it happen.


Solution

  • Ok this is simply impossible because the library simply injects the keys into the keyboard input buffer, but special key sequences like CTRL+ALT+DEL, WIN+L, etc operate at a lower layer that are interpretted by the OS before keys are put in the input buffer. When this happens the OS security protocols prevents it from working.