Search code examples
pythonpython-2.7pyautogui

How to trigger a Windows and L key Python-hotkey?


I am trying to run this code in Python.

import pyautogui
pyautogui.hotkey('win', 'l')

So that when I run it it will trigger switch user in Windows but all it does is press l when I need it to press Win+l


Solution

  • As said in my comment, it is most likely that this key combination doesn't work because Windows handles it specially.

    If you want to simply lock the workstation, you can use this solution which uses ctypes to call Windows' LockWorkstation-Function:

    Lock windows workstation using Python

    Python code:

    import ctypes
    ctypes.windll.user32.LockWorkStation()