3

I am using python keyboard lib to unlock my windows desktop, when I try

keyboard.send('win+l')

It print l in my screen but not lock my computer

later I using ctypes.windll.lockworkstation() to lock my computer, but when I want to control my keyboard to unlock my computer, It dosen't work, so how should I fix this problem

below is my code now,I using python36/win10

import ctypes,time,keyboard
dll = ctypes.WinDLL('user32.dll')
dll.LockWorkStation()
time.sleep(1)
keyboard.send('enter')
keyboard.send('1,2,3')
keyboard.send('enter')
Jeffrey
  • 49
  • 1
  • 4
  • 1
    what do you mean, you should imort time,keyboard,ctypes before copy the code – Jeffrey Oct 25 '17 at 14:25
  • you should include the complete code including `imports`. There's no way for us to know what to import – yash Oct 25 '17 at 14:33
  • @yklsga, thanks for your reminder, but do you konw how could I solve my problem – Jeffrey Oct 25 '17 at 14:36
  • @Jeffrey this might help https://stackoverflow.com/a/36379918/4410922 – yash Oct 25 '17 at 14:39
  • @Jeffrey Were you able to resolve this issue? I have a process that uses win32com and win32gui to bring an application to the foreground. It runs without issue while my computer is unlocked. However, it is unable to grab the focus of the application when the computer is locked. – datalifenyc Sep 30 '19 at 20:52

1 Answers1

1

For anyone still looking for a solution, there is none (in python)

Both unfortunately and fortunately, Windows blocks software keyboard input in the passcode/password screen to prevent automated scripts from controlling the PC. The few ways you can unlock Windows programmatically, is to either emulate a physical keyboard, or use a lower-level language such as C, C++ or C#

farooq GV
  • 81
  • 7