Reputation: 339
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
Upvotes: 5
Views: 19389
Reputation: 65
import pyautogui
pyautogui.hold('win')
pyautogui.press('l')
This is working on my PC if you want to use only pyautogui and not ctypes
Upvotes: 0
Reputation: 61
import pyautogui
pyautogui.hotkey('winleft', 'l')
This is working in my laptop.
Upvotes: 5
Reputation: 63
I had this issue for Win+V and instead of using the hotkey function I used:
pyautogui.keyDown('winleft')
pyautogui.press('v')
pyautogui.keyUp('winleft')
Upvotes: 6
Reputation: 6359
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()
Upvotes: 8