javascriptfirefox-addonxulxulrunner

Get notified when workstation gets locked


On Windows system pressing Win + L will lock the workstation. Is there a way within XUL addon detect when workstation is being locked down? I could probably detect pressing this key combination, but it would only work if XUL application in focus.

There is a sleep_notification available for when computer is going into sleep mode (or waking up). I can't find any information about locking workstation.


Solution

  • Found a way using js-ctypes (tested on Windows 10):

    Components.utils.import("resource://gre/modules/ctypes.jsm");
    var lib           = ctypes.open("user32.dll"),
        openDesktop   = lib.declare("OpenDesktopA", ctypes.winapi_abi, ctypes.uint32_t, ctypes.char.ptr, ctypes.uint32_t, ctypes.bool, ctypes.uint32_t),
        switchDesktop = lib.declare("SwitchDesktop", ctypes.winapi_abi, ctypes.bool, ctypes.uint32_t),
        closeDesktop  = lib.declare("CloseDesktop", ctypes.winapi_abi, ctypes.bool, ctypes.uint32_t),
        desktop       = openDesktop("Default", 0, 0, 0x0100),
        isUnLocked    = switchDesktop(desktop);
    
    console.log(isUnLocked);//result false = locked, true = unlocked
    
    closeDesktop(desktop);
    lib.close();