first commit
This commit is contained in:
21
callbacks/lock.py
Normal file
21
callbacks/lock.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import ctypes
|
||||
from typing import Dict, Any
|
||||
|
||||
async def lock_computer(args: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""
|
||||
Locks the Windows computer screen using the LockWorkStation API.
|
||||
Args:
|
||||
args: Dictionary of arguments (not used in this implementation).
|
||||
Returns:
|
||||
Dictionary with status message and input arguments.
|
||||
Raises:
|
||||
OSError: If the lock operation fails or the platform is not Windows.
|
||||
"""
|
||||
try:
|
||||
# Use Windows API to lock the screen
|
||||
result = ctypes.WinDLL('user32.dll').LockWorkStation()
|
||||
if not result:
|
||||
raise OSError("Failed to lock the Windows screen")
|
||||
return {"message": "Windows screen locked successfully", "args": args}
|
||||
except Exception as e:
|
||||
raise OSError(f"Error while locking the Windows screen: {str(e)}")
|
||||
Reference in New Issue
Block a user