-1

I am writing a code in which I need to lock the user's input via mouse and keyboard. I am using sockets and when i get the message "LOCK" it should lock the computer and when I get the message "UNLOCK" it will unlock the user's PC. I've tried using the module pyhook but if I use this module then the program will stop and I cant receive info from the socket. I have also tried working with pynput but I couldn't find a way to lock the keyboard/ mouse.

1 Answers1

0

Assuming this is a windows machine, you can use LockWorkstation()from ctypes

import ctypes
ctypes.windll.user32.LockWorkStation ()

if you are on an ubuntu machine, you can do the following.

os.popen('gnome-screensaver-command --lock')
cyberbemon
  • 3,000
  • 11
  • 37
  • 62